Search in sources :

Example 26 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project crate by crate.

the class OrderedLuceneBatchIteratorFactoryTest method prepareSearchers.

@Before
public void prepareSearchers() throws Exception {
    IndexWriter iw1 = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    IndexWriter iw2 = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    expectedResult = LongStream.range(0, 20).mapToObj(i -> new Object[] { i }).collect(Collectors.toList());
    // expect descending order to differentiate between insert order
    expectedResult.sort(Comparator.comparingLong((Object[] o) -> ((long) o[0])).reversed());
    for (int i = 0; i < 20; i++) {
        Document doc = new Document();
        doc.add(new NumericDocValuesField(columnName, i));
        if (i % 2 == 0) {
            iw1.addDocument(doc);
        } else {
            iw2.addDocument(doc);
        }
    }
    iw1.commit();
    iw2.commit();
    searcher1 = new IndexSearcher(DirectoryReader.open(iw1));
    searcher2 = new IndexSearcher(DirectoryReader.open(iw2));
    orderBy = new OrderBy(Collections.singletonList(reference), reverseFlags, nullsFirst);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) OrderBy(io.crate.analyze.OrderBy) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Document(org.apache.lucene.document.Document) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 27 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project crate by crate.

the class DocValuesGroupByOptimizedIteratorTest method setup.

@Before
public void setup() throws IOException {
    var nodeContext = createNodeContext();
    functions = nodeContext.functions();
    var indexWriter = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig());
    for (var row : rows) {
        Document doc = new Document();
        doc.add(new SortedSetDocValuesField("x", BytesRefs.toBytesRef(row[0])));
        doc.add(new NumericDocValuesField("y", (Long) row[1]));
        doc.add(new NumericDocValuesField("z", (Long) row[2]));
        indexWriter.addDocument(doc);
    }
    indexWriter.commit();
    indexSearcher = new IndexSearcher(DirectoryReader.open(indexWriter));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) Document(org.apache.lucene.document.Document) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 28 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project crate by crate.

the class LuceneBatchIteratorTest method prepareSearcher.

@Before
public void prepareSearcher() throws Exception {
    IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), 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));
    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) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) Document(org.apache.lucene.document.Document) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Example 29 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project crate by crate.

the class GroupByOptimizedIteratorTest method testHighCardinalityRatioReturnsTrueForHighCardinality.

@Test
public void testHighCardinalityRatioReturnsTrueForHighCardinality() throws Exception {
    IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    String columnName = "x";
    for (int i = 0; i < 10; i++) {
        Document doc = new Document();
        BytesRef value = new BytesRef(Integer.toString(i));
        doc.add(new Field(columnName, value, KeywordFieldMapper.Defaults.FIELD_TYPE));
        iw.addDocument(doc);
    }
    iw.commit();
    IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(iw));
    assertThat(GroupByOptimizedIterator.hasHighCardinalityRatio(() -> new Engine.Searcher("dummy", indexSearcher.getIndexReader(), indexSearcher.getQueryCache(), indexSearcher.getQueryCachingPolicy(), () -> {
    }), "x"), is(true));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) Field(org.apache.lucene.document.Field) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) IndexSearcher(org.apache.lucene.search.IndexSearcher) Document(org.apache.lucene.document.Document) BytesRef(org.apache.lucene.util.BytesRef) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 30 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project crate by crate.

the class GroupByOptimizedIteratorTest method prepare.

@Before
public void prepare() throws Exception {
    NodeContext nodeCtx = createNodeContext();
    IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
    columnName = "x";
    expectedResult = new ArrayList<>(20);
    for (long i = 0; i < 20; i++) {
        Document doc = new Document();
        String val = "val_" + i;
        doc.add(new SortedSetDocValuesField(columnName, new BytesRef(val)));
        iw.addDocument(doc);
        expectedResult.add(new Object[] { val, 1L });
    }
    iw.commit();
    indexSearcher = new IndexSearcher(DirectoryReader.open(iw));
    inExpr = new InputCollectExpression(0);
    CountAggregation aggregation = (CountAggregation) nodeCtx.functions().getQualified(CountAggregation.COUNT_STAR_SIGNATURE, Collections.emptyList(), CountAggregation.COUNT_STAR_SIGNATURE.getReturnType().createType());
    aggregationContexts = List.of(new AggregationContext(aggregation, () -> true, List.of()));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) AggregationContext(io.crate.execution.engine.aggregation.AggregationContext) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) NodeContext(io.crate.metadata.NodeContext) Document(org.apache.lucene.document.Document) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) CountAggregation(io.crate.execution.engine.aggregation.impl.CountAggregation) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) BytesRef(org.apache.lucene.util.BytesRef) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Before(org.junit.Before)

Aggregations

ByteBuffersDirectory (org.apache.lucene.store.ByteBuffersDirectory)32 IndexWriter (org.apache.lucene.index.IndexWriter)18 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)18 Document (org.apache.lucene.document.Document)15 IndexSearcher (org.apache.lucene.search.IndexSearcher)13 Directory (org.apache.lucene.store.Directory)13 Test (org.junit.Test)11 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)8 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)6 TextField (org.apache.lucene.document.TextField)6 Before (org.junit.Before)6 BytesRef (org.apache.lucene.util.BytesRef)5 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)4 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)3 Row (io.crate.data.Row)3 LuceneCollectorExpression (io.crate.expression.reference.doc.lucene.LuceneCollectorExpression)3 ScoreCollectorExpression (io.crate.expression.reference.doc.lucene.ScoreCollectorExpression)3 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 Term (org.apache.lucene.index.Term)3