use of org.apache.lucene.store.ByteBuffersDirectory in project jena by apache.
the class TestTextTxnTDB method create.
private Dataset create() {
Dataset ds1 = factory.create();
Directory dir = new ByteBuffersDirectory();
EntityDefinition eDef = new EntityDefinition("iri", "text");
eDef.setPrimaryPredicate(RDFS.label);
TextIndex tidx = new TextIndexLucene(dir, new TextIndexConfig(eDef));
Dataset ds = TextDatasetFactory.create(ds1, tidx);
return ds;
}
use of org.apache.lucene.store.ByteBuffersDirectory in project jena by apache.
the class TestBuildTextDataset method createCode.
public static Dataset createCode() {
// Base data
Dataset ds1 = DatasetFactory.create();
// Define the index mapping
EntityDefinition entDef = new EntityDefinition("uri", "text");
entDef.setPrimaryPredicate(RDFS.label);
// Lucene, in memory.
Directory dir = new ByteBuffersDirectory();
// Join together into a dataset
Dataset ds = TextDatasetFactory.createLucene(ds1, dir, new TextIndexConfig(entDef));
return ds;
}
use of org.apache.lucene.store.ByteBuffersDirectory in project OpenGrok by OpenGrok.
the class SuggesterSearcherTest method setUpClass.
@BeforeAll
public static void setUpClass() throws IOException {
dir = new ByteBuffersDirectory();
try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) {
Document doc1 = new Document();
Document doc2 = new Document();
doc1.add(new TextField("test", "opengrok opengrok2", Field.Store.NO));
doc2.add(new TextField("test", "opengrok test", Field.Store.NO));
iw.addDocument(doc1);
iw.addDocument(doc2);
}
IndexReader ir = DirectoryReader.open(dir);
searcher = new SuggesterSearcher(ir, 10);
}
use of org.apache.lucene.store.ByteBuffersDirectory in project OpenGrok by OpenGrok.
the class CustomSloppyPhraseScorerTest method test.
public static void test(final int slop, final int offset, final String[] terms, final Integer[] expectedPositions) throws IOException {
Directory dir = new ByteBuffersDirectory();
try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) {
Document doc = new Document();
doc.add(new TextField("test", "zero one two three four five six seven eight nine ten", Field.Store.NO));
iw.addDocument(doc);
}
CustomPhraseQuery query = new CustomPhraseQuery(slop, "test", terms);
query.setOffset(offset);
try (IndexReader ir = DirectoryReader.open(dir)) {
IndexSearcher is = new IndexSearcher(ir);
Weight w = query.createWeight(is, ScoreMode.COMPLETE_NO_SCORES, 1);
LeafReaderContext context = ir.getContext().leaves().get(0);
Scorer scorer = w.scorer(context);
TwoPhaseIterator it = scorer.twoPhaseIterator();
int correctDoc = -1;
int docId;
while ((docId = it.approximation().nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
if (it.matches()) {
correctDoc = docId;
}
}
BitIntsHolder bs = (BitIntsHolder) ((PhraseScorer) scorer).getPositions(correctDoc);
assertThat(toSet(bs), contains(expectedPositions));
}
}
use of org.apache.lucene.store.ByteBuffersDirectory in project OpenGrok by OpenGrok.
the class SuggesterProjectDataTest method testRemove.
@Test
public void testRemove() throws IOException {
Directory dir = new ByteBuffersDirectory();
Path tempDir = Files.createTempDirectory("test");
try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) {
Document doc = new Document();
doc.add(new TextField("test", "text", Field.Store.NO));
iw.addDocument(doc);
}
SuggesterProjectData data = new SuggesterProjectData(dir, tempDir, false, Collections.singleton("test"));
data.init();
data.remove();
assertFalse(tempDir.toFile().exists());
}
Aggregations