use of org.apache.lucene.search.TermQuery in project elasticsearch by elastic.
the class QueryProfilerTests method testBasic.
public void testBasic() throws IOException {
QueryProfiler profiler = new QueryProfiler();
searcher.setProfiler(profiler);
Query query = new TermQuery(new Term("foo", "bar"));
searcher.search(query, 1);
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(), greaterThan(0L));
assertThat(breakdown.get(QueryTimingType.MATCH.toString()).longValue(), equalTo(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(), greaterThan(0L));
assertThat(breakdown.get(QueryTimingType.MATCH.toString() + "_count").longValue(), equalTo(0L));
long rewriteTime = profiler.getRewriteTime();
assertThat(rewriteTime, greaterThan(0L));
}
use of org.apache.lucene.search.TermQuery in project elasticsearch by elastic.
the class QueryProfilerTests method testApproximations.
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);
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));
}
use of org.apache.lucene.search.TermQuery in project graphdb by neo4j-attic.
the class FullTxData method injectOrphans.
private Query injectOrphans(Query query) {
if (query instanceof BooleanQuery) {
BooleanQuery source = (BooleanQuery) query;
BooleanQuery result = new BooleanQuery();
for (BooleanClause clause : source.clauses()) {
result.add(injectOrphans(clause.getQuery()), clause.getOccur());
}
return result;
} else {
Set<Term> terms = new HashSet<Term>();
query.extractTerms(terms);
// TODO Don't only use the first term
Term term = terms.iterator().next();
BooleanQuery result = new BooleanQuery();
result.add(query, Occur.SHOULD);
result.add(new TermQuery(new Term(ORPHANS_KEY, term.field())), Occur.SHOULD);
return result;
}
}
use of org.apache.lucene.search.TermQuery in project graphdb by neo4j-attic.
the class TestPerformanceAndSanity method testInsertionSpeed.
private <T extends PropertyContainer> void testInsertionSpeed(Index<T> index, EntityCreator<T> creator) {
long t = System.currentTimeMillis();
for (int i = 0; i < 300000; i++) {
T entity = creator.create();
if (i % 5000 == 5) {
index.query(new TermQuery(new Term("name", "The name " + i)));
}
IteratorUtil.lastOrNull((Iterable<T>) index.query(new QueryContext(new TermQuery(new Term("name", "The name " + i))).tradeCorrectnessForSpeed()));
IteratorUtil.lastOrNull((Iterable<T>) index.get("name", "The name " + i));
index.add(entity, "name", "The name " + i);
index.add(entity, "title", "Some title " + i);
index.add(entity, "something", i + "Nothing");
index.add(entity, "else", i + "kdfjkdjf" + i);
if (i % 10000 == 0) {
restartTx();
System.out.println(i);
}
}
System.out.println("insert:" + (System.currentTimeMillis() - t));
t = System.currentTimeMillis();
int count = 1000;
int resultCount = 0;
for (int i = 0; i < count; i++) {
resultCount += IteratorUtil.count((Iterator<T>) index.get("name", "The name " + i * 900));
}
System.out.println("get(" + resultCount + "):" + (double) (System.currentTimeMillis() - t) / (double) count);
t = System.currentTimeMillis();
resultCount = 0;
for (int i = 0; i < count; i++) {
resultCount += IteratorUtil.count((Iterator<T>) index.get("something", i * 900 + "Nothing"));
}
System.out.println("get(" + resultCount + "):" + (double) (System.currentTimeMillis() - t) / (double) count);
}
use of org.apache.lucene.search.TermQuery in project neo4j by neo4j.
the class FullTxData method injectOrphans.
private Query injectOrphans(Query query) {
if (query instanceof BooleanQuery) {
BooleanQuery source = (BooleanQuery) query;
BooleanQuery.Builder builder = new BooleanQuery.Builder();
for (BooleanClause clause : source.clauses()) {
builder.add(injectOrphans(clause.getQuery()), clause.getOccur());
}
return builder.build();
}
String orphanField = extractTermField(query);
if (orphanField == null) {
return query;
}
return new BooleanQuery.Builder().add(query, Occur.SHOULD).add(new TermQuery(new Term(ORPHANS_KEY, orphanField)), Occur.SHOULD).build();
}
Aggregations