FullTextSearchParser implements QueryParser { public Term parse( String fullTextSearchExpression ) { CheckArg.isNotNull(fullTextSearchExpression, "fullTextSearchExpression"); Tokenizer tokenizer = new TermTokenizer(); TokenStream stream = new TokenStream(fullTextSearchExpression, tokenizer, false); return parse(stream.start()); }  @Override String getLanguage(); @Override QueryCommand parseQuery( String query,
                                    TypeSystem typeSystem ); Term parse( String fullTextSearchExpression ); Term parse( TokenStream tokens ); static final String LANGUAGE; }
@Test( expected = IllegalArgumentException.class ) public void shouldFailToParseNullString() { parser.parse((String)null); }
@Test( expected = ParsingException.class ) public void shouldFailToParseEmptyString() { parser.parse(""); }
@Test( expected = ParsingException.class ) public void shouldFailToParseBlankString() { parser.parse(" "); }
@Test public void shouldParseStringWithOneUnquotedTerm() { Term result = parser.parse("term1"); assertSimpleTerm(result, "term1", false, false); }
@Test public void shouldParseStringWithOneSingleQuotedTermWithOneWord() { Term result = parser.parse("'term1'"); assertSimpleTerm(result, "term1", false, false); }
@Test public void shouldParseStringWithOneSingleQuotedTermWithMultipleWords() { Term result = parser.parse("'term1 has two words'"); assertSimpleTerm(result, "term1 has two words", false, true); }
@Test public void shouldParseStringWithOneDoubleQuotedTermWithOneWord() { Term result = parser.parse("\"term1\""); assertSimpleTerm(result, "term1", false, false); }
@Test public void shouldParseStringWithOneDoubleQuotedTermWithMultipleWords() { Term result = parser.parse("\"term1 has two words\""); assertSimpleTerm(result, "term1 has two words", false, true); }
@Test public void shouldParseStringWithMultipleUnquotedTerms() { Term result = parser.parse("term1 term2 term3"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Conjunction.class))); Conjunction conjunction = (Conjunction)result; assertHasSimpleTerms(conjunction, "term1", "term2", "term3"); }
@Test public void shouldParseStringWithMultipleUnquotedTermsWithNegatedTerms() { Term result = parser.parse("term1 term2 -term3"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Conjunction.class))); Conjunction conjunction = (Conjunction)result; assertHasSimpleTerms(conjunction, "term1", "term2", "-term3"); }
@Test public void shouldParseStringWithMultipleQuotedAndUnquotedTermsWithNegatedTerms() { Term result = parser.parse("term1 \"term2 and 2a\" -term3 -'term 4'"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Conjunction.class))); Conjunction conjunction = (Conjunction)result; assertHasSimpleTerms(conjunction, "term1", "term2 and 2a", "-term3", "-term 4"); }
@Test public void shouldParseStringWithMultipleUnquotedORedTerms() { Term result = parser.parse("term1 OR term2 OR term3"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Disjunction.class))); Disjunction disjunction = (Disjunction)result; assertHasSimpleTerms(disjunction, "term1", "term2", "term3"); }
@Test public void shouldParseStringWithMultipleUnquotedORedTermsWithNegatedTerms() { Term result = parser.parse("term1 OR term2 OR -term3"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Disjunction.class))); Disjunction disjunction = (Disjunction)result; assertHasSimpleTerms(disjunction, "term1", "term2", "-term3"); }
@Test public void shouldParseStringWithMultipleUnquotedANDedTermsORedTogether() { Term result = parser.parse("term1 term2 OR -term3 -term4"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Disjunction.class))); Disjunction disjunction = (Disjunction)result; assertThat(disjunction.getTerms().size(), is(2)); Conjunction conjunction1 = (Conjunction)disjunction.getTerms().get(0); Conjunction conjunction2 = (Conjunction)disjunction.getTerms().get(1); assertHasSimpleTerms(conjunction1, "term1", "term2"); assertHasSimpleTerms(conjunction2, "-term3", "term4"); }
@Test public void shouldParseStringWithTwoANDedUnquotedTermsORedWithMultipleUnquotedTerms() { Term result = parser.parse("term1 term2 OR -term3 OR -term4 OR term5"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Disjunction.class))); Disjunction disjunction = (Disjunction)result; assertThat(disjunction.getTerms().size(), is(4)); Conjunction conjunction1 = (Conjunction)disjunction.getTerms().get(0); Term term3 = disjunction.getTerms().get(1); Term term4 = disjunction.getTerms().get(2); Term term5 = disjunction.getTerms().get(3); assertHasSimpleTerms(conjunction1, "term1", "term2"); assertSimpleTerm(term3, "term3", true, false); assertSimpleTerm(term4, "term4", true, false); assertSimpleTerm(term5, "term5", false, false); }
@Test public void shouldParseStringWithWildcardCharactersAtEndOfSingleTerm() { Term result = parser.parse("term*"); assertSimpleTerm(result, "term*", false, false); }
@Test public void shouldParseStringWithWildcardCharactersAtBeginningOfSingleTerm() { Term result = parser.parse("*term"); assertSimpleTerm(result, "*term", false, false); }
@Test public void shouldParseStringWithWildcardCharactersInsideSingleTerm() { Term result = parser.parse("te*rm"); assertSimpleTerm(result, "te*rm", false, false); }
@Test public void shouldParseStringWithWildcardCharactersInMultipleTerms() { Term result = parser.parse("term* term? *term*"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Conjunction.class))); Conjunction conjunction = (Conjunction)result; assertHasSimpleTerms(conjunction, "term*", "term?", "*term*"); }
@Test public void shouldParseStringWithWildcardCharactersInSingleQuotedTerm() { Term result = parser.parse("'term* term? *term*'"); assertSimpleTerm(result, "term* term? *term*", false, true); }
@Test public void shouldParseStringWithSqlStyleWildcardCharactersInMultipleTerms() { Term result = parser.parse("term% term_ %term_"); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(Conjunction.class))); Conjunction conjunction = (Conjunction)result; assertHasSimpleTerms(conjunction, "term%", "term_", "%term_"); }
@Test public void shouldParseStringWithSqlStyleWildcardCharactersInSingleQuotedTerm() { Term result = parser.parse("'term% term_ %term_'"); assertSimpleTerm(result, "term% term_ %term_", false, true); }
@Test public void shouldParseStringWithEscapedWildcardCharacterInSingleTerm() { Term result = parser.parse("term\\*"); assertSimpleTerm(result, "term\\*", false, false); }