Search in sources :

Example 46 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project lucene-skos by behas.

the class AbstractFilterTest method setUp.

@Before
protected void setUp() throws Exception {
    // adding some test data
    skosEngine = new SKOSEngineMock();
    skosEngine.addEntry("http://example.com/concept/1", SKOSType.PREF, "jumps");
    skosEngine.addEntry("http://example.com/concept/1", SKOSType.ALT, "leaps", "hops");
    skosEngine.addEntry("http://example.com/concept/2", SKOSType.PREF, "quick");
    skosEngine.addEntry("http://example.com/concept/2", SKOSType.ALT, "fast", "speedy");
    skosEngine.addEntry("http://example.com/concept/3", SKOSType.PREF, "over");
    skosEngine.addEntry("http://example.com/concept/3", SKOSType.ALT, "above");
    skosEngine.addEntry("http://example.com/concept/4", SKOSType.PREF, "lazy");
    skosEngine.addEntry("http://example.com/concept/4", SKOSType.ALT, "apathic", "sluggish");
    skosEngine.addEntry("http://example.com/concept/5", SKOSType.PREF, "dog");
    skosEngine.addEntry("http://example.com/concept/5", SKOSType.ALT, "canine", "pooch");
    skosEngine.addEntry("http://example.com/concept/6", SKOSType.PREF, "united nations");
    skosEngine.addEntry("http://example.com/concept/6", SKOSType.ALT, "UN");
    skosEngine.addEntry("http://example.com/concept/7", SKOSType.PREF, "lazy dog");
    skosEngine.addEntry("http://example.com/concept/7", SKOSType.ALT, "Odie");
    this.directory = new RAMDirectory();
}
Also used : SKOSEngineMock(at.ac.univie.mminf.luceneSKOS.skos.engine.mock.SKOSEngineMock) RAMDirectory(org.apache.lucene.store.RAMDirectory) Before(org.junit.Before)

Example 47 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project lucene-skos by behas.

the class AbstractTermExpansionTest method noExpansion.

/**
   * This test indexes a sample metadata record (=lucene document) having a
   * "title", "description", and "subject" field, which contains plain subject
   * terms.
   * <p/>
   * A search for "arms" doesn't return that record because the term "arms" is
   * not explicitly contained in the record (document).
   *
   * @throws IOException
   * @throws LockObtainFailedException
   * @throws CorruptIndexException
   */
@Test
public void noExpansion() throws IOException {
    /* defining the document to be indexed */
    Document doc = new Document();
    doc.add(new Field("title", "Spearhead", TextField.TYPE_STORED));
    doc.add(new Field("description", "Roman iron spearhead. The spearhead was attached to one end of a wooden shaft..." + "The spear was mainly a thrusting weapon, but could also be thrown. " + "It was the principal weapon of the auxiliary soldier... " + "(second - fourth century, Arbeia Roman Fort).", TextField.TYPE_NOT_STORED));
    doc.add(new Field("subject", "weapons", TextField.TYPE_NOT_STORED));
    /* setting up a writer with a default (simple) analyzer */
    writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new SimpleAnalyzer()));
    /* adding the document to the index */
    writer.addDocument(doc);
    /* defining a query that searches over all fields */
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new TermQuery(new Term("title", "arms")), BooleanClause.Occur.SHOULD).add(new TermQuery(new Term("description", "arms")), BooleanClause.Occur.SHOULD).add(new TermQuery(new Term("subject", "arms")), BooleanClause.Occur.SHOULD);
    /* creating a new searcher */
    searcher = new IndexSearcher(DirectoryReader.open(writer, false));
    TopDocs results = searcher.search(builder.build(), 10);
    /* no results are returned since there is no term match */
    assertEquals(0, results.totalHits);
}
Also used : SimpleAnalyzer(org.apache.lucene.analysis.core.SimpleAnalyzer) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) Field(org.apache.lucene.document.Field) TextField(org.apache.lucene.document.TextField) Test(org.junit.Test)

