public Query getQueryDOA(String query, Analyzer a) throws Exception { if (a == null) a = new SimpleAnalyzer(); QueryParserWrapper qp = new QueryParserWrapper("field", a); qp.setDefaultOperator(QueryParserWrapper.AND_OPERATOR); return qp.parse(query); }
public void testSimple() throws Exception { assertQueryEquals("\"term germ\"~2", null, "\"term germ\"~2"); assertQueryEquals("term term term", null, "term term term"); assertQueryEquals("t�rm term term", new WhitespaceAnalyzer(), "t�rm term term"); assertQueryEquals("�mlaut", new WhitespaceAnalyzer(), "�mlaut"); assertQueryEquals("\"\"", new KeywordAnalyzer(), ""); assertQueryEquals("foo:\"\"", new KeywordAnalyzer(), "foo:"); assertQueryEquals("a AND b", null, "+a +b"); assertQueryEquals("(a AND b)", null, "+a +b"); assertQueryEquals("c OR (a AND b)", null, "c (+a +b)"); assertQueryEquals("a AND NOT b", null, "+a -b"); assertQueryEquals("a AND -b", null, "+a -b"); assertQueryEquals("a AND !b", null, "+a -b"); assertQueryEquals("a && b", null, "+a +b"); assertQueryEquals("a && ! b", null, "+a -b"); assertQueryEquals("a OR b", null, "a b"); assertQueryEquals("a || b", null, "a b"); assertQueryEquals("a OR !b", null, "a -b"); assertQueryEquals("a OR ! b", null, "a -b"); assertQueryEquals("a OR -b", null, "a -b"); assertQueryEquals("+term -term term", null, "+term -term term"); assertQueryEquals("foo:term AND field:anotherTerm", null, "+foo:term +anotherterm"); assertQueryEquals("term AND \"phrase phrase\"", null, "+term +\"phrase phrase\""); assertQueryEquals("\"hello there\"", null, "\"hello there\""); assertTrue(getQuery("a AND b", null) instanceof BooleanQuery); assertTrue(getQuery("hello", null) instanceof TermQuery); assertTrue(getQuery("\"hello there\"", null) instanceof PhraseQuery); assertQueryEquals("germ term^2.0", null, "germ term^2.0"); assertQueryEquals("(term)^2.0", null, "term^2.0"); assertQueryEquals("(germ term)^2.0", null, "(germ term)^2.0"); assertQueryEquals("term^2.0", null, "term^2.0"); assertQueryEquals("term^2", null, "term^2.0"); assertQueryEquals("\"germ term\"^2.0", null, "\"germ term\"^2.0"); assertQueryEquals("\"term germ\"^2", null, "\"term germ\"^2.0"); assertQueryEquals("(foo OR bar) AND (baz OR boo)", null, "+(foo bar) +(baz boo)"); assertQueryEquals("((a OR b) AND NOT c) OR d", null, "(+(a b) -c) d"); assertQueryEquals( "+(apple \"steve jobs\") -(foo bar baz)", null, "+(apple \"steve jobs\") -(foo bar baz)"); assertQueryEquals( "+title:(dog OR cat) -author:\"bob dole\"", null, "+(title:dog title:cat) -author:\"bob dole\""); QueryParserWrapper qp = new QueryParserWrapper("field", new StandardAnalyzer()); // make sure OR is the default: assertEquals(QueryParserWrapper.OR_OPERATOR, qp.getDefaultOperator()); qp.setDefaultOperator(QueryParserWrapper.AND_OPERATOR); assertEquals(QueryParserWrapper.AND_OPERATOR, qp.getDefaultOperator()); qp.setDefaultOperator(QueryParserWrapper.OR_OPERATOR); assertEquals(QueryParserWrapper.OR_OPERATOR, qp.getDefaultOperator()); }
public QueryParserWrapper getParser(Analyzer a) throws Exception { if (a == null) a = new SimpleAnalyzer(); QueryParserWrapper qp = new QueryParserWrapper("field", a); qp.setDefaultOperator(QueryParserWrapper.OR_OPERATOR); return qp; }