Search in sources :

Example 81 with TermQuery

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));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) TermQuery(org.apache.lucene.search.TermQuery) ProfileResult(org.elasticsearch.search.profile.ProfileResult) Term(org.apache.lucene.index.Term)

Example 82 with TermQuery

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));
}
Also used : ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) TermQuery(org.apache.lucene.search.TermQuery) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) RandomApproximationQuery(org.apache.lucene.search.RandomApproximationQuery) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) Term(org.apache.lucene.index.Term) ProfileResult(org.elasticsearch.search.profile.ProfileResult) Engine(org.elasticsearch.index.engine.Engine)

Example 83 with TermQuery

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;
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term) HashSet(java.util.HashSet)

Example 84 with TermQuery

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);
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) Iterator(java.util.Iterator) Term(org.apache.lucene.index.Term) QueryContext(org.neo4j.index.lucene.QueryContext)

Example 85 with TermQuery

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();
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) Term(org.apache.lucene.index.Term)

Aggregations

TermQuery (org.apache.lucene.search.TermQuery)673 Term (org.apache.lucene.index.Term)560 BooleanQuery (org.apache.lucene.search.BooleanQuery)343 Query (org.apache.lucene.search.Query)275 IndexSearcher (org.apache.lucene.search.IndexSearcher)252 Document (org.apache.lucene.document.Document)210 TopDocs (org.apache.lucene.search.TopDocs)164 Directory (org.apache.lucene.store.Directory)164 IndexReader (org.apache.lucene.index.IndexReader)125 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)125 PhraseQuery (org.apache.lucene.search.PhraseQuery)122 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)116 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)114 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)97 BoostQuery (org.apache.lucene.search.BoostQuery)85 Field (org.apache.lucene.document.Field)81 Test (org.junit.Test)75 PrefixQuery (org.apache.lucene.search.PrefixQuery)74 ArrayList (java.util.ArrayList)72 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)62