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 to...@apache.org on 2014/04/03 10:27:04 UTC

svn commit: r1584280 - in /jackrabbit/oak/trunk: oak-parent/ oak-solr-core/ oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/ oak-solr-core/src/main/resources/solr/oak/conf/ oak-solr-core/src/test/java/org/apache/jackrabbi...

Author: tommaso
Date: Thu Apr  3 08:27:03 2014
New Revision: 1584280

URL: http://svn.apache.org/r1584280
Log:
OAK-1671 - use Solr RHs instead of SCs in native queries

Modified:
    jackrabbit/oak/trunk/oak-parent/pom.xml
    jackrabbit/oak/trunk/oak-solr-core/pom.xml
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
    jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml
    jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml

Modified: jackrabbit/oak/trunk/oak-parent/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-parent/pom.xml?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-parent/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-parent/pom.xml Thu Apr  3 08:27:03 2014
@@ -47,7 +47,7 @@
     <mongo.db>MongoMKDB</mongo.db>
     <mongo.db2>MongoMKDB2</mongo.db2>
     <segment.db>SegmentMK</segment.db>
-    <lucene.version>4.7.0</lucene.version>
+    <lucene.version>4.7.1</lucene.version>
     <!-- Note that we're using SLF4J API version 1.7 when compiling     -->
     <!-- core Oak components but more recent SLF4J and Logback versions -->
     <!-- when compiling and running test cases and the oak-run jar.     -->

Modified: jackrabbit/oak/trunk/oak-solr-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/pom.xml?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-core/pom.xml Thu Apr  3 08:27:03 2014
@@ -137,19 +137,19 @@
         <dependency>
             <groupId>org.apache.lucene</groupId>
             <artifactId>lucene-test-framework</artifactId>
