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 2015/09/09 11:36:48 UTC
svn commit: r1701958 - in /jackrabbit/oak/branches/1.2: ./
oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/
oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/
Author: chetanm
Date: Wed Sep 9 09:36:45 2015
New Revision: 1701958
URL: http://svn.apache.org/r1701958
Log:
OAK-3367 - Boosting fields not working as expected
Merging 1701750, 1701768, 1701806, 1701948
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Sep 9 09:36:45 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673713,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1681955,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820
,1684868,1685023,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030,1693209,1693421,1693525-1693526,1694007,1694393-1694394,1695050,1695122,1695280,1695299,1695457,1695482,1695507,1695521,1695540,1696194,1696242,1696285,1696578,1696759,1696916,1697363,1697373,1697410,1697
582,1697589,1697616,1697672,1700191,1700231,1700397,1700506,1700571,1700727,1700749,1700769,1700775,1701619,1701733,1701743,1701814
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414-1673415,1673436,1673644,1673662-1673664,1673669,1673695,1673713,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678023,1678095-1678096,1678124,1678171,1678173,1678211,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679232,1679235,1679503,1679958,1679961,1680170,1680172,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680747,1680805-1680806,1680903,1681282,1681767,1681918,1681955,1682042,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683059,1683089,1683213,1683249,1683259,1683278,1683323,1683687,1683700,1684174-1684175,1684186,1684376,1684442,1684561,1684570,1684601,1684618,1684820
,1684868,1685023,1685075,1685370,1685552,1685589-1685590,1685840,1685964,1685977,1685989,1685999,1686023,1686032,1686097,1686162,1686229,1686234,1686253,1686414,1686780,1686854,1686857,1686971,1687053-1687055,1687175,1687196,1687198,1687220,1687239-1687240,1687301,1687441,1687553,1688089-1688090,1688172,1688179,1688349,1688421,1688436,1688453,1688616,1688622,1688634,1688636,1688817,1689003-1689004,1689008,1689577,1689581,1689623,1689810,1689828,1689831,1689833,1689903,1690017,1690043,1690047,1690057,1690247,1690249,1690634-1690637,1690650,1690669,1690674,1690885,1690941,1691139,1691151,1691159,1691167,1691183,1691188,1691210,1691280,1691307,1691331-1691333,1691345,1691384-1691385,1691401,1691509,1692133-1692134,1692156,1692250,1692274,1692363,1692382,1692478,1692955,1693002,1693030,1693209,1693421,1693525-1693526,1694007,1694393-1694394,1695050,1695122,1695280,1695299,1695457,1695482,1695507,1695521,1695540,1696194,1696242,1696285,1696578,1696759,1696916,1697363,1697373,1697410,1697
582,1697589,1697616,1697672,1700191,1700231,1700397,1700506,1700571,1700727,1700749,1700769,1700775,1701619,1701733,1701743,1701750,1701768,1701814
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java?rev=1701958&r1=1701957&r2=1701958&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java (original)
+++ jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinition.java Wed Sep 9 09:36:45 2015
@@ -624,6 +624,7 @@ class IndexDefinition implements Aggrega
private final List<NamePattern> namePatterns;
private final List<PropertyDefinition> nullCheckEnabledProperties;
private final List<PropertyDefinition> notNullCheckEnabledProperties;
+ private final List<PropertyDefinition> boostedProps;
private final boolean indexesAllNodesOfMatchingType;
private final boolean nodeNameIndexed;
@@ -647,12 +648,15 @@ class IndexDefinition implements Aggrega
List<NamePattern> namePatterns = newArrayList();
List<PropertyDefinition> nonExistentProperties = newArrayList();
List<PropertyDefinition> existentProperties = newArrayList();
+ List<PropertyDefinition> boostedProps = newArrayList();
List<Aggregate.Include> propIncludes = newArrayList();
- this.propConfigs = collectPropConfigs(config, namePatterns, propIncludes, nonExistentProperties, existentProperties);
+ this.propConfigs = collectPropConfigs(config, namePatterns, propIncludes, nonExistentProperties,
+ existentProperties, boostedProps);
this.propAggregate = new Aggregate(nodeTypeName, propIncludes);
this.aggregate = combine(propAggregate, nodeTypeName);
this.namePatterns = ImmutableList.copyOf(namePatterns);
+ this.boostedProps = ImmutableList.copyOf(boostedProps);
this.nullCheckEnabledProperties = ImmutableList.copyOf(nonExistentProperties);
this.notNullCheckEnabledProperties = ImmutableList.copyOf(existentProperties);
this.fulltextEnabled = aggregate.hasNodeAggregates() || hasAnyFullTextEnabledProperty();
@@ -681,6 +685,7 @@ class IndexDefinition implements Aggrega
this.propAggregate = original.propAggregate;
this.nullCheckEnabledProperties = original.nullCheckEnabledProperties;
this.notNullCheckEnabledProperties = original.notNullCheckEnabledProperties;
+ this.boostedProps = original.boostedProps;
this.aggregate = combine(propAggregate, nodeTypeName);
this.fulltextEnabled = aggregate.hasNodeAggregates() || original.fulltextEnabled;
this.indexesAllNodesOfMatchingType = allMatchingNodeByTypeIndexed();
@@ -717,6 +722,10 @@ class IndexDefinition implements Aggrega
return notNullCheckEnabledProperties;
}
+ public List<PropertyDefinition> getBoostedProps() {
+ return boostedProps;
+ }
+
@Override
public String toString() {
String str = "IndexRule: "+ nodeTypeName;
@@ -815,7 +824,8 @@ class IndexDefinition implements Aggrega
private Map<String, PropertyDefinition> collectPropConfigs(NodeState config, List<NamePattern> patterns,
List<Aggregate.Include> propAggregate,
List<PropertyDefinition> nonExistentProperties,
- List<PropertyDefinition> existentProperties) {
+ List<PropertyDefinition> existentProperties,
+ List<PropertyDefinition> boostedProps) {
Map<String, PropertyDefinition> propDefns = newHashMap();
NodeState propNode = config.getChildNode(LuceneIndexConstants.PROP_NODE);
@@ -852,6 +862,14 @@ class IndexDefinition implements Aggrega
if (pd.notNullCheckEnabled){
existentProperties.add(pd);
}
+
+ //Include props with name, boosted and nodeScopeIndex
+ if (pd.nodeScopeIndex
+ && pd.boost != PropertyDefinition.DEFAULT_BOOST
+ && pd.analyzed
+ && !pd.isRegexp){
+ boostedProps.add(pd);
+ }
}
}
return ImmutableMap.copyOf(propDefns);
Modified: jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java?rev=1701958&r1=1701957&r2=1701958&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java (original)
+++ jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditor.java Wed Sep 9 09:36:45 2015
@@ -434,7 +434,6 @@ public class LuceneIndexEditor implement
if (pd.nodeScopeIndex) {
Field field = newFulltextField(value);
- field.setBoost(pd.boost);
fields.add(field);
}
dirty = true;
Modified: jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java?rev=1701958&r1=1701957&r2=1701958&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java (original)
+++ jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndex.java Wed Sep 9 09:36:45 2015
@@ -1073,7 +1073,7 @@ public class LucenePropertyIndex impleme
private boolean visitTerm(String propertyName, String text, String boost, boolean not) {
String p = getLuceneFieldName(propertyName, pr);
- Query q = tokenToQuery(text, p, analyzer);
+ Query q = tokenToQuery(text, p, pr.indexingRule, analyzer);
if (q == null) {
return false;
}
@@ -1119,6 +1119,25 @@ public class LucenePropertyIndex impleme
return p;
}
+ private static Query tokenToQuery(String text, String fieldName, IndexingRule indexingRule, Analyzer analyzer) {
+ //Expand the query on fulltext field
+ if (FieldNames.FULLTEXT.equals(fieldName) &&
+ !indexingRule.getBoostedProps().isEmpty()) {
+ BooleanQuery in = new BooleanQuery();
+ for (PropertyDefinition pd : indexingRule.getBoostedProps()) {
+ Query q = tokenToQuery(text, FieldNames.createAnalyzedFieldName(pd.name), analyzer);
+ q.setBoost(pd.boost);
+ in.add(q, BooleanClause.Occur.SHOULD);
+ }
+
+ //Add the query for actual fulltext field also. That query would
+ //not be boosted
+ in.add(tokenToQuery(text, fieldName, analyzer), BooleanClause.Occur.SHOULD);
+ return in;
+ }
+ return tokenToQuery(text, fieldName, analyzer);
+ }
+
static Query tokenToQuery(String text, String fieldName, Analyzer analyzer) {
if (analyzer == null) {
return null;
Modified: jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java?rev=1701958&r1=1701957&r2=1701958&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java (original)
+++ jackrabbit/oak/branches/1.2/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/PropertyDefinition.java Wed Sep 9 09:36:45 2015
@@ -105,7 +105,13 @@ class PropertyDefinition {
this.index = getOptionalValue(defn, LuceneIndexConstants.PROP_INDEX, true);
this.stored = getOptionalValue(defn, LuceneIndexConstants.PROP_USE_IN_EXCERPT, false);
this.nodeScopeIndex = getOptionalValue(defn, LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, false);
- this.analyzed = getOptionalValue(defn, LuceneIndexConstants.PROP_ANALYZED, false);
+
+ //If boost is specified then that field MUST be analyzed
+ if (defn.hasProperty(FIELD_BOOST)){
+ this.analyzed = true;
+ } else {
+ this.analyzed = getOptionalValue(defn, LuceneIndexConstants.PROP_ANALYZED, false);
+ }
//If node is not set for full text then a property definition indicates that definition is for property index
this.propertyIndex = getOptionalValue(defn, LuceneIndexConstants.PROP_PROPERTY_INDEX, false);
Modified: jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java?rev=1701958&r1=1701957&r2=1701958&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/IndexDefinitionTest.java Wed Sep 9 09:36:45 2015
@@ -25,12 +25,12 @@ import com.google.common.collect.Immutab
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
+import org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.IndexingRule;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.TokenizerChain;
import org.apache.jackrabbit.oak.plugins.tree.TreeFactory;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.lucene.codecs.Codec;
-import org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition.IndexingRule;
import org.junit.Test;
import static com.google.common.collect.ImmutableSet.of;
@@ -625,6 +625,30 @@ public class IndexDefinitionTest {
assertFalse(idxDefn.isSuggestEnabled());
}
+ @Test
+ public void analyzedEnabledForBoostedField() throws Exception {
+ NodeBuilder rules = builder.child(INDEX_RULES);
+ rules.child("nt:folder");
+ TestUtil.child(rules, "nt:folder/properties/prop1")
+ .setProperty(LuceneIndexConstants.FIELD_BOOST, 3.0)
+ .setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+ TestUtil.child(rules, "nt:folder/properties/prop2")
+ .setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true)
+ .setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+
+ IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
+
+ IndexingRule rule1 = defn.getApplicableIndexingRule(newTree(newNode("nt:folder")));
+ assertNotNull(rule1);
+
+ PropertyDefinition pd = rule1.getConfig("prop1");
+ assertEquals(3.0f, pd.boost, 0);
+ assertTrue("Analyzed should be assumed to be true for boosted fields", pd.analyzed);
+ assertFalse(rule1.getConfig("prop2").analyzed);
+
+ assertEquals(1, rule1.getBoostedProps().size());
+ }
+
//TODO indexesAllNodesOfMatchingType - with nullCheckEnabled
private static IndexingRule getRule(IndexDefinition defn, String typeName){
Modified: jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java?rev=1701958&r1=1701957&r2=1701958&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LucenePropertyIndexTest.java Wed Sep 9 09:36:45 2015
@@ -48,6 +48,7 @@ import org.apache.jackrabbit.oak.api.Blo
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.ContentRepository;
import org.apache.jackrabbit.oak.api.PropertyValue;
+import org.apache.jackrabbit.oak.api.Result;
import org.apache.jackrabbit.oak.api.ResultRow;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
@@ -67,6 +68,7 @@ import org.apache.jackrabbit.oak.spi.que
import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
import org.apache.jackrabbit.util.ISO8601;
import org.junit.After;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -75,6 +77,7 @@ import static com.google.common.collect.
import static java.util.Arrays.asList;
import static org.apache.jackrabbit.JcrConstants.JCR_CONTENT;
import static org.apache.jackrabbit.JcrConstants.JCR_DATA;
+import static org.apache.jackrabbit.oak.api.QueryEngine.NO_BINDINGS;
import static org.apache.jackrabbit.oak.api.QueryEngine.NO_MAPPINGS;
import static org.apache.jackrabbit.oak.api.Type.NAMES;
import static org.apache.jackrabbit.oak.api.Type.STRINGS;
@@ -433,8 +436,8 @@ public class LucenePropertyIndexTest ext
System.out.println(explain);
String luceneQuery = explain.substring(0, explain.indexOf('\n'));
assertEquals("[nt:unstructured] as [content] /* lucene:test1(/oak:index/test1) " +
- "+(tags:Products:A tags:Products:A/B) " +
- "+(tags:DocTypes:A tags:DocTypes:B tags:DocTypes:C tags:ProblemType:A)",
+ "+(tags:Products:A tags:Products:A/B) " +
+ "+(tags:DocTypes:A tags:DocTypes:B tags:DocTypes:C tags:ProblemType:A)",
luceneQuery);
}
@@ -954,10 +957,10 @@ public class LucenePropertyIndexTest ext
root.commit();
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo]", Lists
- .newArrayList(Iterables.concat(Lists.newArrayList("/test/a"), getSortedPaths(tuples, OrderDirection.ASC))));
+ .newArrayList(Iterables.concat(Lists.newArrayList("/test/a"), getSortedPaths(tuples, OrderDirection.ASC))));
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo] DESC", Lists
- .newArrayList(Iterables.concat(getSortedPaths(tuples, OrderDirection.DESC), Lists.newArrayList("/test/a")
- )));
+ .newArrayList(Iterables.concat(getSortedPaths(tuples, OrderDirection.DESC), Lists.newArrayList("/test/a")
+ )));
}
void assertSortedString() throws CommitFailedException {
@@ -1046,7 +1049,7 @@ public class LucenePropertyIndexTest ext
// Add the path of property added as timestamp string in the sorted list
assertOrderedQuery("select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo]",
Lists.newArrayList(Iterables.concat(Lists.newArrayList("/test/n0"),
- getSortedPaths(tuples, OrderDirection.ASC))));
+ getSortedPaths(tuples, OrderDirection.ASC))));
// Append the path of property added as timestamp string to the sorted list
assertOrderedQuery(
"select [jcr:path] from [nt:base] where [bar] = 'baz' order by [foo] DESC", Lists
@@ -1084,6 +1087,7 @@ public class LucenePropertyIndexTest ext
public void indexTimeFieldBoost() throws Exception {
// Index Definition
Tree idx = createIndex("test1", of("propa", "propb", "propc"));
+ TestUtil.useV2(idx);
idx.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, true);
Tree propNode = idx.addChild(PROP_NODE);
@@ -1111,12 +1115,65 @@ public class LucenePropertyIndexTest ext
root.commit();
String queryString = "//* [jcr:contains(., 'foo' )]";
+ String explain = explainXpath(queryString);
+ System.out.println(explain);
// verify results ordering
// which should be /test/c (boost = 4.0), /test/a(boost = 2.0), /test/b (1.0)
assertOrderedQuery(queryString, asList("/test/c", "/test/a", "/test/b"), XPATH, true);
}
@Test
+ public void boostTitleOverDescription() throws Exception{
+ NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
+
+ Tree idx = createIndex("test1", of("propa", "propb"));
+ Tree props = TestUtil.newRulePropTree(idx, TestUtil.NT_TEST);
+
+ Tree title = props.addChild("title");
+ title.setProperty(LuceneIndexConstants.PROP_NAME, "jcr:content/jcr:title");
+ title.setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+ title.setProperty(LuceneIndexConstants.FIELD_BOOST, 4.0);
+
+ Tree desc = props.addChild("desc");
+ desc.setProperty(LuceneIndexConstants.PROP_NAME, "jcr:content/jcr:description");
+ desc.setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+ desc.setProperty(LuceneIndexConstants.FIELD_BOOST, 2.0);
+
+ Tree text = props.addChild("text");
+ text.setProperty(LuceneIndexConstants.PROP_NAME, "jcr:content/text");
+ text.setProperty(LuceneIndexConstants.PROP_NODE_SCOPE_INDEX, true);
+
+ root.commit();
+
+ Tree test = root.getTree("/").addChild("test");
+ Tree a = createNodeWithType(test, "a", "oak:TestNode").addChild("jcr:content");
+ a.setProperty("jcr:title", "Batman");
+ a.setProperty("jcr:description", "Silent angel of Gotham");
+ a.setProperty("text", "once upon a time a long text phrase so as to add penalty to /test/a and nullifying boost");
+
+ Tree b = createNodeWithType(test, "b", "oak:TestNode").addChild("jcr:content");
+ b.setProperty("jcr:title", "Superman");
+ b.setProperty("jcr:description", "Tale of two heroes Superman and Batman");
+ b.setProperty("text", "some stuff");
+
+ Tree c = createNodeWithType(test, "c", "oak:TestNode").addChild("jcr:content");
+ c.setProperty("jcr:title", "Ironman");
+ c.setProperty("jcr:description", "New kid in the town");
+ c.setProperty("text", "Friend of batman?");
+ root.commit();
+
+ String queryString = "//element(*,oak:TestNode)[jcr:contains(., 'batman')]";
+ String explain = explainXpath(queryString);
+
+ //Assert that Lucene query generated has entries for all included boosted fields
+ assertThat(explain, containsString("full:jcr:content/jcr:title:batman^4.0"));
+ assertThat(explain, containsString("full:jcr:content/jcr:description:batman^2.0"));
+ assertThat(explain, containsString(":fulltext:batman"));
+
+ assertOrderedQuery(queryString, asList("/test/a", "/test/b", "/test/c"), XPATH, true);
+ }
+
+ @Test
public void sortQueriesWithJcrScore() throws Exception {
Tree idx = createIndex("test1", of("propa", "n0", "n1", "n2"));
root.commit();
@@ -1503,6 +1560,13 @@ public class LucenePropertyIndexTest ext
return executeQuery(explain, "JCR-SQL2").get(0);
}
+ private String explainXpath(String query) throws ParseException {
+ String explain = "explain " + query;
+ Result result = executeQuery(explain, "xpath", NO_BINDINGS);
+ ResultRow row = Iterables.getOnlyElement(result.getRows());
+ return row.getValue("plan").getValue(Type.STRING);
+ }
+
private Tree createIndex(String name, Set<String> propNames) throws CommitFailedException {
Tree index = root.getTree("/");
return createIndex(index, name, propNames);