Search in sources :

Example 6 with ByteBuffersDirectory

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

the class TestTextTxn 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;
}
Also used : ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory)

Example 7 with ByteBuffersDirectory

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

the class TestTextNonTxn 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;
}
Also used : ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory)

Example 8 with ByteBuffersDirectory

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

the class TestTextNonTxnTDB1 method create.

private static Dataset create() {
    Dataset ds1 = TDBFactory.createDataset();
    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;
}
Also used : ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Directory(org.apache.lucene.store.Directory)

Example 9 with ByteBuffersDirectory

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

the class TestLuceneWithMultipleThreads method testReadInMiddleOfWrite.

@Test
public void testReadInMiddleOfWrite() throws InterruptedException, ExecutionException {
    final DatasetGraphText dsg = (DatasetGraphText) TextDatasetFactory.createLucene(DatasetGraphFactory.create(), new ByteBuffersDirectory(), new TextIndexConfig(entDef));
    final Dataset ds = DatasetFactory.wrap(dsg);
    final ExecutorService execService = Executors.newSingleThreadExecutor();
    final Future<?> f = execService.submit(new Runnable() {

        @Override
        public void run() {
            // Hammer the dataset with a series of read queries
            while (!Thread.interrupted()) {
                dsg.begin(ReadWrite.READ);
                try {
                    QueryExecution qExec = QueryExecutionFactory.create("select * where { ?s ?p ?o }", ds);
                    ResultSet rs = qExec.execSelect();
                    while (rs.hasNext()) {
                        rs.next();
                    }
                    dsg.commit();
                } finally {
                    dsg.end();
                }
            }
        }
    });
    dsg.begin(ReadWrite.WRITE);
    try {
        Model m = ds.getDefaultModel();
        m.add(ResourceFactory.createResource("http://example.org/"), RDFS.label, "entity");
        // Sleep for a bit so that the reader thread can get in between these two writes
        Thread.sleep(100);
        m.add(ResourceFactory.createResource("http://example.org/"), RDFS.comment, "comment");
        dsg.commit();
    } finally {
        dsg.end();
    }
    execService.shutdownNow();
    execService.awaitTermination(1000, TimeUnit.MILLISECONDS);
    // If there was an exception in the read thread then Future.get() will throw an ExecutionException
    assertTrue(f.get() == null);
}
Also used : ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test)

Example 10 with ByteBuffersDirectory

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

the class TestTextGraphIndexExtra method textDataset.

static Dataset textDataset(Dataset dataset) {
    EntityDefinition entdef = new EntityDefinition("uri", "text", "graph", rdfsLabel);
    TextIndex textIndex = TextDatasetFactory.createLuceneIndex(new ByteBuffersDirectory(), new TextIndexConfig(entdef));
    return TextDatasetFactory.create(dataset, textIndex, true);
}
Also used : ByteBuffersDirectory(org.apache.lucene.store.ByteBuffersDirectory)

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