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