public void testBoost() throws Exception { StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer(TEST_VERSION_CURRENT, Collections.singleton("on")); AqpQueryParser qp = getParser(); qp.setAnalyzer(oneStopAnalyzer); Query q = qp.parse("on^1.0", "field"); assertNotNull(q); q = qp.parse("\"hello\"^2.0", "field"); assertNotNull(q); assertEquals(q.getBoost(), (float) 2.0, (float) 0.5); q = qp.parse("hello^2.0", "field"); assertNotNull(q); assertEquals(q.getBoost(), (float) 2.0, (float) 0.5); q = qp.parse("\"on\"^1.0", "field"); assertNotNull(q); AqpQueryParser qp2 = AqpStandardLuceneParser.init(); qp2.setAnalyzer(new StandardAnalyzer(TEST_VERSION_CURRENT)); q = qp2.parse("the^3", "field"); // "the" is a stop word so the result is an empty query: assertNotNull(q); assertEquals("", q.toString()); assertEquals(1.0f, q.getBoost(), 0.01f); }
public static AqpQueryParser init(Analyzer a) throws Exception { AqpQueryParser p = AqpStandardLuceneParser.init(); ((QueryNodeProcessorPipeline) p.getQueryNodeProcessor()) .add(new QPTestParserQueryNodeProcessor()); p.setAnalyzer(a); return p; }
public void testConstantScoreAutoRewrite() throws Exception { AqpQueryParser qp = AqpStandardLuceneParser.init(getGrammarName()); qp.setAnalyzer(new WhitespaceAnalyzer(TEST_VERSION_CURRENT)); Query q = qp.parse("foo*bar", "field"); assertTrue(q instanceof WildcardQuery); assertEquals( MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT, ((MultiTermQuery) q).getRewriteMethod()); q = qp.parse("foo*", "field"); assertTrue(q instanceof PrefixQuery); assertEquals( MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT, ((MultiTermQuery) q).getRewriteMethod()); q = qp.parse("[a TO z]", "field"); assertTrue(q instanceof TermRangeQuery); assertEquals( MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT, ((MultiTermQuery) q).getRewriteMethod()); }