Search in sources :

Example 1 with LongColumnReference

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

the class LongColumnReferenceTest method testLongExpression.

@Test
public void testLongExpression() throws Exception {
    LongColumnReference longColumn = new LongColumnReference(column);
    longColumn.startCollect(ctx);
    longColumn.setNextReader(readerContext);
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 20);
    long l = Long.MIN_VALUE;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        longColumn.setNextDocId(doc.doc);
        assertThat(longColumn.value(), is(l));
        l++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) LongColumnReference(io.crate.operation.reference.doc.lucene.LongColumnReference) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Example 2 with LongColumnReference

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

the class LuceneBatchIteratorTest method prepareSearcher.

@Before
public void prepareSearcher() throws Exception {
    IndexWriter iw = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    String columnName = "x";
    expectedResult = new ArrayList<>(20);
    for (long i = 0; i < 20; i++) {
        Document doc = new Document();
        doc.add(new NumericDocValuesField(columnName, i));
        iw.addDocument(doc);
        expectedResult.add(new Object[] { i });
    }
    iw.commit();
    indexSearcher = new IndexSearcher(DirectoryReader.open(iw, true));
    LongColumnReference columnReference = new LongColumnReference(columnName);
    columnRefs = Collections.singletonList(columnReference);
}
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) LongColumnReference(io.crate.operation.reference.doc.lucene.LongColumnReference) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Aggregations

LongColumnReference (io.crate.operation.reference.doc.lucene.LongColumnReference)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 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 Before (org.junit.Before)1 Test (org.junit.Test)1