Search in sources :

Example 36 with StringField

use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.

the class LuceneDocumentMaker method addNodeNameField.

/**
     * Extracts the local name of the current node ignoring any namespace prefix
     *
     * @param name node name
     */
private static void addNodeNameField(List<Field> fields, String name) {
    //TODO Need to check if it covers all cases
    int colon = name.indexOf(':');
    String value = colon < 0 ? name : name.substring(colon + 1);
    //For now just add a single term. Later we can look into using different analyzer
    //to analyze the node name and add multiple terms. Like add multiple terms for a
    //cameCase file name to allow faster like search
    fields.add(new StringField(FieldNames.NODE_NAME, value, Field.Store.NO));
}
Also used : StringField(org.apache.lucene.document.StringField)

Example 37 with StringField

use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.

the class LuceneDocumentMaker method addTypedFields.

private boolean addTypedFields(List<Field> fields, PropertyState property, String pname) {
    int tag = property.getType().tag();
    boolean fieldAdded = false;
    for (int i = 0; i < property.count(); i++) {
        Field f;
        if (tag == Type.LONG.tag()) {
            f = new LongField(pname, property.getValue(Type.LONG, i), Field.Store.NO);
        } else if (tag == Type.DATE.tag()) {
            String date = property.getValue(Type.DATE, i);
            f = new LongField(pname, FieldFactory.dateToLong(date), Field.Store.NO);
        } else if (tag == Type.DOUBLE.tag()) {
            f = new DoubleField(pname, property.getValue(Type.DOUBLE, i), Field.Store.NO);
        } else if (tag == Type.BOOLEAN.tag()) {
            f = new StringField(pname, property.getValue(Type.BOOLEAN, i).toString(), Field.Store.NO);
        } else {
            f = new StringField(pname, property.getValue(Type.STRING, i), Field.Store.NO);
        }
        fields.add(f);
        fieldAdded = true;
    }
    return fieldAdded;
}
Also used : FieldFactory.newFulltextField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newFulltextField) LongField(org.apache.lucene.document.LongField) StringField(org.apache.lucene.document.StringField) SortedSetDocValuesFacetField(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetField) FieldFactory.newDepthField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newDepthField) FieldFactory.newPropertyField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField) DoubleDocValuesField(org.apache.lucene.document.DoubleDocValuesField) FieldFactory.newPathField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField) NumericDocValuesField(org.apache.lucene.document.NumericDocValuesField) DoubleField(org.apache.lucene.document.DoubleField) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) FieldFactory.newAncestorsField(org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newAncestorsField) Field(org.apache.lucene.document.Field) LongField(org.apache.lucene.document.LongField) StringField(org.apache.lucene.document.StringField) DoubleField(org.apache.lucene.document.DoubleField)

Example 38 with StringField

use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.

the class LuceneDocumentMaker method indexNullCheckEnabledProps.

private boolean indexNullCheckEnabledProps(String path, List<Field> fields, NodeState state) {
    boolean fieldAdded = false;
    for (PropertyDefinition pd : indexingRule.getNullCheckEnabledProperties()) {
        if (isPropertyNull(state, pd)) {
            fields.add(new StringField(FieldNames.NULL_PROPS, pd.name, Field.Store.NO));
            fieldAdded = true;
        }
    }
    return fieldAdded;
}
Also used : StringField(org.apache.lucene.document.StringField)

Example 39 with StringField

use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.

the class DefaultIndexReaderFactoryTest method multipleReaders_SingleSuggester.

@Test
public void multipleReaders_SingleSuggester() throws Exception {
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    enabledSuggestorForSomeProp();
    defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    //Suggester field is only present for document in default mount
    Document doc = newDoc("/content/en");
    doc.add(new StringField(FieldNames.SUGGEST, "test", null));
    writer.updateDocument("/content/en", doc);
    writer.updateDocument("/libs/config", newDoc("/libs/config"));
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    //Suggester should be present for all though it may be empty
    for (LuceneIndexReader reader : readers) {
        assertNotNull(reader.getReader());
        assertNotNull(reader.getSuggestDirectory());
        assertNotNull(reader.getLookup());
    }
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) StringField(org.apache.lucene.document.StringField) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 40 with StringField

use of org.apache.lucene.document.StringField in project jackrabbit-oak by apache.

the class DefaultIndexReaderFactoryTest method suggesterDir.

@Test
public void suggesterDir() throws Exception {
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    enabledSuggestorForSomeProp();
    defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    Document doc = newDoc("/content/en");
    doc.add(new StringField(FieldNames.SUGGEST, "test", null));
    writer.updateDocument("/content/en", doc);
    writer.close(0);
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    LuceneIndexReader reader = readers.get(0);
    assertNotNull(reader.getReader());
    assertNotNull(reader.getSuggestDirectory());
    assertNotNull(reader.getLookup());
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) StringField(org.apache.lucene.document.StringField) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) 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