Search in sources :

Example 31 with StringField

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;
}
Also used : StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document)

Example 32 with StringField

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;
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 33 with StringField

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++);
}
Also used : IndexFieldProvider(org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider) TermQuery(org.apache.lucene.search.TermQuery) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Set(java.util.Set) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) Nonnull(javax.annotation.Nonnull) FulltextQueryTermsProvider(org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider) Term(org.apache.lucene.index.Term) Analyzer(org.apache.lucene.analysis.Analyzer) StringField(org.apache.lucene.document.StringField) Tree(org.apache.jackrabbit.oak.api.Tree) List(java.util.List) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 34 with StringField

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);
}
Also used : StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document)

Example 35 with StringField

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());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexTracker(org.apache.jackrabbit.oak.plugins.index.lucene.IndexTracker) StringField(org.apache.lucene.document.StringField) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Aggregations

StringField (org.apache.lucene.document.StringField)323 Document (org.apache.lucene.document.Document)302 Directory (org.apache.lucene.store.Directory)227 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)129 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)94 Term (org.apache.lucene.index.Term)90 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)82 BytesRef (org.apache.lucene.util.BytesRef)73 IndexSearcher (org.apache.lucene.search.IndexSearcher)57 DirectoryReader (org.apache.lucene.index.DirectoryReader)56 BinaryDocValuesField (org.apache.lucene.document.BinaryDocValuesField)55 ArrayList (java.util.ArrayList)54 TextField (org.apache.lucene.document.TextField)54 IndexReader (org.apache.lucene.index.IndexReader)51 Field (org.apache.lucene.document.Field)50 TermQuery (org.apache.lucene.search.TermQuery)50 IndexWriter (org.apache.lucene.index.IndexWriter)45 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)43 NRTCachingDirectory (org.apache.lucene.store.NRTCachingDirectory)43 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)40