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/14 07:07:21 UTC
svn commit: r1631619 - in /jackrabbit/oak/trunk/oak-lucene/src:
main/java/org/apache/jackrabbit/oak/plugins/index/lucene/
test/java/org/apache/jackrabbit/oak/plugins/index/lucene/
Author: chetanm
Date: Tue Oct 14 05:07:21 2014
New Revision: 1631619
URL: http://svn.apache.org/r1631619
Log:
OAK-2005 - Use separate Lucene index for performing property related queries
Add support for property definitions. Individual property specific config can be specified by creating a child node with propertyName and then adding values there
Added:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java (with props)
jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1631619&r1=1631618&r2=1631619&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Tue Oct 14 05:07:21 2014
@@ -20,11 +20,15 @@
package org.apache.jackrabbit.oak.plugins.index.lucene;
import java.util.Collections;
+import java.util.Map;
import java.util.Set;
+import javax.annotation.CheckForNull;
import javax.jcr.PropertyType;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
@@ -53,6 +57,8 @@ public class IndexDefinition {
private final NodeBuilder definition;
+ private final Map<String, PropertyDefinition> propDefns;
+
public IndexDefinition(NodeBuilder defn) {
this.definition = defn;
PropertyState pst = defn.getProperty(INCLUDE_PROPERTY_TYPES);
@@ -75,6 +81,14 @@ public class IndexDefinition {
this.fullTextEnabled = getOptionalValue(defn, FULL_TEXT_ENABLED, true);
//Storage is disabled for non full text indexes
this.storageEnabled = this.fullTextEnabled && getOptionalValue(defn, EXPERIMENTAL_STORAGE, true);
+
+ Map<String, PropertyDefinition> propDefns = Maps.newHashMap();
+ for(String propName : includes){
+ if(defn.hasChildNode(propName)){
+ propDefns.put(propName, new PropertyDefinition(this, propName, defn.child(propName)));
+ }
+ }
+ this.propDefns = ImmutableMap.copyOf(propDefns);
}
boolean includeProperty(String name) {
@@ -119,6 +133,15 @@ public class IndexDefinition {
return LuceneIndexHelper.skipTokenization(propertyName);
}
+ @CheckForNull
+ public PropertyDefinition getPropDefn(String propName){
+ return propDefns.get(propName);
+ }
+
+ public boolean hasPropertyDefinition(String propName){
+ return propDefns.containsKey(propName);
+ }
+
//~------------------------------------------< Internal >
private static boolean getOptionalValue(NodeBuilder definition, String propName, boolean defaultVal){
Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java?rev=1631619&r1=1631618&r2=1631619&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexConstants.java Tue Oct 14 05:07:21 2014
@@ -66,4 +66,10 @@ public interface LuceneIndexConstants {
*/
String INCLUDE_PROPERTY_NAMES = "includePropertyNames";
+ /**
+ * Type of the property being indexed defined as part of property definition
+ * under the given index definition. Refer to {@ling javax.jcr.PropertyType}
+ * contants for the possible values
+ */
+ String PROP_TYPE = "propertyType";
}
Added: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java?rev=1631619&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java (added)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java Tue Oct 14 05:07:21 2014
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.index.lucene;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PropertyDefinition {
+ private static final Logger log = LoggerFactory.getLogger(PropertyDefinition.class);
+ private final String name;
+ private final NodeBuilder definition;
+
+ private final int propertyType;
+
+ public PropertyDefinition(IndexDefinition idxDefn, String name, NodeBuilder defn) {
+ this.name = name;
+ this.definition = defn;
+
+ int type = PropertyType.UNDEFINED;
+ if(defn.hasProperty(LuceneIndexConstants.PROP_TYPE)){
+ String typeName = defn.getString(LuceneIndexConstants.PROP_TYPE);
+ try{
+ type = PropertyType.valueFromName(typeName);
+ } catch (IllegalArgumentException e){
+ log.warn("Invalid property type {} for property {} in Index {}", typeName, name, idxDefn);
+ }
+ }
+ this.propertyType = type;
+ }
+
+ public int getPropertyType() {
+ return propertyType;
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java?rev=1631619&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java (added)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java Tue Oct 14 05:07:21 2014
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.plugins.index.lucene;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+import static com.google.common.collect.ImmutableSet.of;
+import static javax.jcr.PropertyType.TYPENAME_LONG;
+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.memory.PropertyStates.createProperty;
+import static org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class IndexDefinitionTest {
+ private NodeState root = INITIAL_CONTENT;
+
+ private NodeBuilder builder = root.builder();
+
+ @Test
+ public void fullTextEnabled() throws Exception{
+ IndexDefinition defn = new IndexDefinition(builder);
+ assertTrue("By default fulltext is enabled", defn.isFullTextEnabled());
+ assertTrue("By default everything is indexed", defn.includeProperty("foo"));
+ assertFalse("Property types need to be defined", defn.includePropertyType(PropertyType.DATE));
+ assertTrue("For fulltext storage is enabled", defn.isStored("foo"));
+
+ assertFalse(defn.skipTokenization("foo"));
+ assertTrue(defn.skipTokenization("jcr:uuid"));
+ }
+
+ @Test
+ public void propertyTypes() throws Exception{
+ builder.setProperty(createProperty(INCLUDE_PROPERTY_TYPES, of(TYPENAME_LONG), STRINGS));
+ builder.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo" , "bar"), STRINGS));
+ builder.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, false);
+ IndexDefinition defn = new IndexDefinition(builder);
+
+ assertFalse(defn.isFullTextEnabled());
+ assertFalse("If fulltext disabled then nothing stored",defn.isStored("foo"));
+
+ assertTrue(defn.includePropertyType(PropertyType.LONG));
+ assertFalse(defn.includePropertyType(PropertyType.STRING));
+
+ assertTrue(defn.includeProperty("foo"));
+ assertTrue(defn.includeProperty("bar"));
+ assertFalse(defn.includeProperty("baz"));
+
+ assertTrue(defn.skipTokenization("foo"));
+ }
+
+ @Test
+ public void propertyDefinition() throws Exception{
+ builder.child("foo").setProperty(LuceneIndexConstants.PROP_TYPE, PropertyType.TYPENAME_DATE);
+ builder.setProperty(createProperty(INCLUDE_PROPERTY_NAMES, of("foo" , "bar"), STRINGS));
+ IndexDefinition defn = new IndexDefinition(builder);
+
+ assertTrue(defn.hasPropertyDefinition("foo"));
+ assertFalse(defn.hasPropertyDefinition("bar"));
+
+ assertEquals(PropertyType.DATE, defn.getPropDefn("foo").getPropertyType());
+
+ }
+
+
+}
Propchange: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
------------------------------------------------------------------------------
svn:eol-style = native