Search in sources :

Example 1 with BytesRefColumnReference

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

the class BytesRefColumnReferenceTest method testFieldCacheExpression.

@Test
public void testFieldCacheExpression() throws Exception {
    MappedFieldType fieldType = StringFieldMapper.Defaults.FIELD_TYPE.clone();
    fieldType.setNames(new MappedFieldType.Names(column));
    BytesRefColumnReference bytesRefColumn = new BytesRefColumnReference(column, fieldType);
    bytesRefColumn.startCollect(ctx);
    bytesRefColumn.setNextReader(readerContext);
    IndexSearcher searcher = new IndexSearcher(readerContext.reader());
    TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), 20);
    int i = 0;
    StringBuilder builder = new StringBuilder();
    for (ScoreDoc doc : topDocs.scoreDocs) {
        builder.append(i);
        bytesRefColumn.setNextDocId(doc.doc);
        assertThat(bytesRefColumn.value().utf8ToString(), is(builder.toString()));
        i++;
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TopDocs(org.apache.lucene.search.TopDocs) BytesRefColumnReference(io.crate.operation.reference.doc.lucene.BytesRefColumnReference) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ScoreDoc(org.apache.lucene.search.ScoreDoc) Test(org.junit.Test)

Aggregations

BytesRefColumnReference (io.crate.operation.reference.doc.lucene.BytesRefColumnReference)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