Search in sources :

Example 1 with LuceneIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition in project jackrabbit-oak by apache.

the class LuceneIndexEditorTest method testLuceneWithNonFullText.

@Test
public void testLuceneWithNonFullText() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder nb = newLuceneIndexDefinitionV2(index, "lucene", of(TYPENAME_STRING));
    nb.setProperty(FulltextIndexConstants.FULL_TEXT_ENABLED, false);
    nb.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo", "price", "weight", "bool", "creationTime"), STRINGS));
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, nb.getNodeState(), "/foo");
    NodeState before = builder.getNodeState();
    builder.child("test").setProperty("foo", "fox is jumping");
    builder.child("test").setProperty("bar", "kite is flying");
    builder.child("test").setProperty("price", 100);
    builder.child("test").setProperty("weight", 10.0);
    builder.child("test").setProperty("bool", true);
    builder.child("test").setProperty("truth", true);
    builder.child("test").setProperty("creationTime", createCal("05/06/2014"));
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker.update(indexed);
    assertNull("Fulltext search should not work", query("foo:fox", defn));
    assertEquals("/test", getPath(new TermQuery(new Term("foo", "fox is jumping"))));
    assertNull("bar must NOT be indexed", getPath(new TermQuery(new Term("bar", "kite is flying"))));
    // Long
    assertEquals("/test", getPath(NumericRangeQuery.newDoubleRange("weight", 8D, 12D, true, true)));
    // Double
    assertEquals("/test", getPath(NumericRangeQuery.newLongRange("price", 100L, 100L, true, true)));
    // Boolean
    assertEquals("/test", getPath(new TermQuery(new Term("bool", "true"))));
    assertNull("truth must NOT be indexed", getPath(new TermQuery(new Term("truth", "true"))));
    // Date
    assertEquals("/test", getPath(NumericRangeQuery.newLongRange("creationTime", dateToTime("05/05/2014"), dateToTime("05/07/2014"), true, true)));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Term(org.apache.lucene.index.Term) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Test(org.junit.Test)

Example 2 with LuceneIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition in project jackrabbit-oak by apache.

the class LuceneIndexEditorTest method numDocs.

private int numDocs(Mount m) throws IOException {
    String indexDirName = MultiplexersLucene.getIndexDirName(m);
    NodeBuilder defnBuilder = builder.child(INDEX_DEFINITIONS_NAME).child("lucene");
    Directory d = new OakDirectory(defnBuilder, indexDirName, new LuceneIndexDefinition(root, defnBuilder.getNodeState(), "/foo"), true);
    IndexReader r = DirectoryReader.open(d);
    return r.numDocs();
}
Also used : IndexReader(org.apache.lucene.index.IndexReader) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Directory(org.apache.lucene.store.Directory) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory)

Example 3 with LuceneIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition in project jackrabbit-oak by apache.

the class DefaultIndexWriterTest method indexUpdated.

@Test
public void indexUpdated() throws Exception {
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, builder.getNodeState(), "/foo");
    DefaultIndexWriter writer = createWriter(defn, false);
    Document document = new Document();
    document.add(newPathField("/a/b"));
    writer.updateDocument("/a/b", document);
    assertTrue(writer.close(0));
}
Also used : Document(org.apache.lucene.document.Document) LuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition) Test(org.junit.Test)

Example 4 with LuceneIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition in project jackrabbit-oak by apache.

the class DefaultIndexWriterTest method writeInitializedUponReindex.

@Test
public void writeInitializedUponReindex() throws Exception {
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, builder.getNodeState(), "/foo");
    DefaultIndexWriter writer = createWriter(defn, true);
    assertTrue(writer.close(0));
}
Also used : LuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition) Test(org.junit.Test)

Example 5 with LuceneIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition in project jackrabbit-oak by apache.

the class DefaultIndexWriterTest method indexWriterConfig_Scheduler_Remote.

@Test
public void indexWriterConfig_Scheduler_Remote() throws Exception {
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, builder.getNodeState(), "/foo");
    DefaultIndexWriter writer = createWriter(defn, true);
    IndexWriter w = writer.getWriter();
    assertThat(w.getConfig().getMergeScheduler(), instanceOf(SerialMergeScheduler.class));
}
Also used : SerialMergeScheduler(org.apache.lucene.index.SerialMergeScheduler) IndexWriter(org.apache.lucene.index.IndexWriter) LuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition) Test(org.junit.Test)

Aggregations

LuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexDefinition)52 Test (org.junit.Test)44 Directory (org.apache.lucene.store.Directory)17 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)15 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)14 File (java.io.File)13 Document (org.apache.lucene.document.Document)9 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 NullInputStream (org.apache.commons.io.input.NullInputStream)6 Iterables (com.google.common.collect.Iterables)5 List (java.util.List)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Sets (com.google.common.collect.Sets)4 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)4