Example 48 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project geode by apache.

the class RawIndexRepositoryFactory method computeIndexRepository.

@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
    final IndexRepository repo;
    if (oldRepository != null) {
        oldRepository.cleanup();
    }
    LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
    BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
    Directory dir = null;
    if (indexForRaw.withPersistence()) {
        String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId);
        File location = new File(index.getName(), bucketLocation);
        if (!location.exists()) {
            location.mkdirs();
        }
        dir = new NIOFSDirectory(location.toPath());
    } else {
        dir = new RAMDirectory();
    }
    IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer());
    IndexWriter writer = new IndexWriter(dir, config);
    return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "");
}
Also used : NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexWriter(org.apache.lucene.index.IndexWriter) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexRepositoryImpl(org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)

Example 49 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project jackrabbit by apache.

the class IndexInputStreamTest method checkStream.

private void checkStream(int size, int buffer) throws IOException {
    Random rand = new Random();
    byte[] data = new byte[size];
    rand.nextBytes(data);
    Directory dir = new RAMDirectory();
    IndexOutput out = dir.createOutput("test");
    out.writeBytes(data, data.length);
    out.close();
    InputStream in = new IndexInputStream(dir.openInput("test"));
    if (buffer != 0) {
        in = new BufferedInputStream(in, buffer);
    }
    byte[] buf = new byte[3];
    int len;
    int pos = 0;
    while ((len = in.read(buf)) > -1) {
        for (int i = 0; i < len; i++, pos++) {
            assertEquals(data[pos], buf[i]);
        }
    }
    in.close();
    // assert length
    assertEquals(data.length, pos);
}
Also used : Random(java.util.Random) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IndexOutput(org.apache.lucene.store.IndexOutput) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 50 with RAMDirectory

use of org.apache.lucene.store.RAMDirectory in project jackrabbit by apache.

the class IndexOutputStreamTest method checkStream.

private void checkStream(int size, int buffer) throws IOException {
    Random rand = new Random();
    byte[] data = new byte[size];
    rand.nextBytes(data);
    Directory dir = new RAMDirectory();
    OutputStream out = new IndexOutputStream(dir.createOutput("test"));
    if (buffer != 0) {
        out = new BufferedOutputStream(out, buffer);
    }
    out.write(data);
    out.close();
    byte[] buf = new byte[3];
    int pos = 0;
    IndexInput in = dir.openInput("test");
    for (; ; ) {
        int len = (int) Math.min(buf.length, in.length() - pos);
        in.readBytes(buf, 0, len);
        for (int i = 0; i < len; i++, pos++) {
            assertEquals(data[pos], buf[i]);
        }
        if (len == 0) {
            // EOF
            break;
        }
    }
    in.close();
    // assert length
    assertEquals(data.length, pos);
}
Also used : Random(java.util.Random) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IndexInput(org.apache.lucene.store.IndexInput) BufferedOutputStream(java.io.BufferedOutputStream) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Aggregations

RAMDirectory (org.apache.lucene.store.RAMDirectory)183 Directory (org.apache.lucene.store.Directory)101 IndexWriter (org.apache.lucene.index.IndexWriter)82 Document (org.apache.lucene.document.Document)75 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)73 IndexSearcher (org.apache.lucene.search.IndexSearcher)43 IndexReader (org.apache.lucene.index.IndexReader)41 Test (org.junit.Test)35 TextField (org.apache.lucene.document.TextField)33 Field (org.apache.lucene.document.Field)29 Term (org.apache.lucene.index.Term)25 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)21 Before (org.junit.Before)21 IOException (java.io.IOException)19 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)19 Analyzer (org.apache.lucene.analysis.Analyzer)18 TopDocs (org.apache.lucene.search.TopDocs)16 DirectoryReader (org.apache.lucene.index.DirectoryReader)15 FilterDirectory (org.apache.lucene.store.FilterDirectory)15 FieldType (org.apache.lucene.document.FieldType)13