You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ry...@apache.org on 2007/04/30 00:10:21 UTC
svn commit: r533566 - in /lucene/solr/trunk: ./
src/java/org/apache/solr/request/ src/java/org/apache/solr/util/
src/site/src/documentation/content/xdocs/ src/test/org/apache/solr/
src/test/org/apache/solr/handler/ src/test/test-files/solr/conf/
Author: ryan
Date: Sun Apr 29 15:10:20 2007
New Revision: 533566
URL: http://svn.apache.org/viewvc?view=rev&rev=533566
Log:
SOLR-170 -- adding a 'sort' parameter that works for both dismax and standard request handlers. The ';' is still suported (if the 'sort' parameter is not in the query). This also adds a new test class for StandardRequestHandler.
Added:
lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java (with props)
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java
lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
lucene/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java
lucene/solr/trunk/src/site/src/documentation/content/xdocs/tutorial.xml
lucene/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
lucene/solr/trunk/src/test/test-files/solr/conf/schema.xml
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Sun Apr 29 15:10:20 2007
@@ -157,6 +157,10 @@
/select. To enable this behavior, you must add:
<requestDispatcher handleSelect="true" > to your solrconfig.xml
See the example solrconfig.xml for details. (ryan)
+
+26. SOLR-170: StandardRequestHandler now supports a "sort" parameter.
+ Using the ';' syntax is still supported, but it is recommended to
+ transition to the new syntax. (ryan)
Changes in runtime behavior
1. Highlighting using DisMax will only pick up terms from the main
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/SolrParams.java Sun Apr 29 15:10:20 2007
@@ -37,6 +37,8 @@
public static final String WT ="wt";
/** query string */
public static final String Q ="q";
+ /** sort order */
+ public static final String SORT ="sort";
/** Lucene query string(s) for filtering the results without affecting scoring */
public static final String FQ ="fq";
/** zero based offset of matching documents to retrieve */
@@ -360,6 +362,8 @@
return result;
}
}
+
+
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/StandardRequestHandler.java Sun Apr 29 15:10:20 2007
@@ -67,7 +67,7 @@
{
SolrParams p = req.getParams();
- String sreq = p.get(Q);
+ String qstr = p.required().get(Q);
String defaultField = p.get(DF);
@@ -77,25 +77,37 @@
if (fl != null) {
flags |= U.setReturnFields(fl, rsp);
}
+
+ String sortStr = p.get(SORT);
+ if( sortStr == null ) {
+ // TODO? should we disable the ';' syntax with config?
+ // legacy mode, where sreq is query;sort
+ List<String> commands = StrUtils.splitSmart(qstr,';');
+ if( commands.size() == 2 ) {
+ // TODO? add a deprication warning to the response header
+ qstr = commands.get( 0 );
+ sortStr = commands.get( 1 );
+ }
+ else if( commands.size() == 1 ) {
+ // This is need to support the case where someone sends: "q=query;"
+ qstr = commands.get( 0 );
+ }
+ else if( commands.size() > 2 ) {
+ throw new SolrException( 400, "If you want to use multiple ';' in the query, use the 'sort' param." );
+ }
+ }
- if (sreq==null) throw new SolrException(400,"Missing queryString");
- List<String> commands = StrUtils.splitSmart(sreq,';');
-
- String qs = commands.size() >= 1 ? commands.get(0) : "";
- Query query = QueryParsing.parseQuery(qs, defaultField, p, req.getSchema());
-
- // If the first non-query, non-filter command is a simple sort on an indexed field, then
- // we can use the Lucene sort ability.
Sort sort = null;
- if (commands.size() >= 2) {
- QueryParsing.SortSpec sortSpec = QueryParsing.parseSort(commands.get(1), req.getSchema());
+ if( sortStr != null ) {
+ QueryParsing.SortSpec sortSpec = QueryParsing.parseSort(sortStr, req.getSchema());
if (sortSpec != null) {
sort = sortSpec.getSort();
- // ignore the count for now... it's currently only controlled by start & limit on req
- // count = sortSpec.getCount();
}
}
+ // parse the query from the 'q' parameter (sort has been striped)
+ Query query = QueryParsing.parseQuery(qstr, defaultField, p, req.getSchema());
+
DocListAndSet results = new DocListAndSet();
NamedList facetInfo = null;
List<Query> filters = U.parseFilterQueries(req);
@@ -120,7 +132,7 @@
if (null != facetInfo) rsp.add("facet_counts", facetInfo);
try {
- NamedList dbg = U.doStandardDebug(req, qs, query, results.docList);
+ NamedList dbg = U.doStandardDebug(req, qstr, query, results.docList);
if (null != dbg) {
if (null != filters) {
dbg.add("filter_queries",req.getParams().getParams(FQ));
@@ -187,4 +199,6 @@
catch( MalformedURLException ex ) { return null; }
}
}
+
+
Modified: lucene/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/SolrPluginUtils.java Sun Apr 29 15:10:20 2007
@@ -785,7 +785,7 @@
*/
public static Sort getSort(SolrQueryRequest req) {
- String sort = req.getParam("sort");
+ String sort = req.getParam(SolrParams.SORT);
if (null == sort || sort.equals("")) {
return null;
}
@@ -863,6 +863,8 @@
}
}
+
+
Modified: lucene/solr/trunk/src/site/src/documentation/content/xdocs/tutorial.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/site/src/documentation/content/xdocs/tutorial.xml?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/src/site/src/documentation/content/xdocs/tutorial.xml (original)
+++ lucene/solr/trunk/src/site/src/documentation/content/xdocs/tutorial.xml Sun Apr 29 15:10:20 2007
@@ -261,7 +261,7 @@
<li><a href="http://localhost:8983/solr/select/?indent=on&q=video&fl=name,id">q=video&fl=name,id</a> (return only name and id fields) </li>
<li><a href="http://localhost:8983/solr/select/?indent=on&q=video&fl=name,id,score">q=video&fl=name,id,score</a> (return relevancy score as well) </li>
<li><a href="http://localhost:8983/solr/select/?indent=on&q=video&fl=*,score">q=video&fl=*,score</a> (return all stored fields, as well as relevancy score) </li>
- <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;price desc&fl=name,id">q=video;price desc&fl=name,id</a> (add sort specification: sort by price descending) </li>
+ <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;price desc&fl=name,id">q=video&sort=price desc&fl=name,id</a> (add sort specification: sort by price descending) </li>
</ul>
<p>
@@ -273,21 +273,21 @@
<title>Sorting</title>
<p>
- Solr provides a simple extension to the Lucene QueryParser syntax for specifying sort options. After your search, add a semi-colon followed by a list of "field direction" pairs...
+ Solr provides a simple extension to the Lucene QueryParser syntax for specifying sort options. Use the 'sort' parameter to specify "field direction" pairs...
</p>
<ul>
- <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;price+desc">video; price desc</a></li>
- <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;price+asc">video; price asc</a></li>
- <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;inStock+asc+price+desc">video; inStock asc, price desc</a></li>
+ <li><a href="http://localhost:8983/solr/select/?indent=on&q=video&sort=price+desc">video; price desc</a></li>
+ <li><a href="http://localhost:8983/solr/select/?indent=on&q=video&sort=price+asc">video; price asc</a></li>
+ <li><a href="http://localhost:8983/solr/select/?indent=on&q=video&sort=inStock+asc+price+desc">video; inStock asc, price desc</a></li>
</ul>
<p>
"score" can also be used as a field name when specifying a sort...
</p>
<ul>
- <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;score+desc">video; score desc</a></li>
- <li><a href="http://localhost:8983/solr/select/?indent=on&q=video;inStock+asc,score+desc">video; inStock asc, score desc</a></li>
+ <li><a href="http://localhost:8983/solr/select/?indent=on&q=video&sort=score+desc">video; score desc</a></li>
+ <li><a href="http://localhost:8983/solr/select/?indent=on&q=video&sort=inStock+asc,score+desc">video; inStock asc, score desc</a></li>
</ul>
<p>
Modified: lucene/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/BasicFunctionalityTest.java Sun Apr 29 15:10:20 2007
@@ -583,7 +583,6 @@
,"facet.mincount","0"
,"facet.offset","0"
,"facet.limit","3"
- ,"sort","true"
)
,"*[count(//lst[@name='trait_s']/int)=3]"
,"//lst[@name='trait_s']/int[@name='Tool'][.='2']"
Added: lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java?view=auto&rev=533566
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java (added)
+++ lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java Sun Apr 29 15:10:20 2007
@@ -0,0 +1,93 @@
+/**
+ * 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.handler;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.MapSolrParams;
+import org.apache.solr.request.SolrParams;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.util.AbstractSolrTestCase;
+
+/**
+ * Most of the tests for StandardRequestHandler are in ConvertedLegacyTest
+ *
+ */
+public class StandardRequestHandlerTest extends AbstractSolrTestCase {
+
+ @Override public String getSchemaFile() { return "schema.xml"; }
+ @Override public String getSolrConfigFile() { return "solrconfig.xml"; }
+ @Override public void setUp() throws Exception {
+ super.setUp();
+ lrf = h.getRequestFactory("standard", 0, 20 );
+ }
+
+ public void testSorting() throws Exception {
+ assertU(adoc("id", "10", "title", "test", "val_s", "aaa"));
+ assertU(adoc("id", "11", "title", "test", "val_s", "bbb"));
+ assertU(adoc("id", "12", "title", "test", "val_s", "ccc"));
+ assertU(commit());
+
+ Map<String,String> args = new HashMap<String, String>();
+ args.put( SolrParams.Q, "title:test" );
+ args.put( "indent", "true" );
+ SolrQueryRequest req = new LocalSolrQueryRequest( SolrCore.getSolrCore(), new MapSolrParams( args) );
+
+
+ assertQ("Make sure they got in", req
+ ,"//*[@numFound='3']"
+ );
+
+ args.put( SolrParams.SORT, "val_s asc" );
+ assertQ("with sort param [asc]", req
+ ,"//*[@numFound='3']"
+ ,"//result/doc[1]/int[@name='id'][.='10']"
+ ,"//result/doc[2]/int[@name='id'][.='11']"
+ ,"//result/doc[3]/int[@name='id'][.='12']"
+ );
+
+ args.put( SolrParams.SORT, "val_s desc" );
+ assertQ("with sort param [desc]", req
+ ,"//*[@numFound='3']"
+ ,"//result/doc[1]/int[@name='id'][.='12']"
+ ,"//result/doc[2]/int[@name='id'][.='11']"
+ ,"//result/doc[3]/int[@name='id'][.='10']"
+ );
+
+ // Using legacy ';' param
+ args.remove( SolrParams.SORT );
+ args.put( SolrParams.Q, "title:test; val_s desc" );
+ assertQ("with sort param [desc]", req
+ ,"//*[@numFound='3']"
+ ,"//result/doc[1]/int[@name='id'][.='12']"
+ ,"//result/doc[2]/int[@name='id'][.='11']"
+ ,"//result/doc[3]/int[@name='id'][.='10']"
+ );
+
+ args.put( SolrParams.Q, "title:test; val_s asc" );
+ assertQ("with sort param [desc]", req
+ ,"//*[@numFound='3']"
+ ,"//result/doc[1]/int[@name='id'][.='10']"
+ ,"//result/doc[2]/int[@name='id'][.='11']"
+ ,"//result/doc[3]/int[@name='id'][.='12']"
+ );
+ }
+}
Propchange: lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: lucene/solr/trunk/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: lucene/solr/trunk/src/test/test-files/solr/conf/schema.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/test-files/solr/conf/schema.xml?view=diff&rev=533566&r1=533565&r2=533566
==============================================================================
--- lucene/solr/trunk/src/test/test-files/solr/conf/schema.xml (original)
+++ lucene/solr/trunk/src/test/test-files/solr/conf/schema.xml Sun Apr 29 15:10:20 2007
@@ -298,7 +298,7 @@
<fields>
- <field name="id" type="integer" indexed="true" stored="true"/>
+ <field name="id" type="integer" indexed="true" stored="true" multiValued="false"/>
<field name="name" type="nametext" indexed="true" stored="true"/>
<field name="text" type="text" indexed="true" stored="false"/>
<field name="subject" type="text" indexed="true" stored="true"/>