-            <version>4.7.0</version>
+            <version>${lucene.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.lucene</groupId>
             <artifactId>lucene-core</artifactId>
-            <version>4.7.0</version>
+            <version>${lucene.version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.lucene</groupId>
             <artifactId>lucene-analyzers-common</artifactId>
-            <version>4.7.0</version>
+            <version>${lucene.version}</version>
             <scope>test</scope>
         </dependency>
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrQueryIndex.java Thu Apr  3 08:27:03 2014
@@ -52,6 +52,7 @@ import static org.apache.jackrabbit.oak.
 public class SolrQueryIndex implements FulltextQueryIndex {
 
     private static final String NATIVE_SOLR_QUERY = "native*solr";
+    private static final String NATIVE_LUCENE_QUERY = "native*lucene";
 
     public static final String TYPE = "solr";
 
@@ -109,12 +110,15 @@ public class SolrQueryIndex implements F
         if (propertyRestrictions != null && !propertyRestrictions.isEmpty()) {
             for (Filter.PropertyRestriction pr : propertyRestrictions) {
                 // native query support
-                if (NATIVE_SOLR_QUERY.equals(pr.propertyName)) {
+                if (NATIVE_SOLR_QUERY.equals(pr.propertyName) || NATIVE_LUCENE_QUERY.equals(pr.propertyName)) {
                     String nativeQueryString = String.valueOf(pr.first.getValue(pr.first.getType()));
                     if (isSupportedHttpRequest(nativeQueryString)) {
                         // pass through the native HTTP Solr request
                         String requestHandlerString = nativeQueryString.substring(0, nativeQueryString.indexOf('?'));
                         if (!"select".equals(requestHandlerString)) {
+                            if (requestHandlerString.charAt(0) != '/') {
+                                requestHandlerString = "/" + requestHandlerString;
+                            }
                             solrQuery.setRequestHandler(requestHandlerString);
                         }
                         String parameterString = nativeQueryString.substring(nativeQueryString.indexOf('?') + 1);
@@ -123,6 +127,23 @@ public class SolrQueryIndex implements F
                             if (kv.length != 2) {
                                 throw new RuntimeException("Unparsable native HTTP Solr query");
                             } else {
+                                if ("stream.body".equals(kv[0])) {
+                                    kv[0] = "q";
+                                    String mltFlString = "mlt.fl=";
+                                    int mltFlIndex = parameterString.indexOf(mltFlString);
+                                    if (mltFlIndex > -1) {
+                                        int beginIndex = mltFlIndex + mltFlString.length();
+                                        int endIndex = parameterString.indexOf('&',beginIndex);
+                                        String fields;
+                                        if (endIndex > beginIndex) {
+                                            fields = parameterString.substring(beginIndex, endIndex);
+                                        }
+                                        else {
+                                            fields = parameterString.substring(beginIndex);
+                                        }
+                                        kv[1] = "_query_:\"{!dismax qf="+fields+" q.op=OR}"+kv[1]+"\"";
+                                    }
+                                }
                                 solrQuery.setParam(kv[0], kv[1]);
                             }
                         }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/schema.xml Thu Apr  3 08:27:03 2014
@@ -103,6 +103,7 @@
     <field name="ignored" type="ignored" multiValued="true"/>
     <field name="catch_all" type="text_general" indexed="true" stored="false" multiValued="true"/>
     <field name="_version_" type="long" indexed="true" stored="true"/>
+    <field name=":path" type="string" indexed="true" stored="false"/>
 
     <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
     <dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>
@@ -136,5 +137,6 @@
   <copyField source="path_exact" dest="path_anc"/>
   <copyField source="path_exact" dest="path_des"/>
   <copyField source="path_exact" dest="path_child"/>
+    <copyField source="path_exact" dest=":path"/>
   <copyField source="*" dest="catch_all"/>
 </schema>

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/resources/solr/oak/conf/solrconfig.xml Thu Apr  3 08:27:03 2014
@@ -1079,6 +1079,8 @@
                     startup="lazy"
                     class="solr.FieldAnalysisRequestHandler" />
 
+    <requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
+    </requestHandler>
 
     <!-- Document Analysis Handler
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/query/SolrIndexQueryTest.java Thu Apr  3 08:27:03 2014
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.TestUtils;
 import org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.solr.util.SolrIndexInitializer;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.query.AbstractQueryTest;
 import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
@@ -66,6 +67,7 @@ public class SolrIndexQueryTest extends 
         solrServer = provider.getSolrServer();
         try {
             return new Oak().with(new InitialContent())
+                    .with(new SolrIndexInitializer())
                     .with(new OpenSecurityProvider())
                     .with(new CompositeQueryIndexProvider(
                             new SolrQueryIndexProvider(provider, provider),
@@ -181,7 +183,7 @@ public class SolrIndexQueryTest extends 
         Tree test = tree.addChild("test");
         test.addChild("a").setProperty("name", "Hello");
         test.addChild("b").setProperty("name", "World");
-        tree.addChild("c");
+        test.addChild("c");
         root.commit();
 
         Iterator<String> strings = executeQuery(nativeQueryString, "JCR-SQL2").iterator();
@@ -212,14 +214,14 @@ public class SolrIndexQueryTest extends 
     }
 
     @Test
-    public void testNativeSolrNestedQuery() throws Exception {
+    public void testNativeSolrLocalParams() throws Exception {
         String nativeQueryString = "select [jcr:path] from [nt:base] where native('solr', '_query_:\"{!dismax qf=catch_all q.op=OR}hello world\"')";
 
         Tree tree = root.getTree("/");
         Tree test = tree.addChild("test");
         test.addChild("a").setProperty("name", "Hello");
         test.addChild("b").setProperty("name", "World");
-        tree.addChild("c");
+        test.addChild("c");
         root.commit();
 
         Iterator<String> strings = executeQuery(nativeQueryString, "JCR-SQL2").iterator();
@@ -238,7 +240,7 @@ public class SolrIndexQueryTest extends 
         Tree test = tree.addChild("test");
         test.addChild("a").setProperty("name", "Hello World, today weather is nice");
         test.addChild("b").setProperty("name", "Cheers World, today weather is quite nice");
-        tree.addChild("c");
+        test.addChild("c").setProperty("name", "Halo Welt, today sky is cloudy");
         root.commit();
 
         Iterator<String> strings = executeQuery(nativeQueryString, "JCR-SQL2").iterator();
@@ -250,7 +252,27 @@ public class SolrIndexQueryTest extends 
     }
 
     @Test
+    public void testNativeMLTQueryWithStream() throws Exception {
+        String nativeQueryString = "select [jcr:path] from [nt:base] where native('solr', 'mlt?stream.body=world is nice today&mlt.fl=name&mlt.mindf=0&mlt.mintf=0')";
+
+        Tree tree = root.getTree("/");
+        Tree test = tree.addChild("test");
+        test.addChild("a").setProperty("name", "Hello World, today weather is nice");
+        test.addChild("b").setProperty("name", "Cheers World, today weather is quite nice");
+        test.addChild("c").setProperty("name", "Halo Welt, today sky is cloudy");
+        root.commit();
+
+        Iterator<String> strings = executeQuery(nativeQueryString, "JCR-SQL2").iterator();
+        assertTrue(strings.hasNext());
+        assertEquals("/test/a", strings.next());
+        assertTrue(strings.hasNext());
+        assertEquals("/test/c", strings.next());
+        assertFalse(strings.hasNext());
+    }
+
+    @Test
     public void nativeSolr() throws Exception {
         test("native_solr.txt");
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/schema.xml Thu Apr  3 08:27:03 2014
@@ -110,6 +110,7 @@
         <field name="ignored" type="ignored" multiValued="true"/>
         <field name="catch_all" type="text_general" indexed="true" stored="false" multiValued="true"/>
         <field name="_version_" type="long" indexed="true" stored="true"/>
+        <field name=":path" type="string" indexed="true" stored="false"/>
 
         <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
         <dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>
@@ -146,5 +147,6 @@
     <copyField source="path_exact" dest="path_anc"/>
     <copyField source="path_exact" dest="path_des"/>
     <copyField source="path_exact" dest="path_child"/>
+    <copyField source="path_exact" dest=":path"/>
     <copyField source="*" dest="catch_all"/>
 </schema>

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml?rev=1584280&r1=1584279&r2=1584280&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/resources/solr/oak/conf/solrconfig.xml Thu Apr  3 08:27:03 2014
@@ -48,7 +48,7 @@
        If a "./lib" directory exists in your instanceDir, all files
        found in it are included as if you had used the following
        syntax...
-       
+
               <lib dir="./lib" />
     -->
 
@@ -82,7 +82,7 @@
     <lib dir="/total/crap/dir/ignored"/>
 
     <!-- an exact 'path' can be used instead of a 'dir' to specify a
-       specific file.  This will cause a serious error to be logged if 
+       specific file.  This will cause a serious error to be logged if
        it can't be loaded.
     -->
     <!--
@@ -100,7 +100,7 @@
 
 
     <!-- The DirectoryFactory to use for indexes.
-       
+
        solr.StandardDirectoryFactory is filesystem
        based and tries to pick the best implementation for the current
        JVM and platform.  solr.NRTCachingDirectoryFactory, the default,
@@ -273,7 +273,7 @@ Lucene will flush based on whichever lim
 
 
     <!-- JMX
-       
+
        This example enables JMX if and only if an existing MBeanServer
        is found, use this if you want to configure JMX through JVM
        parameters. Remove this to disable exposing Solr configuration
@@ -283,7 +283,7 @@ Lucene will flush based on whichever lim
     -->
     <jmx/>
     <!-- If you want to connect to a particular server, specify the
-       agentId 
+       agentId
     -->
     <!-- <jmx agentId="myAgent" /> -->
     <!-- If you want to start a new MBeanServer, specify the serviceUrl -->
@@ -400,7 +400,7 @@ Lucene will flush based on whichever lim
        be specified.
     -->
     <!--
-     <indexReaderFactory name="IndexReaderFactory" 
+     <indexReaderFactory name="IndexReaderFactory"
                          class="solr.StandardIndexReaderFactory">
        <int name="setTermIndexDivisor">12</int>
      </indexReaderFactory >
@@ -729,7 +729,7 @@ Lucene will flush based on whichever lim
        like so: http://host/app/[core/]select?qt=name  If no qt is
        given, then the requestHandler that declares default="true" will be
        used or the one named "standard".
-       
+
        If a Request Handler is declared with startup="lazy", then it will
        not be initialized until the first request that uses it.
 
@@ -830,7 +830,7 @@ current implementation relies on the upd
 
 
     <!-- A Robust Example
-       
+
        This example SearchHandler declaration shows off usage of the
        SearchHandler with many defaults declared
 
@@ -934,7 +934,7 @@ current implementation relies on the upd
 
 
     <!-- Update Request Handler.
-       
+
        http://wiki.apache.org/solr/UpdateXmlMessages
 
        The canonical Request Handler for Modifying the Index through
@@ -943,11 +943,11 @@ current implementation relies on the upd
        Note: Since solr1.1 requestHandlers requires a valid content
        type header if posted in the body. For example, curl now
        requires: -H 'Content-type:text/xml; charset=utf-8'
-       
-       To override the request content type and force a specific 
-       Content-type, use the request parameter: 
+
+       To override the request content type and force a specific
+       Content-type, use the request parameter:
          ?update.contentType=text/csv
-       
+
        This handler will pick a response format to match the input
        if the 'wt' parameter is not explicit
     -->
@@ -977,7 +977,7 @@ current implementation relies on the upd
 
     <!-- Solr Cell Update Request Handler
 
-       http://wiki.apache.org/solr/ExtractingRequestHandler 
+       http://wiki.apache.org/solr/ExtractingRequestHandler
 
     -->
     <requestHandler name="/update/extract"
@@ -1055,7 +1055,7 @@ current implementation relies on the upd
     <!-- Admin Handlers
 
        Admin Handlers - This will register all the standard admin
-       RequestHandlers.  
+       RequestHandlers.
     -->
     <requestHandler name="/admin/"
                     class="solr.admin.AdminHandlers"/>
@@ -1069,14 +1069,14 @@ current implementation relies on the upd
      <requestHandler name="/admin/file"       class="solr.admin.ShowFileRequestHandler" >
     -->
     <!-- If you wish to hide files under ${solr.home}/conf, explicitly
-       register the ShowFileRequestHandler using: 
+       register the ShowFileRequestHandler using:
     -->
     <!--
-     <requestHandler name="/admin/file" 
+     <requestHandler name="/admin/file"
                      class="solr.admin.ShowFileRequestHandler" >
        <lst name="invariants">
-         <str name="hidden">synonyms.txt</str> 
-         <str name="hidden">anotherfile.txt</str> 
+         <str name="hidden">synonyms.txt</str>
+         <str name="hidden">anotherfile.txt</str>
        </lst>
      </requestHandler>
     -->
@@ -1110,10 +1110,10 @@ current implementation relies on the upd
        The SolrReplicationHandler supports replicating indexes from a
        "master" used for indexing and "slaves" used for queries.
 
-       http://wiki.apache.org/solr/SolrReplication 
+       http://wiki.apache.org/solr/SolrReplication
 
-       It is also neccessary for SolrCloud to function (in Cloud mode, the 
-       replication handler is used to bulk transfer segments when nodes 
+       It is also neccessary for SolrCloud to function (in Cloud mode, the
+       replication handler is used to bulk transfer segments when nodes
        are added or need to recover).
 
        https://wiki.apache.org/solr/SolrCloud/
@@ -1280,7 +1280,7 @@ current implementation relies on the upd
 
        IN OTHER WORDS, THERE IS REALLY GOOD CHANCE THE SETUP BELOW IS
        NOT WHAT YOU WANT FOR YOUR PRODUCTION SYSTEM!
-       
+
        See http://wiki.apache.org/solr/SpellCheckComponent for details
        on the request parameters.
     -->
@@ -1318,8 +1318,8 @@ current implementation relies on the upd
 
        This is purely as an example.
 
-       In reality you will likely want to add the component to your 
-       already specified request handlers. 
+       In reality you will likely want to add the component to your
+       already specified request handlers.
     -->
     <requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy">
         <lst name="defaults">
@@ -1411,8 +1411,8 @@ current implementation relies on the upd
 
        This is purely as an example.
 
-       In reality you will likely want to add the component to your 
-       already specified request handlers. 
+       In reality you will likely want to add the component to your
+       already specified request handlers.
     -->
     <requestHandler name="/clustering"
                     startup="lazy"
@@ -1600,8 +1600,8 @@ current implementation relies on the upd
        on the fly based on the hash code of some other fields.  This
        example has overwriteDupes set to false since we are using the
        id field as the signatureField and Solr will maintain
-       uniqueness based on that anyway.  
-       
+       uniqueness based on that anyway.
+
     -->
     <!--
      <updateRequestProcessorChain name="dedupe">
@@ -1672,7 +1672,7 @@ current implementation relies on the upd
        overridden...
     -->
     <!--
-     <queryResponseWriter name="xml" 
+     <queryResponseWriter name="xml"
                           default="true"
                           class="solr.XMLResponseWriter" />
      <queryResponseWriter name="json" class="solr.JSONResponseWriter"/>
@@ -1700,7 +1700,7 @@ current implementation relies on the upd
 
     <!-- XSLT response writer transforms the XML output by any xslt file found
        in Solr's conf/xslt directory.  Changes to xslt files are checked for
-       every xsltCacheLifetimeSeconds.  
+       every xsltCacheLifetimeSeconds.
     -->
     <queryResponseWriter name="xslt" class="solr.XSLTResponseWriter">
         <int name="xsltCacheLifetimeSeconds">5</int>
@@ -1728,7 +1728,7 @@ current implementation relies on the upd
     -->
     <!-- example of registering a custom function parser  -->
     <!--
-     <valueSourceParser name="myfunc" 
+     <valueSourceParser name="myfunc"
                         class="com.mycompany.MyValueSourceParser" />
     -->
 
@@ -1741,12 +1741,12 @@ current implementation relies on the upd
      <transformer name="db" class="com.mycompany.LoadFromDatabaseTransformer" >
        <int name="connection">jdbc://....</int>
      </transformer>
-     
+
      To add a constant value to all docs, use:
      <transformer name="mytrans2" class="org.apache.solr.response.transform.ValueAugmenterFactory" >
        <int name="value">5</int>
      </transformer>
-     
+
      If you want the user to still be able to change it with _value:something_ use this:
      <transformer name="mytrans3" class="org.apache.solr.response.transform.ValueAugmenterFactory" >
        <double name="defaultValue">5</double>