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));
}
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();
}
}
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");
}
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();
}
}
}
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();
}
}
Aggregations