use of org.apache.lucene.store.RAMDirectory in project lucene-solr by apache.
the class TestTryDelete method createIndex.
private static Directory createIndex() throws IOException {
Directory directory = new RAMDirectory();
IndexWriter writer = getWriter(directory);
for (int i = 0; i < 10; i++) {
Document doc = new Document();
doc.add(new StringField("foo", String.valueOf(i), Store.YES));
writer.addDocument(doc);
}
writer.commit();
writer.close();
return directory;
}
use of org.apache.lucene.store.RAMDirectory in project lucene-solr by apache.
the class TestSloppyPhraseQuery method checkPhraseQuery.
private float checkPhraseQuery(Document doc, PhraseQuery query, int slop, int expectedNumResults) throws Exception {
PhraseQuery.Builder builder = new PhraseQuery.Builder();
Term[] terms = query.getTerms();
int[] positions = query.getPositions();
for (int i = 0; i < terms.length; ++i) {
builder.add(terms[i], positions[i]);
}
builder.setSlop(slop);
query = builder.build();
MockDirectoryWrapper ramDir = new MockDirectoryWrapper(random(), new RAMDirectory());
RandomIndexWriter writer = new RandomIndexWriter(random(), ramDir, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));
writer.addDocument(doc);
IndexReader reader = writer.getReader();
IndexSearcher searcher = newSearcher(reader);
MaxFreqCollector c = new MaxFreqCollector();
searcher.search(query, c);
assertEquals("slop: " + slop + " query: " + query + " doc: " + doc + " Wrong number of hits", expectedNumResults, c.totalHits);
//QueryUtils.check(query,searcher);
writer.close();
reader.close();
ramDir.close();
// with these different tokens/distributions/lengths.. otherwise this test is very fragile.
return c.max;
}
use of org.apache.lucene.store.RAMDirectory in project lucene-solr by apache.
the class SweetSpotSimilarityTest method computeNorm.
private static float computeNorm(Similarity sim, String field, int length) throws IOException {
String value = IntStream.range(0, length).mapToObj(i -> "a").collect(Collectors.joining(" "));
Directory dir = new RAMDirectory();
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setSimilarity(sim));
w.addDocument(Collections.singleton(newTextField(field, value, Store.NO)));
DirectoryReader reader = DirectoryReader.open(w);
w.close();
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(sim);
Explanation expl = searcher.explain(new TermQuery(new Term(field, "a")), 0);
reader.close();
dir.close();
Explanation norm = findExplanation(expl, "fieldNorm");
assertNotNull(norm);
return norm.getValue();
}
use of org.apache.lucene.store.RAMDirectory in project lucene-solr by apache.
the class BaseCompressingDocValuesFormatTestCase method testUniqueValuesCompression.
public void testUniqueValuesCompression() throws IOException {
final Directory dir = new RAMDirectory();
final IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
final IndexWriter iwriter = new IndexWriter(dir, iwc);
final int uniqueValueCount = TestUtil.nextInt(random(), 1, 256);
final List<Long> values = new ArrayList<>();
final Document doc = new Document();
final NumericDocValuesField dvf = new NumericDocValuesField("dv", 0);
doc.add(dvf);
for (int i = 0; i < 300; ++i) {
final long value;
if (values.size() < uniqueValueCount) {
value = random().nextLong();
values.add(value);
} else {
value = RandomPicks.randomFrom(random(), values);
}
dvf.setLongValue(value);
iwriter.addDocument(doc);
}
iwriter.forceMerge(1);
final long size1 = dirSize(dir);
for (int i = 0; i < 20; ++i) {
dvf.setLongValue(RandomPicks.randomFrom(random(), values));
iwriter.addDocument(doc);
}
iwriter.forceMerge(1);
final long size2 = dirSize(dir);
// make sure the new longs did not cost 8 bytes each
assertTrue(size2 < size1 + 8 * 20);
}
use of org.apache.lucene.store.RAMDirectory in project lucene-solr by apache.
the class SpatialExample method init.
protected void init() {
//Typical geospatial context
// These can also be constructed from SpatialContextFactory
this.ctx = SpatialContext.GEO;
//results in sub-meter precision for geohash
int maxLevels = 11;
//TODO demo lookup by detail distance
// This can also be constructed from SpatialPrefixTreeFactory
SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);
this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField");
this.directory = new RAMDirectory();
}
Aggregations