public void testBuildSearchClauses() {

    StringSearchFacet.SearchClauseFactory f = testInstance.CLAUSE_FACTORY;
    StringSearchFacet.SearchTarget t = StringSearchFacet.SearchTarget.TEXT;
    Boolean caps = true;
    Boolean marks = false;

    try {

      // sanity check - no terms yields null
      String search1 = "";
      ArrayList<StringSearchFacet.SearchClause> clauses =
          f.buildSearchClauses(search1, t, caps, marks);
      assertNull(clauses);

      // sanity check - single term
      String search2 = "kai";
      ArrayList<StringSearchFacet.SearchClause> clauses1 =
          f.buildSearchClauses(search2, t, caps, marks);
      StringSearchFacet.SearchClause kaiClause = clauses1.get(0);
      assertEquals("kai", kaiClause.getOriginalString());
      assertTrue(kaiClause instanceof StringSearchFacet.SearchTerm);

      // sanity check - 4 terms
      String search3 = "kai ouk eleutheria kaisaros";
      ArrayList<StringSearchFacet.SearchClause> clauses2 =
          f.buildSearchClauses(search3, t, caps, marks);
      assertEquals(4, clauses2.size());
      StringSearchFacet.SearchClause eleuClause = clauses2.get(2);
      assertEquals("eleutheria", eleuClause.getOriginalString());
      assertTrue(eleuClause instanceof StringSearchFacet.SearchTerm);

      // quote-delimited terms resolve as a single term
      String search4 = "\"kai ouk\" \"eleutheria kaisaros\"";
      ArrayList<StringSearchFacet.SearchClause> clauses3 =
          f.buildSearchClauses(search4, t, caps, marks);
      assertEquals(2, clauses3.size());
      StringSearchFacet.SearchClause oukClause = clauses3.get(0);
      assertEquals("\"kai ouk\"", oukClause.getOriginalString());
      assertTrue(oukClause instanceof StringSearchFacet.SearchTerm);

      // whitespace shouldn't make a difference
      String search6 = "kai     AND  ouk";
      ArrayList<StringSearchFacet.SearchClause> clauses5 =
          f.buildSearchClauses(search6, t, caps, marks);
      assertEquals(3, clauses5.size());
      StringSearchFacet.SearchClause andClause = clauses5.get(1);
      assertEquals("AND", andClause.getOriginalString());
      assertTrue(andClause instanceof StringSearchFacet.SearchTerm);

    } catch (StringSearchParsingException sspe) {

      fail(
          "StringSearchParsingException erroneously thrown in breakIntoComponents test: "
              + sspe.getMessage());

    } catch (Exception e) {

      fail("Exception erroneously thrown in breakIntoComponents test:" + e.getMessage());
    }
  }
  public void testSwapInProxperators() {

    StringSearchFacet.SearchClauseFactory s = testInstance.CLAUSE_FACTORY;

    try {

      // sanity check - no search terms returns string unchanged
      String prox0 = "(kai AND ouk)";
      String test0 = "(kai AND ouk)";
      assertEquals(test0, s.swapInProxperators(prox0));

      // search type THEN swapped in as 'w' and unit type 'words' eliminated
      String prox1 = "(kai THEN ouk)~15words";
      String test1 = "kai 15w ouk";
      assertEquals(test1, s.swapInProxperators(prox1));

      // search type NEAR swapped in as 'n' and unit type 'chars' retained as 'c'
      String prox2 = "(kai NEAR ouk)~15chars";
      String test2 = "kai 15nc ouk";
      assertEquals(test2, s.swapInProxperators(prox2));

      // malformed unit defaults to 'words' (i.e. eliminated)
      String prox3 = "(kai THEN ouk)~15whars";
      assertEquals(test1, s.swapInProxperators(prox3));
      // absent unit defaults to 'words'
      String prox4 = "(kai THEN ouk)~15";
      assertEquals(test1, s.swapInProxperators(prox4));

      // absent brackets dealt with correctly
      String prox5 = "kai THEN ouk~15";
      String test5 = "kai 15w ouk";
      assertEquals(test5, s.swapInProxperators(prox5));

      // internal brackets dealt with correctly
      String prox6 = "(kai THEN (kai OR ouk))~17words";
      String test6 = "kai 17w (kai OR ouk)";
      assertEquals(test6, s.swapInProxperators(prox6));

      // absent metrics default to one word
      String prox8 = "(kai THEN ouk)";
      String test8 = "kai 1w ouk";
      assertEquals(test8, s.swapInProxperators(prox8));

    } catch (MalformedProximitySearchException mpse) {

      fail("MalformedProximitySearchException wrongly thrown in proxperator test");

    } catch (MismatchedBracketException mbe) {

      fail("MismatchedBracketException wrongly thrown in proxperator test");
    }
    // malformed or absent proximity operator throws MalformedProximitySearchException
    try {

      String prox8 = "(kai AND ouk)~15chars";
      s.swapInProxperators(prox8);
      fail("Proxperator swap should have thrown MalformedProximitySearchException");

    } catch (MalformedProximitySearchException mpse) {
    } catch (MismatchedBracketException mbe) {

      fail("MismatchedBracketException wrongly thrown in proxperator test");
    }
  }