use of org.apache.lucene.document.StringField in project lucene-solr by apache.
the class TestBinaryDocValuesUpdates method doc.
private Document doc(int id) {
Document doc = new Document();
doc.add(new StringField("id", "doc-" + id, Store.NO));
doc.add(new BinaryDocValuesField("val", toBytes(id + 1)));
return doc;
}
use of org.apache.lucene.document.StringField in project lucene-solr by apache.
the class TestBinaryDocValuesUpdates method testUpdateBinaryDVFieldWithSameNameAsPostingField.
public void testUpdateBinaryDVFieldWithSameNameAsPostingField() throws Exception {
// this used to fail because FieldInfos.Builder neglected to update
// globalFieldMaps.docValuesTypes map
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new StringField("f", "mock-value", Store.NO));
doc.add(new BinaryDocValuesField("f", toBytes(5L)));
writer.addDocument(doc);
writer.commit();
writer.updateBinaryDocValue(new Term("f", "mock-value"), "f", toBytes(17L));
writer.close();
DirectoryReader r = DirectoryReader.open(dir);
BinaryDocValues bdv = r.leaves().get(0).reader().getBinaryDocValues("f");
assertEquals(0, bdv.nextDoc());
assertEquals(17, getValue(bdv));
r.close();
dir.close();
}
use of org.apache.lucene.document.StringField in project lucene-solr by apache.
the class TestBinaryDocValuesUpdates method testUpdateTwoNonexistingTerms.
public void testUpdateTwoNonexistingTerms() throws Exception {
Directory dir = newDirectory();
IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = new Document();
doc.add(new StringField("id", "doc", Store.NO));
doc.add(new BinaryDocValuesField("f1", toBytes(1L)));
writer.addDocument(doc);
// update w/ multiple nonexisting terms in same field
writer.updateBinaryDocValue(new Term("c", "foo"), "f1", toBytes(2L));
writer.updateBinaryDocValue(new Term("c", "bar"), "f1", toBytes(2L));
writer.close();
DirectoryReader reader = DirectoryReader.open(dir);
assertEquals(1, reader.leaves().size());
BinaryDocValues bdv = reader.leaves().get(0).reader().getBinaryDocValues("f1");
assertEquals(0, bdv.nextDoc());
assertEquals(1L, getValue(bdv));
reader.close();
dir.close();
}
use of org.apache.lucene.document.StringField in project lucene-solr by apache.
the class TermInSetQueryTest method testPullOneTermsEnum.
public void testPullOneTermsEnum() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
Document doc = new Document();
doc.add(new StringField("foo", "1", Store.NO));
w.addDocument(doc);
DirectoryReader reader = w.getReader();
w.close();
final AtomicInteger counter = new AtomicInteger();
DirectoryReader wrapped = new TermsCountingDirectoryReaderWrapper(reader, counter);
final List<BytesRef> terms = new ArrayList<>();
// enough terms to avoid the rewrite
final int numTerms = TestUtil.nextInt(random(), TermInSetQuery.BOOLEAN_REWRITE_TERM_COUNT_THRESHOLD + 1, 100);
for (int i = 0; i < numTerms; ++i) {
final BytesRef term = new BytesRef(RandomStrings.randomUnicodeOfCodepointLength(random(), 10));
terms.add(term);
}
assertEquals(0, new IndexSearcher(wrapped).count(new TermInSetQuery("bar", terms)));
// missing field
assertEquals(0, counter.get());
new IndexSearcher(wrapped).count(new TermInSetQuery("foo", terms));
assertEquals(1, counter.get());
wrapped.close();
dir.close();
}
use of org.apache.lucene.document.StringField in project lucene-solr by apache.
the class TestBooleanScorer method testSparseClauseOptimization.
public void testSparseClauseOptimization() throws IOException {
// When some windows have only one scorer that can match, the scorer will
// directly call the collector in this window
Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
Document emptyDoc = new Document();
final int numDocs = atLeast(10);
for (int d = 0; d < numDocs; ++d) {
for (int i = random().nextInt(5000); i >= 0; --i) {
w.addDocument(emptyDoc);
}
Document doc = new Document();
for (String value : Arrays.asList("foo", "bar", "baz")) {
if (random().nextBoolean()) {
doc.add(new StringField("field", value, Store.NO));
}
}
}
for (int i = TestUtil.nextInt(random(), 3000, 5000); i >= 0; --i) {
w.addDocument(emptyDoc);
}
if (random().nextBoolean()) {
w.forceMerge(1);
}
IndexReader reader = w.getReader();
IndexSearcher searcher = newSearcher(reader);
Query query = new BooleanQuery.Builder().add(new BoostQuery(new TermQuery(new Term("field", "foo")), 3), Occur.SHOULD).add(new BoostQuery(new TermQuery(new Term("field", "bar")), 3), Occur.SHOULD).add(new BoostQuery(new TermQuery(new Term("field", "baz")), 3), Occur.SHOULD).build();
// duel BS1 vs. BS2
QueryUtils.check(random(), query, searcher);
reader.close();
w.close();
dir.close();
}
Aggregations