lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r889825 - /lucene/solr/trunk/src/test/org/apache/solr/search/QueryParsingTest.java
Date Fri, 11 Dec 2009 21:36:41 GMT
Author: gsingers
Date: Fri Dec 11 21:36:41 2009
New Revision: 889825

URL: http://svn.apache.org/viewvc?rev=889825&view=rev
Log:
SOLR-1297: establish some standalone, baseline tests for parsing the sort strings

Added:
    lucene/solr/trunk/src/test/org/apache/solr/search/QueryParsingTest.java   (with props)

Added: lucene/solr/trunk/src/test/org/apache/solr/search/QueryParsingTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/search/QueryParsingTest.java?rev=889825&view=auto
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/search/QueryParsingTest.java (added)
+++ lucene/solr/trunk/src/test/org/apache/solr/search/QueryParsingTest.java Fri Dec 11 21:36:41
2009
@@ -0,0 +1,104 @@
+package org.apache.solr.search;
+/**
+ * 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.
+ */
+
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.util.AbstractSolrTestCase;
+
+
+/**
+ *
+ *
+ **/
+public class QueryParsingTest extends AbstractSolrTestCase {
+  public String getSchemaFile() {
+    return "schema.xml";
+  }
+
+  public String getSolrConfigFile() {
+    return "solrconfig.xml";
+  }
+
+
+  public void testSort() throws Exception {
+    Sort sort;
+
+    IndexSchema schema = h.getCore().getSchema();
+    sort = QueryParsing.parseSort("score desc", schema);
+    assertNull("sort", sort);//only 1 thing in the list, no Sort specified
+    sort = QueryParsing.parseSort("weight desc", schema);
+    SortField[] flds = sort.getSort();
+    assertEquals(flds[0].getType(), SortField.FLOAT);
+    assertEquals(flds[0].getField(), "weight");
+    assertEquals(flds[0].getReverse(), true);
+    sort = QueryParsing.parseSort("weight desc,bday asc", schema);
+    flds = sort.getSort();
+    assertEquals(flds[0].getType(), SortField.FLOAT);
+    assertEquals(flds[0].getField(), "weight");
+    assertEquals(flds[0].getReverse(), true);
+    assertEquals(flds[1].getType(), SortField.LONG);
+    assertEquals(flds[1].getField(), "bday");
+    assertEquals(flds[1].getReverse(), false);
+    //order aliases
+    sort = QueryParsing.parseSort("weight top,bday asc", schema);
+    flds = sort.getSort();
+    assertEquals(flds[0].getType(), SortField.FLOAT);
+    assertEquals(flds[0].getField(), "weight");
+    assertEquals(flds[0].getReverse(), true);
+    assertEquals(flds[1].getType(), SortField.LONG);
+    assertEquals(flds[1].getField(), "bday");
+    assertEquals(flds[1].getReverse(), false);
+    sort = QueryParsing.parseSort("weight top,bday bottom", schema);
+    flds = sort.getSort();
+    assertEquals(flds[0].getType(), SortField.FLOAT);
+    assertEquals(flds[0].getField(), "weight");
+    assertEquals(flds[0].getReverse(), true);
+    assertEquals(flds[1].getType(), SortField.LONG);
+    assertEquals(flds[1].getField(), "bday");
+    assertEquals(flds[1].getReverse(), false);
+
+    //test weird spacing
+    sort = QueryParsing.parseSort("weight         desc,            bday         asc", schema);
+    flds = sort.getSort();
+    assertEquals(flds[0].getType(), SortField.FLOAT);
+    assertEquals(flds[0].getField(), "weight");
+    assertEquals(flds[1].getType(), SortField.LONG);
+    assertEquals(flds[1].getField(), "bday");
+    //handles trailing commas
+    sort = QueryParsing.parseSort("weight desc,", schema);
+    flds = sort.getSort();
+    assertEquals(flds[0].getType(), SortField.FLOAT);
+    assertEquals(flds[0].getField(), "weight");
+    //test some bad vals
+    try {
+      sort = QueryParsing.parseSort("weight, desc", schema);
+      assertTrue(false);
+    } catch (SolrException e) {
+      //expected
+    }
+    try {
+      sort = QueryParsing.parseSort("weight desc, bday", schema);
+      assertTrue(false);
+    } catch (SolrException e) {
+    }
+
+  }
+
+}

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



Mime
View raw message