use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestAddIndexes method testWithPendingDeletes3.
public void testWithPendingDeletes3() throws IOException {
// main directory
Directory dir = newDirectory();
// auxiliary directory
Directory aux = newDirectory();
setUpDirs(dir, aux);
IndexWriter writer = newWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND));
// docs, so 10 pending deletes:
for (int i = 0; i < 20; i++) {
Document doc = new Document();
doc.add(newStringField("id", "" + (i % 10), Field.Store.NO));
doc.add(newTextField("content", "bbb " + i, Field.Store.NO));
doc.add(new IntPoint("doc", i));
doc.add(new IntPoint("doc2d", i, i));
doc.add(new NumericDocValuesField("dv", i));
writer.updateDocument(new Term("id", "" + (i % 10)), doc);
}
// Deletes one of the 10 added docs, leaving 9:
PhraseQuery q = new PhraseQuery("content", "bbb", "14");
writer.deleteDocuments(q);
writer.addIndexes(aux);
writer.forceMerge(1);
writer.commit();
verifyNumDocs(dir, 1039);
verifyTermDocs(dir, new Term("content", "aaa"), 1030);
verifyTermDocs(dir, new Term("content", "bbb"), 9);
writer.close();
dir.close();
aux.close();
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestAddIndexes method addDocs2.
private void addDocs2(IndexWriter writer, int numDocs) throws IOException {
for (int i = 0; i < numDocs; i++) {
Document doc = new Document();
doc.add(newTextField("content", "bbb", Field.Store.NO));
doc.add(new IntPoint("doc", i));
doc.add(new IntPoint("doc2d", i, i));
doc.add(new NumericDocValuesField("dv", i));
writer.addDocument(doc);
}
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointValues method testTieBreakByDocID.
public void testTieBreakByDocID() throws Exception {
Directory dir = newFSDirectory(createTempDir());
IndexWriterConfig iwc = newIndexWriterConfig();
IndexWriter w = new IndexWriter(dir, iwc);
Document doc = new Document();
doc.add(new IntPoint("int", 17));
for (int i = 0; i < 300000; i++) {
w.addDocument(doc);
if (random().nextInt(1000) == 17) {
w.commit();
}
}
IndexReader r = DirectoryReader.open(w);
for (LeafReaderContext ctx : r.leaves()) {
PointValues points = ctx.reader().getPointValues("int");
points.intersect(new IntersectVisitor() {
int lastDocID = -1;
@Override
public void visit(int docID) {
if (docID < lastDocID) {
fail("docs out of order: docID=" + docID + " but lastDocID=" + lastDocID);
}
lastDocID = docID;
}
@Override
public void visit(int docID, byte[] packedValue) {
visit(docID);
}
@Override
public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
if (random().nextBoolean()) {
return Relation.CELL_CROSSES_QUERY;
} else {
return Relation.CELL_INSIDE_QUERY;
}
}
});
}
r.close();
w.close();
dir.close();
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointValues method testIllegalTooManyDimensions.
public void testIllegalTooManyDimensions() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
IndexWriter w = new IndexWriter(dir, iwc);
Document doc = new Document();
byte[][] values = new byte[PointValues.MAX_DIMENSIONS + 1][];
for (int i = 0; i < values.length; i++) {
values[i] = new byte[4];
}
expectThrows(IllegalArgumentException.class, () -> {
doc.add(new BinaryPoint("dim", values));
});
Document doc2 = new Document();
doc2.add(new IntPoint("dim", 17));
w.addDocument(doc2);
w.close();
dir.close();
}
use of org.apache.lucene.document.IntPoint in project lucene-solr by apache.
the class TestPointValues method testMergedStatsAllPointsDeleted.
public void testMergedStatsAllPointsDeleted() throws IOException {
Directory dir = new RAMDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
w.addDocument(new Document());
Document doc = new Document();
doc.add(new IntPoint("field", Integer.MIN_VALUE));
doc.add(new StringField("delete", "yes", Store.NO));
w.addDocument(doc);
w.forceMerge(1);
w.deleteDocuments(new Term("delete", "yes"));
w.addDocument(new Document());
w.forceMerge(1);
IndexReader reader = DirectoryReader.open(w);
assertNull(PointValues.getMinPackedValue(reader, "field"));
assertNull(PointValues.getMaxPackedValue(reader, "field"));
assertEquals(0, PointValues.getDocCount(reader, "field"));
assertEquals(0, PointValues.size(reader, "field"));
}
Aggregations