You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2014/10/31 07:19:49 UTC
svn commit: r1635684 - in /jackrabbit/oak/branches/1.0/oak-lucene/src:
main/java/org/apache/jackrabbit/oak/plugins/index/lucene/
test/java/org/apache/jackrabbit/oak/plugins/index/lucene/
Author: chetanm
Date: Fri Oct 31 06:19:49 2014
New Revision: 1635684
URL: http://svn.apache.org/r1635684
Log:
OAK-2005 - Use separate Lucene index for performing property related queries
Merging 1633032,1633123,1634504
Modified:
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorTest.java
jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1635684&r1=1635683&r2=1635684&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Fri Oct 31 06:19:49 2014
@@ -106,9 +106,10 @@ public class IndexDefinition {
this.storageEnabled = this.fullTextEnabled && getOptionalValue(defn, EXPERIMENTAL_STORAGE, true);
Map<String, PropertyDefinition> propDefns = Maps.newHashMap();
+ NodeBuilder propNode = defn.getChildNode(LuceneIndexConstants.PROP_NODE);
for(String propName : Iterables.concat(includes, orderedProps)){
- if(defn.hasChildNode(propName)){
- propDefns.put(propName, new PropertyDefinition(this, propName, defn.child(propName)));
+ if(propNode.hasChildNode(propName)){
+ propDefns.put(propName, new PropertyDefinition(this, propName, propNode.child(propName)));
}
}
this.propDefns = ImmutableMap.copyOf(propDefns);
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java?rev=1635684&r1=1635683&r2=1635684&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java Fri Oct 31 06:19:49 2014
@@ -71,7 +71,7 @@ public interface LuceneIndexConstants {
* under the given index definition. Refer to {@link javax.jcr.PropertyType}
* contants for the possible values
*/
- String PROP_TYPE = "propertyType";
+ String PROP_TYPE = "type";
/**
* Defines properties which would be used for ordering. If range queries are to
@@ -95,4 +95,9 @@ public interface LuceneIndexConstants {
* Name of the codec to be used for indexing
*/
String CODEC_NAME = "codec";
+
+ /**
+ * Child node name under which property details are provided
+ */
+ String PROP_NODE = "properties";
}
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java?rev=1635684&r1=1635683&r2=1635684&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java Fri Oct 31 06:19:49 2014
@@ -31,6 +31,7 @@ import static javax.jcr.PropertyType.TYP
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_TYPES;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_NODE;
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
import static org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
import static org.junit.Assert.assertEquals;
@@ -80,7 +81,7 @@ public class IndexDefinitionTest {
@Test
public void propertyDefinition() throws Exception{
- builder.child("foo").setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE);
+ builder.child(PROP_NODE).child("foo").setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE);
builder.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo" , "bar"), STRINGS));
IndexDefinition defn = new IndexDefinition(builder);
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorTest.java?rev=1635684&r1=1635683&r2=1635684&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorTest.java Fri Oct 31 06:19:49 2014
@@ -21,8 +21,10 @@ package org.apache.jackrabbit.oak.plugin
import java.io.IOException;
import java.text.SimpleDateFormat;
+import java.util.Arrays;
import java.util.Calendar;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EditorHook;
@@ -30,6 +32,7 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.test.ISO8601;
import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
@@ -38,6 +41,7 @@ import org.apache.lucene.search.NumericR
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
import org.junit.After;
import org.junit.Test;
@@ -149,11 +153,44 @@ public class LuceneIndexEditorTest {
assertEquals(2, getSearcher().getIndexReader().numDocs());
}
+ //@Test
+ public void checkLuceneIndexFileUpdates() throws Exception{
+ NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
+ NodeBuilder nb = newLuceneIndexDefinition(index, "lucene",
+ of(TYPENAME_STRING));
+ nb.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, false);
+ nb.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo" , "bar", "baz"), STRINGS));
+ //nb.removeProperty(REINDEX_PROPERTY_NAME);
+
+ NodeState before = builder.getNodeState();
+ builder.child("test").setProperty("foo", "fox is jumping");
+
+ //InfoStream.setDefault(new PrintStreamInfoStream(System.out));
+ before = commitAndDump(before, builder.getNodeState());
+
+ builder = before.builder();
+ builder.child("test2").setProperty("bar", "ship is sinking");
+ before = commitAndDump(before, builder.getNodeState());
+
+ builder = before.builder();
+ builder.child("test3").setProperty("baz", "horn is blowing");
+ before = commitAndDump(before, builder.getNodeState());
+
+ builder = before.builder();
+ builder.child("test2").remove();
+ before = commitAndDump(before, builder.getNodeState());
+
+ builder = before.builder();
+ builder.child("test2").setProperty("bar", "ship is back again");
+ before = commitAndDump(before, builder.getNodeState());
+ }
+
@After
public void releaseIndexNode(){
if(indexNode != null){
indexNode.release();
}
+ indexNode = null;
}
private String query(String query) throws IOException, ParseException {
@@ -179,6 +216,25 @@ public class LuceneIndexEditorTest {
return indexNode.getSearcher();
}
+ private NodeState commitAndDump(NodeState before, NodeState after) throws CommitFailedException, IOException {
+ NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
+ tracker.update(indexed);
+ dumpIndexDir();
+ return indexed;
+ }
+
+ private void dumpIndexDir() throws IOException {
+ Directory dir = ((DirectoryReader)getSearcher().getIndexReader()).directory();
+
+ System.out.println("================");
+ String[] fileNames = dir.listAll();
+ Arrays.sort(fileNames);
+ for (String file : fileNames){
+ System.out.printf("%s - %d %n", file, dir.fileLength(file));
+ }
+ releaseIndexNode();
+ }
+
static Calendar createCal(String dt) throws java.text.ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
Modified: jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1635684&r1=1635683&r2=1635684&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java (original)
+++ jackrabbit/oak/branches/1.0/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java Fri Oct 31 06:19:49 2014
@@ -56,6 +56,7 @@ import static org.apache.jackrabbit.oak.
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_NAMES;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.ORDERED_PROP_NAMES;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.PROP_NODE;
import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorTest.createCal;
import static org.apache.jackrabbit.oak.plugins.index.property.OrderedIndex.OrderDirection;
import static org.apache.jackrabbit.oak.plugins.memory.PropertyStates.createProperty;
@@ -112,7 +113,7 @@ public class LucenePropertyIndexTest ext
@Test
public void rangeQueriesWithLong() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
- Tree propIdx = idx.addChild("propa");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("propa");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_LONG);
root.commit();
@@ -139,7 +140,7 @@ public class LucenePropertyIndexTest ext
@Test
public void rangeQueriesWithDouble() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
- Tree propIdx = idx.addChild("propa");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("propa");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DOUBLE);
root.commit();
@@ -161,7 +162,7 @@ public class LucenePropertyIndexTest ext
@Test
public void rangeQueriesWithString() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
- idx.addChild("propa");
+ idx.addChild(PROP_NODE).addChild("propa");
root.commit();
Tree test = root.getTree("/").addChild("test");
@@ -187,7 +188,7 @@ public class LucenePropertyIndexTest ext
@Test
public void rangeQueriesWithDate() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
- Tree propIdx = idx.addChild("propa");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("propa");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE);
root.commit();
@@ -209,7 +210,7 @@ public class LucenePropertyIndexTest ext
@Test
public void likeQueriesWithString() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
- idx.addChild("propa");
+ idx.addChild(PROP_NODE).addChild("propa");
root.commit();
Tree test = root.getTree("/").addChild("test");
@@ -225,7 +226,7 @@ public class LucenePropertyIndexTest ext
@Test
public void nativeQueries() throws Exception {
Tree idx = createIndex("test1", of("propa", "propb"));
- idx.addChild("propa");
+ idx.addChild(PROP_NODE).addChild("propa");
idx.setProperty(LuceneIndexConstants.FUNC_NAME, "foo");
root.commit();
@@ -243,7 +244,7 @@ public class LucenePropertyIndexTest ext
public void indexDefinitionBelowRoot() throws Exception {
Tree parent = root.getTree("/").addChild("test");
Tree idx = createIndex(parent, "test1", of("propa", "propb"));
- idx.addChild("propa");
+ idx.addChild(PROP_NODE).addChild("propa");
root.commit();
Tree test = parent.addChild("test2");
@@ -257,7 +258,7 @@ public class LucenePropertyIndexTest ext
@Test
public void sortQueriesWithLong() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar"));
- Tree propIdx = idx.addChild("foo");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("foo");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_LONG);
root.commit();
@@ -269,7 +270,7 @@ public class LucenePropertyIndexTest ext
Tree idx = createIndex("test1", of("foo", "bar"));
idx.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("bar"), STRINGS));
idx.setProperty(createProperty(ORDERED_PROP_NAMES, of("foo"), STRINGS));
- Tree propIdx = idx.addChild("foo");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("foo");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_LONG);
root.commit();
@@ -295,7 +296,7 @@ public class LucenePropertyIndexTest ext
@Test
public void sortQueriesWithDouble() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar"));
- Tree propIdx = idx.addChild("foo");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("foo");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DOUBLE);
root.commit();
@@ -307,7 +308,7 @@ public class LucenePropertyIndexTest ext
Tree idx = createIndex("test1", of("foo", "bar"));
idx.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("bar"), STRINGS));
idx.setProperty(createProperty(ORDERED_PROP_NAMES, of("foo"), STRINGS));
- Tree propIdx = idx.addChild("foo");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("foo");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DOUBLE);
root.commit();
@@ -333,7 +334,7 @@ public class LucenePropertyIndexTest ext
@Test
public void sortQueriesWithString() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar"));
- idx.addChild("foo");
+ idx.addChild(PROP_NODE).addChild("foo");
root.commit();
assertSortedString();
@@ -344,7 +345,7 @@ public class LucenePropertyIndexTest ext
Tree idx = createIndex("test1", of("foo", "bar"));
idx.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("bar"), STRINGS));
idx.setProperty(createProperty(ORDERED_PROP_NAMES, of("foo"), STRINGS));
- idx.addChild("foo");
+ idx.addChild(PROP_NODE).addChild("foo");
root.commit();
assertSortedString();
@@ -369,7 +370,7 @@ public class LucenePropertyIndexTest ext
@Test
public void sortQueriesWithDate() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar"));
- Tree propIdx = idx.addChild("foo");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("foo");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE);
root.commit();
@@ -381,7 +382,7 @@ public class LucenePropertyIndexTest ext
Tree idx = createIndex("test1", of("foo", "bar"));
idx.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("bar"), STRINGS));
idx.setProperty(createProperty(ORDERED_PROP_NAMES, of("foo"), STRINGS));
- Tree propIdx = idx.addChild("foo");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("foo");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE);
root.commit();
@@ -407,7 +408,7 @@ public class LucenePropertyIndexTest ext
@Test
public void sortQueriesWithStringAndLong() throws Exception {
Tree idx = createIndex("test1", of("foo", "bar", "baz"));
- Tree propIdx = idx.addChild("baz");
+ Tree propIdx = idx.addChild(PROP_NODE).addChild("baz");
propIdx.setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_LONG);
root.commit();