Search in sources :

Example 1 with DoubleColumnReference

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

the class DoubleColumnReferenceTest method testFieldCacheExpression.

@Test
public void testFieldCacheExpression() throws Exception {
    MappedFieldType fieldType = DoubleFieldMapper.Defaults.FIELD_TYPE.clone();
    fieldType.setNames(new MappedFieldType.Names("d"));
    DoubleColumnReference doubleColumn = new DoubleColumnReference(column, fieldType);
    doubleColumn.startCollect(ctx);
    doubleColumn.setNextReader(readerContext);
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 10);
    double d = 0.5;
    for (ScoreDoc doc : topDocs.scoreDocs) {
        doubleColumn.setNextDocId(doc.doc);
        assertThat(doubleColumn.value(), is(d));
        d++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) DoubleColumnReference(io.crate.operation.reference.doc.lucene.DoubleColumnReference) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Aggregations

DoubleColumnReference (io.crate.operation.reference.doc.lucene.DoubleColumnReference)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 TopDocs (org.apache.lucene.search.TopDocs)1 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1 Test (org.junit.Test)1