use of org.apache.lucene.document.StringField in project neo4j by neo4j.
the class PartitionedIndexStorageTest method randomDocument.
private static Document randomDocument() {
Document doc = new Document();
doc.add(new StringField("field", RandomStringUtils.randomAlphabetic(5), Field.Store.YES));
return doc;
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class IndexPlannerTest method createSampleDirectory.
private static Directory createSampleDirectory(long numOfDocs) throws IOException {
Directory dir = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(VERSION, LuceneIndexConstants.ANALYZER);
IndexWriter writer = new IndexWriter(dir, config);
for (int i = 0; i < numOfDocs; i++) {
Document doc = new Document();
doc.add(new StringField("foo", "bar" + i, Field.Store.NO));
writer.addDocument(doc);
}
writer.close();
return dir;
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method nullBehavior.
//OAK-3576
@Test
public void nullBehavior() throws Exception {
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
TestUtil.enableForFullText(props, "foo");
root.commit();
Tree rootTree = root.getTree("/").addChild("test");
//Note: augmentor behavior is tested elsewhere... we are just checking if default works
int testIndex = 1;
//both query and index augmentors are null (no exception expected)
checkSimpleBehavior(rootTree, testIndex++);
//Set a very sad query augmentor
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return FulltextQueryTermsProvider.DEFAULT.getSupportedTypes();
}
};
checkSimpleBehavior(rootTree, testIndex++);
//Set query augmentor... with null query
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
//Set query augmentor... with some query
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return new TermQuery(new Term("bar", "baz"));
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
factory.fulltextQueryTermsProvider = null;
//Set a very sad index augmentor
factory.indexFieldProvider = IndexFieldProvider.DEFAULT;
checkSimpleBehavior(rootTree, testIndex++);
//Set index augmentor... with null fields
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
//Set index augmentor... with some fields
factory.fulltextQueryTermsProvider = null;
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
List<Field> fields = Lists.newArrayList();
fields.add(new StringField("bar", "baz", Field.Store.NO));
return fields;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
//setup composite query term provider with one returning null query
factory.registerQueryTermsProvider(new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
});
factory.useSuperBehavior = true;
checkSimpleBehavior(rootTree, testIndex++);
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class DocumentQueueTest method createDoc.
private static LuceneDoc createDoc(String docPath, String fooValue) {
Document d1 = new Document();
d1.add(newPathField(docPath));
d1.add(new StringField("foo", fooValue, Field.Store.NO));
return LuceneDoc.forUpdate("/oak:index/fooIndex", docPath, d1);
}
use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.
the class DocumentQueueTest method updateDocument.
@Test
public void updateDocument() throws Exception {
IndexTracker tracker = createTracker();
NodeState indexed = createAndPopulateAsyncIndex(IndexingMode.NRT);
tracker.update(indexed);
DocumentQueue queue = new DocumentQueue(2, tracker, sameThreadExecutor());
Document d1 = new Document();
d1.add(newPathField("/a/b"));
d1.add(new StringField("foo", "a", Field.Store.NO));
queue.add(LuceneDoc.forUpdate("/oak:index/fooIndex", "/a/b", d1));
List<NRTIndex> indexes = indexFactory.getIndexes("/oak:index/fooIndex");
NRTIndex index = indexes.get(indexes.size() - 1);
assertEquals(1, index.getPrimaryReader().getReader().numDocs());
}
Aggregations