List of usage examples for org.apache.lucene.search RandomApproximationQuery RandomApproximationQuery
public RandomApproximationQuery(Query query, Random random)
From source file:org.apache.solr.search.TestQueryWrapperFilter.java
License:Apache License
public void testQueryWrapperFilterPropagatesApproximations() throws IOException { Directory dir = newDirectory();/*from w ww . j ava 2s .com*/ RandomIndexWriter writer = new RandomIndexWriter(random(), dir); Document doc = new Document(); doc.add(new StringField("foo", "bar", Store.NO)); writer.addDocument(doc); writer.commit(); final IndexReader reader = writer.getReader(); writer.close(); final IndexSearcher searcher = new IndexSearcher(reader); searcher.setQueryCache(null); // to still have approximations final Query query = new QueryWrapperFilter( new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random())); final Weight weight = searcher.createNormalizedWeight(query, random().nextBoolean()); final Scorer scorer = weight.scorer(reader.leaves().get(0)); assertNotNull(scorer.twoPhaseIterator()); reader.close(); dir.close(); }
From source file:org.elasticsearch.index.query.functionscore.FunctionScoreEquivalenceTests.java
License:Apache License
public void testTwoPhaseMinScore() throws Exception { Term term = randomTerm();//ww w . j av a2 s.com Query query = new TermQuery(term); Float minScore = random().nextFloat(); FunctionScoreQuery fsq1 = new FunctionScoreQuery(query, null, minScore); FunctionScoreQuery fsq2 = new FunctionScoreQuery(new RandomApproximationQuery(query, random()), null, minScore); assertSameScores(fsq1, fsq2); FiltersFunctionScoreQuery ffsq1 = new FiltersFunctionScoreQuery(query, ScoreMode.Sum, new FilterFunction[0], Float.POSITIVE_INFINITY, minScore); FiltersFunctionScoreQuery ffsq2 = new FiltersFunctionScoreQuery(query, ScoreMode.Sum, new FilterFunction[0], Float.POSITIVE_INFINITY, minScore); assertSameScores(ffsq1, ffsq2); }
From source file:org.elasticsearch.index.query.functionscore.FunctionScoreTests.java
License:Apache License
public void testPropagatesApproximations() throws IOException { Query query = new RandomApproximationQuery(new MatchAllDocsQuery(), random()); IndexSearcher searcher = newSearcher(reader); searcher.setQueryCache(null); // otherwise we could get a cached entry that does not have approximations FunctionScoreQuery fsq = new FunctionScoreQuery(query, null, null); for (boolean needsScores : new boolean[] { true, false }) { Weight weight = searcher.createWeight(fsq, needsScores); Scorer scorer = weight.scorer(reader.leaves().get(0)); assertNotNull(scorer.twoPhaseIterator()); }/*from w w w. j a va 2 s. c o m*/ FiltersFunctionScoreQuery ffsq = new FiltersFunctionScoreQuery(query, ScoreMode.Sum, new FilterFunction[0], Float.POSITIVE_INFINITY, null); for (boolean needsScores : new boolean[] { true, false }) { Weight weight = searcher.createWeight(ffsq, needsScores); Scorer scorer = weight.scorer(reader.leaves().get(0)); assertNotNull(scorer.twoPhaseIterator()); } }
From source file:org.elasticsearch.search.profile.ProfileTests.java
License:Apache License
public void testApproximations() throws IOException { Profiler profiler = new Profiler(); Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader)); // disable query caching since we want to test approximations, which won't // be exposed on a cached entry ContextIndexSearcher searcher = new ContextIndexSearcher(engineSearcher, null, MAYBE_CACHE_POLICY); searcher.setProfiler(profiler);/* w w w. jav a 2 s . co m*/ Query query = new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random()); searcher.count(query); List<ProfileResult> results = profiler.getQueryTree(); assertEquals(1, results.size()); Map<String, Long> breakdown = results.get(0).getTimeBreakdown(); assertThat(breakdown.get(ProfileBreakdown.TimingType.CREATE_WEIGHT.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(ProfileBreakdown.TimingType.BUILD_SCORER.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(ProfileBreakdown.TimingType.NEXT_DOC.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(ProfileBreakdown.TimingType.ADVANCE.toString()).longValue(), equalTo(0L)); assertThat(breakdown.get(ProfileBreakdown.TimingType.SCORE.toString()).longValue(), equalTo(0L)); assertThat(breakdown.get(ProfileBreakdown.TimingType.MATCH.toString()).longValue(), greaterThan(0L)); long rewriteTime = profiler.getRewriteTime(); assertThat(rewriteTime, greaterThan(0L)); }
From source file:org.elasticsearch.search.profile.query.ProfileTests.java
License:Apache License
public void testApproximations() throws IOException { QueryProfiler profiler = new QueryProfiler(); Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader)); // disable query caching since we want to test approximations, which won't // be exposed on a cached entry ContextIndexSearcher searcher = new ContextIndexSearcher(engineSearcher, null, MAYBE_CACHE_POLICY); searcher.setProfiler(profiler);/*from ww w .jav a 2s.c o m*/ Query query = new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random()); searcher.count(query); List<ProfileResult> results = profiler.getQueryTree(); assertEquals(1, results.size()); Map<String, Long> breakdown = results.get(0).getTimeBreakdown(); assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.ADVANCE.toString()).longValue(), equalTo(0L)); assertThat(breakdown.get(QueryTimingType.SCORE.toString()).longValue(), equalTo(0L)); assertThat(breakdown.get(QueryTimingType.MATCH.toString()).longValue(), greaterThan(0L)); long rewriteTime = profiler.getRewriteTime(); assertThat(rewriteTime, greaterThan(0L)); }
From source file:org.elasticsearch.search.profile.query.QueryProfilerTests.java
License:Apache License
public void testApproximations() throws IOException { QueryProfiler profiler = new QueryProfiler(); Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader)); // disable query caching since we want to test approximations, which won't // be exposed on a cached entry ContextIndexSearcher searcher = new ContextIndexSearcher(engineSearcher, null, MAYBE_CACHE_POLICY); searcher.setProfiler(profiler);/*from w w w . j a v a 2 s . c o m*/ Query query = new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random()); searcher.count(query); List<ProfileResult> results = profiler.getTree(); assertEquals(1, results.size()); Map<String, Long> breakdown = results.get(0).getTimeBreakdown(); assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.ADVANCE.toString()).longValue(), equalTo(0L)); assertThat(breakdown.get(QueryTimingType.SCORE.toString()).longValue(), equalTo(0L)); assertThat(breakdown.get(QueryTimingType.MATCH.toString()).longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.CREATE_WEIGHT.toString() + "_count").longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.BUILD_SCORER.toString() + "_count").longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.NEXT_DOC.toString() + "_count").longValue(), greaterThan(0L)); assertThat(breakdown.get(QueryTimingType.ADVANCE.toString() + "_count").longValue(), equalTo(0L)); assertThat(breakdown.get(QueryTimingType.SCORE.toString() + "_count").longValue(), equalTo(0L)); assertThat(breakdown.get(QueryTimingType.MATCH.toString() + "_count").longValue(), greaterThan(0L)); long rewriteTime = profiler.getRewriteTime(); assertThat(rewriteTime, greaterThan(0L)); }