lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r633664 - in /lucene/solr/trunk/src: java/org/apache/solr/search/NestedQParserPlugin.java java/org/apache/solr/search/QParserPlugin.java test/org/apache/solr/search/TestQueryTypes.java
Date Tue, 04 Mar 2008 21:59:51 GMT
Author: yonik
Date: Tue Mar  4 13:59:50 2008
New Revision: 633664

URL: http://svn.apache.org/viewvc?rev=633664&view=rev
Log:
SOLR-334: nested query type added

Added:
    lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java   (with props)
Modified:
    lucene/solr/trunk/src/java/org/apache/solr/search/QParserPlugin.java
    lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java

Added: lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java?rev=633664&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java Tue Mar  4
13:59:50 2008
@@ -0,0 +1,70 @@
+/**
+ * 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.solr.search;
+
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.search.Query;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.search.function.BoostedQuery;
+import org.apache.solr.search.function.FunctionQuery;
+import org.apache.solr.search.function.QueryValueSource;
+import org.apache.solr.search.function.ValueSource;
+
+/**
+ * Create a nested query, with the ability of that query to redefine it's type via
+ * local parameters.  This is useful in specifying defaults in configuration and
+ * letting clients indirectly reference them.
+ * <br>Example: <code>&lt;!query defType=func v=$q1&gt;</code>
+ * <br> if the q1 parameter is <code>price</code> then the query would
be a function query on the price field.
+ * <br> if the q1 parameter is <code>&lt;!lucene&gt;inStock:true</code>
then a term query is
+ *     created from the lucene syntax string that matches documents with inStock=true.
+ */
+public class NestedQParserPlugin extends QParserPlugin {
+  public static String NAME = "query";
+
+  public void init(NamedList args) {
+  }
+
+  public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest
req) {
+    return new QParser(qstr, localParams, params, req) {
+      QParser baseParser;
+      ValueSource vs;
+      String b;
+
+      public Query parse() throws ParseException {
+        baseParser = subQuery(localParams.get(QueryParsing.V), null);
+        return baseParser.getQuery();
+      }
+
+      public String[] getDefaultHighlightFields() {
+        return baseParser.getDefaultHighlightFields();
+      }
+
+      public Query getHighlightQuery() throws ParseException {
+        return baseParser.getHighlightQuery();
+      }
+
+      public void addDebugInfo(NamedList<Object> debugInfo) {
+        // encapsulate base debug info in a sub-list?
+        baseParser.addDebugInfo(debugInfo);
+      }
+    };
+  }
+
+}
\ No newline at end of file

Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/NestedQParserPlugin.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/QParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/QParserPlugin.java?rev=633664&r1=633663&r2=633664&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/QParserPlugin.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/QParserPlugin.java Tue Mar  4 13:59:50
2008
@@ -34,6 +34,7 @@
     DisMaxQParserPlugin.NAME, DisMaxQParserPlugin.class,
     FieldQParserPlugin.NAME, FieldQParserPlugin.class,
     RawQParserPlugin.NAME, RawQParserPlugin.class,
+    NestedQParserPlugin.NAME, NestedQParserPlugin.class,
   };
 
   /** return a {@link QParser} */

Modified: lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java?rev=633664&r1=633663&r2=633664&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/search/TestQueryTypes.java Tue Mar  4 13:59:50
2008
@@ -182,5 +182,15 @@
              ,"//result[@numFound='2']"
              );
 
+    assertQ("test nested query",
+            req("q","_query_:\"<!query v=$q1>\"", "q1","<!prefix f=v_t>hel")
+            ,"//result[@numFound='2']"
+            );
+
+    assertQ("test nested nested query",
+            req("q","_query_:\"<!query defType=query v=$q1>\"", "q1","<!v=$q2>","q2","<!prefix
f=v_t v=$qqq>","qqq","hel")
+            ,"//result[@numFound='2']"
+            );
+
   }
 }



Mime
View raw message