From 48109b3dc6068f0d3b521d8115b9c20a2a06552e Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Thu, 20 Aug 2009 18:23:36 +0000 Subject: [PATCH] SOLR-1371: LukeRequestHandler/schema.jsp errored if schema had no uniqueKey field. The new test for this also (hopefully) adds some future proofing against similar bugs in the future. As a side effect QueryElevationComponentTest was refactored, and a bug in that test was found. git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@806289 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 6 + .../handler/admin/LukeRequestHandler.java | 3 +- .../org/apache/solr/MinimalSchemaTest.java | 129 ++++++++++ .../QueryElevationComponentTest.java | 5 +- .../test-files/solr/conf/schema-minimal.xml | 25 ++ .../solr/conf/solrconfig-elevate.xml | 223 ++++++++++++++++++ src/test/test-files/solr/conf/solrconfig.xml | 32 +-- 7 files changed, 404 insertions(+), 19 deletions(-) create mode 100644 src/test/org/apache/solr/MinimalSchemaTest.java create mode 100644 src/test/test-files/solr/conf/schema-minimal.xml create mode 100644 src/test/test-files/solr/conf/solrconfig-elevate.xml diff --git a/CHANGES.txt b/CHANGES.txt index 7cd0fdc0849..70091415756 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -482,6 +482,12 @@ Bug Fixes 57. SOLR-1360: Prevent PhoneticFilter from producing duplicate tokens. (yonik) +58. SOLR-1371: LukeRequestHandler/schema.jsp errored if schema had no + uniqueKey field. The new test for this also (hopefully) adds some + future proofing against similar bugs in the future. As a side + effect QueryElevationComponentTest was refactored, and a bug in + that test was found. (hossman) + Other Changes ---------------------- 1. Upgraded to Lucene 2.4.0 (yonik) diff --git a/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java index 4102fccd243..7248785e2d4 100644 --- a/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java +++ b/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java @@ -370,7 +370,8 @@ public class LukeRequestHandler extends RequestHandlerBase SimpleOrderedMap finfo = new SimpleOrderedMap(); finfo.add("fields", fields); finfo.add("dynamicFields", dynamicFields); - finfo.add("uniqueKeyField", uniqueField.getName()); + finfo.add("uniqueKeyField", + null == uniqueField ? null : uniqueField.getName()); finfo.add("defaultSearchField", schema.getDefaultSearchFieldName()); finfo.add("types", types); return finfo; diff --git a/src/test/org/apache/solr/MinimalSchemaTest.java b/src/test/org/apache/solr/MinimalSchemaTest.java new file mode 100644 index 00000000000..bcb7726b921 --- /dev/null +++ b/src/test/org/apache/solr/MinimalSchemaTest.java @@ -0,0 +1,129 @@ +/** + * 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; + +import org.apache.solr.request.*; +import org.apache.solr.util.*; + +import java.util.Set; + +/** + * A test of basic features using the minial legal solr schema. + */ +public class MinimalSchemaTest extends AbstractSolrTestCase { + + public String getSchemaFile() { return "solr/conf/schema-minimal.xml"; } + + + /** + * NOTE: we explicilty use the general 'solrconfig.xml' file here, in + * an attempt to test as many braod features as possible. + * + * Do not change this to point at some other "simpler" solrconfig.xml + * just because you want to add a new test case using solrconfig.xml, + * but your new testcase adds a feature that breaks this test. + */ + public String getSolrConfigFile() { return "solr/conf/solrconfig.xml"; } + + public void setUp() throws Exception { + super.setUp(); + + /* make sure some missguided soul doesn't inadvertantly give us + a uniqueKey field and defeat the point of hte tests + */ + assertNull("UniqueKey Field isn't null", + h.getCore().getSchema().getUniqueKeyField()); + + lrf.args.put("version","2.0"); + + assertU("Simple assertion that adding a document works", + adoc("id", "4055", + "subject", "Hoss", + "project", "Solr")); + assertU(adoc("id", "4056", + "subject", "Yonik", + "project", "Solr")); + assertU(commit()); + assertU(optimize()); + + } + + public void testSimpleQueries() { + + assertQ("couldn't find subject hoss", + req("subject:Hoss") + ,"//result[@numFound=1]" + ,"//str[@name='id'][.='4055']" + ); + + assertQ("couldn't find subject Yonik", + req("subject:Yonik") + ,"//result[@numFound=1]" + ,"//str[@name='id'][.='4056']" + ); + } + + /** SOLR-1371 */ + public void testLuke() { + + assertQ("basic luke request failed", + req("qt", "/admin/luke") + ,"//int[@name='numDocs'][.='2']" + ,"//int[@name='numTerms'][.='5']" + ); + + assertQ("luke show schema failed", + req("qt", "/admin/luke", + "show","schema") + ,"//int[@name='numDocs'][.='2']" + ,"//int[@name='numTerms'][.='5']" + ,"//null[@name='uniqueKeyField']" + ,"//null[@name='defaultSearchField']" + ); + + } + + + /** + * Iterates over all (non "/update/*") handlers in the core and hits + * them with a request (using some simple params) to verify that they + * don't generate an error against the minimal schema + */ + public void testAllConfiguredHandlers() { + Set handlerNames = h.getCore().getRequestHandlers().keySet(); + for (String handler : handlerNames) { + try { + if (handler.startsWith("/update")) { + continue; + } + + assertQ("failure w/handler: '" + handler + "'", + req("qt", handler, + // this should be fairly innoculous for any type of query + "q", "foo:bar") + ,"//lst[@name='responseHeader']" + ); + } catch (Exception e) { + throw new RuntimeException("exception w/handler: '" + handler + "'", + e); + } + } + } +} + + diff --git a/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java index d0d21ad67d3..d650b17406b 100644 --- a/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java +++ b/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java @@ -40,7 +40,7 @@ import org.apache.solr.util.AbstractSolrTestCase; public class QueryElevationComponentTest extends AbstractSolrTestCase { @Override public String getSchemaFile() { return "schema12.xml"; } - @Override public String getSolrConfigFile() { return "solrconfig.xml"; } + @Override public String getSolrConfigFile() { return "solrconfig-elevate.xml"; } public void testInterface() throws Exception { @@ -89,13 +89,12 @@ public class QueryElevationComponentTest extends AbstractSolrTestCase { public void testEmptyQuery() throws Exception { SolrCore core = h.getCore(); - - //String query = "title:ipod"; Map args = new HashMap(); args.put( "q.alt", "*:*" ); args.put( "defType", "dismax"); + args.put( CommonParams.QT, "/elevate" ); //args.put( CommonParams.FL, "id,title,score" ); SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) ); assertQ("Make sure QEC handles null queries", req, "//*[@numFound='0']"); diff --git a/src/test/test-files/solr/conf/schema-minimal.xml b/src/test/test-files/solr/conf/schema-minimal.xml new file mode 100644 index 00000000000..9e2f9471026 --- /dev/null +++ b/src/test/test-files/solr/conf/schema-minimal.xml @@ -0,0 +1,25 @@ + + + + + + + + + + diff --git a/src/test/test-files/solr/conf/solrconfig-elevate.xml b/src/test/test-files/solr/conf/solrconfig-elevate.xml new file mode 100644 index 00000000000..1b2e39f9317 --- /dev/null +++ b/src/test/test-files/solr/conf/solrconfig-elevate.xml @@ -0,0 +1,223 @@ + + + + + + + + + + + + ${solr.data.dir:./solr/data} + + + + + false + 10 + + + + 32 + 2147483647 + 10000 + 1000 + 10000 + + + false + + + org.apache.lucene.index.LogByteSizeMergePolicy + + + org.apache.lucene.index.ConcurrentMergeScheduler + + 1000 + 10000 + + single + + + + + false + 10 + + 10 + 2147483647 + 10000 + org.apache.lucene.index.LogDocMergePolicy + + true + + + + + + + + + + + + + + + + + 1024 + + + + + + + + + + + true + + 10 + + + + + + + + + + + + + + + + + string + elevate.xml + + + + + explicit + + + elevate + + + + + + + + max-age=30, public + + + + + solr + solrconfig.xml scheam.xml admin-extra.html + + + + prefix-${solr.test.sys.prop2}-suffix + + + + diff --git a/src/test/test-files/solr/conf/solrconfig.xml b/src/test/test-files/solr/conf/solrconfig.xml index 7dac684faf8..72373752bf4 100644 --- a/src/test/test-files/solr/conf/solrconfig.xml +++ b/src/test/test-files/solr/conf/solrconfig.xml @@ -20,6 +20,20 @@ @@ -244,6 +258,7 @@ it's init params as "defaults" if there is no "defaults" list specified --> + *:* 0.01 text^0.5 features_t^1.0 subject^1.4 title_stemmed^2.0 @@ -289,6 +304,8 @@ log 10 + + @@ -314,21 +331,6 @@ false - - - string - elevate.xml - - - - - explicit - - - elevate - - - lowerfilt