Search in sources :

Example 1 with IntegerColumnReference

use of io.crate.operation.reference.doc.lucene.IntegerColumnReference in project crate by crate.

the class LuceneBatchIteratorBenchmark method createLuceneBatchIterator.

@Setup
public void createLuceneBatchIterator() throws Exception {
    IndexWriter iw = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    String columnName = "x";
    for (int i = 0; i < 10_000_000; i++) {
        Document doc = new Document();
        doc.add(new NumericDocValuesField(columnName, i));
        iw.addDocument(doc);
    }
    iw.commit();
    iw.forceMerge(1, true);
    indexSearcher = new IndexSearcher(DirectoryReader.open(iw, true));
    IntegerColumnReference columnReference = new IntegerColumnReference(columnName);
    columnRefs = Collections.singletonList(columnReference);
    collectorContext = new CollectorContext(mock(IndexFieldDataService.class), new CollectorFieldsVisitor(0));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IntegerColumnReference(io.crate.operation.reference.doc.lucene.IntegerColumnReference) CollectorContext(io.crate.operation.reference.doc.lucene.CollectorContext) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 2 with IntegerColumnReference

use of io.crate.operation.reference.doc.lucene.IntegerColumnReference in project crate by crate.

the class IntegerColumnReferenceTest method testIntegerExpression.

@Test
public void testIntegerExpression() throws Exception {
    IntegerColumnReference integerColumn = new IntegerColumnReference(column);
    integerColumn.startCollect(ctx);
    integerColumn.setNextReader(readerContext);
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 20);
    int i = -10;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        integerColumn.setNextDocId(doc.doc);
        assertThat(integerColumn.value(), is(i));
        i++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) IntegerColumnReference(io.crate.operation.reference.doc.lucene.IntegerColumnReference) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Aggregations

IntegerColumnReference (io.crate.operation.reference.doc.lucene.IntegerColumnReference)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 CollectorContext (io.crate.operation.reference.doc.lucene.CollectorContext)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Document (org.apache.lucene.document.Document)1 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 TopDocs (org.apache.lucene.search.TopDocs)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 Test (org.junit.Test)1