Search in sources :

Example 16 with ByteBuffersDirectory

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

the class GroupByOptimizedIteratorTest method testHighCardinalityRatioReturnsTrueForLowCardinality.

@Test
public void testHighCardinalityRatioReturnsTrueForLowCardinality() 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("1");
        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(false));
}
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 17 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project Anserini by castorini.

the class LexicalLshAnalyzerTest method testBinaryIndexAndSearch.

@Test
public void testBinaryIndexAndSearch() throws Exception {
    LexicalLshAnalyzer analyzer = new LexicalLshAnalyzer();
    Directory directory = new ByteBuffersDirectory();
    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(analyzer));
    DirectoryReader reader = null;
    try {
        List<Double> values = new LinkedList<>();
        values.add(0.1d);
        values.add(0.3d);
        values.add(0.5d);
        values.add(0.7d);
        values.add(0.11d);
        values.add(0.13d);
        values.add(0.17d);
        values.add(0.19d);
        values.add(0.23d);
        values.add(0.29d);
        byte[] bytes = toByteArray(values);
        String fvString = toDoubleString(bytes);
        String fieldName = "fvs";
        Document document = new Document();
        document.add(new TextField(fieldName, fvString, Field.Store.YES));
        writer.addDocument(document);
        writer.commit();
        reader = DirectoryReader.open(writer);
        assertSimQuery(analyzer, fieldName, fvString, reader);
    } finally {
        if (reader != null) {
            reader.close();
        }
        writer.close();
        directory.close();
    }
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) LinkedList(java.util.LinkedList) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) TextField(org.apache.lucene.document.TextField) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Example 18 with ByteBuffersDirectory

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

the class SuggesterProjectDataTest method setUp.

@BeforeEach
public void setUp() throws IOException {
    dir = new ByteBuffersDirectory();
    tempDir = Files.createTempDirectory("test");
}
Also used : ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project Anserini by castorini.

the class LexicalLshAnalyzerTest method testTextIndexAndSearch.

@Test
public void testTextIndexAndSearch() throws Exception {
    String fieldName = "text";
    String[] texts = new String[] { "0.1,0.3,0.5,0.7,0.11,0.13,0.17,0.19,0.23,0.29", "0.111 0.3333 0.4445 0.5755 0.1551131 0.12131233 0.155557 0.1123219 0.6623 0.429" };
    for (String text : texts) {
        LexicalLshAnalyzer analyzer = new LexicalLshAnalyzer();
        Directory directory = new ByteBuffersDirectory();
        IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(analyzer));
        DirectoryReader reader = null;
        try {
            Document document = new Document();
            document.add(new TextField(fieldName, text, Field.Store.YES));
            writer.addDocument(document);
            writer.commit();
            reader = DirectoryReader.open(writer);
            assertSimQuery(analyzer, fieldName, text, reader);
        } finally {
            if (reader != null) {
                reader.close();
            }
            writer.close();
            directory.close();
        }
    }
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) DirectoryReader(org.apache.lucene.index.DirectoryReader) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) TextField(org.apache.lucene.document.TextField) Document(org.apache.lucene.document.Document) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

Example 20 with ByteBuffersDirectory

use of org.apache.lucene.store.ByteBuffersDirectory in project Anserini by castorini.

the class FakeWordsEncoderAnalyzerTest method testBinaryFVIndexAndSearch.

@Test
public void testBinaryFVIndexAndSearch() throws Exception {
    FakeWordsEncoderAnalyzer analyzer = new FakeWordsEncoderAnalyzer(30);
    Directory directory = new ByteBuffersDirectory();
    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(analyzer));
    DirectoryReader reader = null;
    try {
        List<Double> values = new LinkedList<>();
        values.add(0.1d);
        values.add(0.3d);
        values.add(0.5d);
        values.add(0.7d);
        values.add(0.11d);
        values.add(0.13d);
        values.add(0.17d);
        values.add(0.19d);
        values.add(0.23d);
        values.add(0.29d);
        byte[] bytes = toByteArray(values);
        String fvString = toDoubleString(bytes);
        String fieldName = "fvs";
        Document document = new Document();
        document.add(new TextField(fieldName, fvString, Field.Store.YES));
        writer.addDocument(document);
        writer.commit();
        reader = DirectoryReader.open(writer);
        assertSimQuery(analyzer, fieldName, fvString, reader);
    } finally {
        if (reader != null) {
            reader.close();
        }
        writer.close();
        directory.close();
    }
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) Document(org.apache.lucene.document.Document) LinkedList(java.util.LinkedList) IndexWriter(org.apache.lucene.index.IndexWriter) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) TextField(org.apache.lucene.document.TextField) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Test(org.junit.Test)

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