You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2010/10/20 14:44:39 UTC
svn commit: r1025539 [9/10] - in /lucene/dev/branches/docvalues: ./ lucene/
lucene/contrib/
lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/
lucene/contrib/highlighter/src/test/
lucene/contrib/instantiated/src/test/org/apache...
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/IndexReaderFactoryTest.java Wed Oct 20 12:44:28 2010
@@ -40,7 +40,7 @@ public class IndexReaderFactoryTest exte
public void testAltReaderUsed() throws Exception {
IndexReaderFactory readerFactory = h.getCore().getIndexReaderFactory();
assertNotNull("Factory is null", readerFactory);
- assertTrue("readerFactory is not an instanceof " + AlternateIndexReaderTest.TestIndexReaderFactory.class, readerFactory instanceof StandardIndexReaderFactory);
+ assertTrue("readerFactory is not an instanceof " + AlternateDirectoryTest.TestIndexReaderFactory.class, readerFactory instanceof StandardIndexReaderFactory);
assertTrue("termInfoIndexDivisor not set to 12", readerFactory.getTermInfosIndexDivisor() == 12);
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RequestHandlersTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RequestHandlersTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RequestHandlersTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/RequestHandlersTest.java Wed Oct 20 12:44:28 2010
@@ -17,22 +17,24 @@
package org.apache.solr.core;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.StandardRequestHandler;
import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
-public class RequestHandlersTest extends AbstractSolrTestCase {
-
- public String getSchemaFile() { return "schema.xml"; }
- public String getSolrConfigFile() { return "solrconfig.xml"; }
+public class RequestHandlersTest extends SolrTestCaseJ4 {
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig.xml", "schema.xml");
+ }
-
+ @Test
public void testLazyLoading() {
SolrCore core = h.getCore();
SolrRequestHandler handler = core.getRequestHandler( "lazy" );
assertFalse( handler instanceof StandardRequestHandler );
- // But it should behave just like the 'defaults' request handler above
assertU(adoc("id", "42",
"name", "Zapp Brannigan"));
assertU(adoc("id", "43",
@@ -48,21 +50,22 @@ public class RequestHandlersTest extends
assertU(commit());
assertQ("lazy request handler returns all matches",
- req("id:[42 TO 47]"),
- "*[count(//doc)=6]"
- );
+ req("q","id:[42 TO 47]"),
+ "*[count(//doc)=6]");
+ // But it should behave just like the 'defaults' request handler above
assertQ("lazy handler returns fewer matches",
- req("q", "id:[42 TO 47]", "qt","defaults"),
+ req("q", "id:[42 TO 47]", "qt","lazy"),
"*[count(//doc)=4]"
);
assertQ("lazy handler includes highlighting",
- req("q", "name:Zapp OR title:General", "qt","defaults"),
+ req("q", "name:Zapp OR title:General", "qt","lazy"),
"//lst[@name='highlighting']"
);
}
-
+
+ @Test
public void testPathNormalization()
{
SolrCore core = h.getCore();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SOLR749Test.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SOLR749Test.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SOLR749Test.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SOLR749Test.java Wed Oct 20 12:44:28 2010
@@ -16,23 +16,22 @@ package org.apache.solr.core;
* limitations under the License.
*/
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.search.QParserPlugin;
import org.apache.solr.search.FooQParserPlugin;
import org.apache.solr.search.ValueSourceParser;
+import org.junit.BeforeClass;
/**
* Test for https://issues.apache.org/jira/browse/SOLR-749
*
**/
-public class SOLR749Test extends AbstractSolrTestCase{
- public String getSchemaFile() {
- return "schema.xml";
- }
-
- public String getSolrConfigFile() {
- return "solrconfig-SOLR-749.xml";
+public class SOLR749Test extends SolrTestCaseJ4 {
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-SOLR-749.xml","schema.xml");
}
public void testConstruction() throws Exception {
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SolrCoreTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SolrCoreTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SolrCoreTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/SolrCoreTest.java Wed Oct 20 12:44:28 2010
@@ -17,22 +17,33 @@
package org.apache.solr.core;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.handler.component.SpellCheckComponent;
import org.apache.solr.handler.component.QueryComponent;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.plugin.SolrCoreAware;
+import org.junit.BeforeClass;
+import org.junit.Test;
import java.util.concurrent.*;
import java.util.*;
-public class SolrCoreTest extends AbstractSolrTestCase {
+public class SolrCoreTest extends SolrTestCaseJ4 {
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ initCore("solrconfig.xml", "schema.xml");
+ }
- public String getSchemaFile() { return "schema.xml"; }
- public String getSolrConfigFile() { return "solrconfig.xml"; }
-
+ @Override
+ public void tearDown() throws Exception {
+ deleteCore();
+ super.tearDown();
+ }
+
+ @Test
public void testRequestHandlerRegistry() {
SolrCore core = h.getCore();
@@ -48,6 +59,7 @@ public class SolrCoreTest extends Abstra
assertEquals( core.getRequestHandlers().get( path ), handler2 );
}
+ @Test
public void testClose() throws Exception {
final CoreContainer cores = h.getCoreContainer();
SolrCore core = cores.getCore("");
@@ -55,7 +67,7 @@ public class SolrCoreTest extends Abstra
ClosingRequestHandler handler1 = new ClosingRequestHandler();
handler1.inform( core );
- String path = "/this/is A path /that won't be registered!";
+ String path = "/this/is A path /that won't be registered 2!!!!!!!!!!!";
SolrRequestHandler old = core.registerRequestHandler( path, handler1 );
assertNull( old ); // should not be anything...
assertEquals( core.getRequestHandlers().get( path ), handler1 );
@@ -64,6 +76,7 @@ public class SolrCoreTest extends Abstra
assertTrue("Handler not closed", handler1.closed == true);
}
+ @Test
public void testRefCount() throws Exception {
SolrCore core = h.getCore();
assertTrue("Refcount != 1", core.getOpenCount() == 1);
@@ -100,6 +113,7 @@ public class SolrCoreTest extends Abstra
}
+ @Test
public void testRefCountMT() throws Exception {
SolrCore core = h.getCore();
assertTrue("Refcount != 1", core.getOpenCount() == 1);
@@ -167,6 +181,7 @@ public class SolrCoreTest extends Abstra
assertTrue("Running for too long...", service.awaitTermination(60, TimeUnit.SECONDS));
}
+ @Test
public void testInfoRegistry() throws Exception {
//TEst that SolrInfoMBeans are registered, including SearchComponents
SolrCore core = h.getCore();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestArbitraryIndexDir.java Wed Oct 20 12:44:28 2010
@@ -48,15 +48,16 @@ public class TestArbitraryIndexDir exten
public void setUp() throws Exception {
super.setUp();
+
dataDir = new File(TEMP_DIR,
getClass().getName() + "-" + System.currentTimeMillis() + System.getProperty("file.separator") + "solr"
+ System.getProperty("file.separator") + "data");
dataDir.mkdirs();
- solrConfig = h.createConfig(getSolrConfigFile());
+ solrConfig = h.createConfig("solrconfig.xml");
h = new TestHarness( dataDir.getAbsolutePath(),
solrConfig,
- getSchemaFile());
+ "schema12.xml");
lrf = h.getRequestFactory
("standard",0,20,"version","2.2");
}
@@ -68,12 +69,12 @@ public class TestArbitraryIndexDir exten
@Override
public String getSchemaFile() {
- return "schema12.xml";
+ return null;
}
@Override
public String getSolrConfigFile() {
- return "solrconfig.xml";
+ return null; // prevent superclass from creating it's own TestHarness
}
@Test
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestConfig.java Wed Oct 20 12:44:28 2010
@@ -20,6 +20,7 @@ package org.apache.solr.core;
import org.apache.lucene.index.IndexWriter;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.admin.ShowFileRequestHandler;
+import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.SolrIndexReader;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.update.DirectUpdateHandler2;
@@ -140,9 +141,9 @@ public class TestConfig extends SolrTest
IndexReaderFactory irf = h.getCore().getIndexReaderFactory();
StandardIndexReaderFactory sirf = (StandardIndexReaderFactory) irf;
assertEquals(12, sirf.termInfosIndexDivisor);
- RefCounted<SolrIndexSearcher> refCounted = h.getCore().getSearcher();
- SolrIndexReader solrReader = refCounted.get().getReader();
- assertEquals(12, solrReader.getTermInfosIndexDivisor());
+ SolrQueryRequest req = req();
+ assertEquals(12, req.getSearcher().getReader().getTermInfosIndexDivisor());
+ req.close();
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestJmxIntegration.java Wed Oct 20 12:44:28 2010
@@ -95,7 +95,6 @@ public class TestJmxIntegration extends
}
if (bean==null) throw new RuntimeException("searcher was never registered");
ObjectName searcher = getObjectName("searcher", bean);
-
MBeanServer mbeanServer = servers.get(0);
log.info("Mbeans in server: " + mbeanServer.queryNames(null, null));
@@ -114,7 +113,14 @@ public class TestJmxIntegration extends
Hashtable<String, String> map = new Hashtable<String, String>();
map.put("type", key);
map.put("id", infoBean.getName());
- return ObjectName.getInstance("solr", map);
+ String coreName = h.getCore().getName();
+ if (coreName.equals("")) {
+ String defaultCoreName = h.getCore().getCoreDescriptor().getCoreContainer().getDefaultCoreName();
+ if (!defaultCoreName.equals("")) {
+ coreName = defaultCoreName;
+ }
+ }
+ return ObjectName.getInstance(("solr" + (null != coreName ? "/" + coreName : "")), map);
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestLegacyMergeSchedulerPolicyConfig.java Wed Oct 20 12:44:28 2010
@@ -5,18 +5,18 @@ import java.io.IOException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.LogDocMergePolicy;
import org.apache.lucene.index.SerialMergeScheduler;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.update.DirectUpdateHandler2;
-import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
-public class TestLegacyMergeSchedulerPolicyConfig extends AbstractSolrTestCase {
- public String getSchemaFile() {
- return "schema.xml";
+public class TestLegacyMergeSchedulerPolicyConfig extends SolrTestCaseJ4 {
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-legacy.xml", "schema.xml");
}
- public String getSolrConfigFile() {
- return "solrconfig-legacy.xml";
- }
-
+ @Test
public void testLegacy() throws Exception {
IndexWriter writer = new ExposeWriterHandler().getWriter();
assertTrue(writer.getMergePolicy().getClass().getName().equals(LogDocMergePolicy.class.getName()));
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInjectDefaults.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInjectDefaults.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInjectDefaults.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestPropInjectDefaults.java Wed Oct 20 12:44:28 2010
@@ -22,19 +22,15 @@ import java.io.IOException;
import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.LogByteSizeMergePolicy;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.update.DirectUpdateHandler2;
-import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
-public class TestPropInjectDefaults extends AbstractSolrTestCase {
-
- @Override
- public String getSchemaFile() {
- return "schema.xml";
- }
-
- @Override
- public String getSolrConfigFile() {
- return "solrconfig-propinject-indexdefault.xml";
+public class TestPropInjectDefaults extends SolrTestCaseJ4 {
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ initCore("solrconfig-propinject-indexdefault.xml", "schema.xml");
}
class ExposeWriterHandler extends DirectUpdateHandler2 {
@@ -47,7 +43,8 @@ public class TestPropInjectDefaults exte
return writer;
}
}
-
+
+ @Test
public void testMergePolicyDefaults() throws Exception {
ExposeWriterHandler uh = new ExposeWriterHandler();
IndexWriter writer = uh.getWriter();
@@ -56,7 +53,7 @@ public class TestPropInjectDefaults exte
uh.close();
}
-
+ @Test
public void testPropsDefaults() throws Exception {
ExposeWriterHandler uh = new ExposeWriterHandler();
IndexWriter writer = uh.getWriter();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/core/TestQuerySenderListener.java Wed Oct 20 12:44:28 2010
@@ -19,6 +19,7 @@ package org.apache.solr.core;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RefCounted;
import org.apache.solr.common.params.EventParams;
import org.apache.lucene.store.Directory;
import org.junit.BeforeClass;
@@ -48,7 +49,8 @@ public class TestQuerySenderListener ext
assertTrue("Not an instance of QuerySenderListener", newSearcherListener instanceof QuerySenderListener);
QuerySenderListener qsl = (QuerySenderListener) newSearcherListener;
- SolrIndexSearcher currentSearcher = core.getSearcher().get();
+ RefCounted<SolrIndexSearcher> currentSearcherRef = core.getSearcher();
+ SolrIndexSearcher currentSearcher = currentSearcherRef.get();
qsl.newSearcher(currentSearcher, null);//test new Searcher
MockQuerySenderListenerReqHandler mock = (MockQuerySenderListenerReqHandler) core.getRequestHandler("mock");
assertNotNull("Mock is null", mock);
@@ -62,6 +64,8 @@ public class TestQuerySenderListener ext
evt = mock.req.getParams().get(EventParams.EVENT);
assertNotNull("Event is null", evt);
assertTrue(evt + " is not equal to " + EventParams.NEW_SEARCHER, evt.equals(EventParams.NEW_SEARCHER) == true);
+ newSearcher.close();
+ currentSearcherRef.decref();
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/DocumentAnalysisRequestHandlerTest.java Wed Oct 20 12:44:28 2010
@@ -104,6 +104,8 @@ public class DocumentAnalysisRequestHand
field = document.getField("text");
assertNotNull(field);
assertEquals("The Text", field.getFirstValue());
+
+ req.close();
}
/**
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java Wed Oct 20 12:44:28 2010
@@ -25,6 +25,7 @@ import org.apache.solr.common.params.Mod
import org.apache.solr.common.util.NamedList;
import org.apache.solr.client.solrj.request.FieldAnalysisRequest;
import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrQueryRequest;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -66,7 +67,8 @@ public class FieldAnalysisRequestHandler
params.add(AnalysisParams.FIELD_VALUE, "the quick red fox jumped over the lazy brown dogs");
params.add(CommonParams.Q, "fox brown");
- FieldAnalysisRequest request = handler.resolveAnalysisRequest(new LocalSolrQueryRequest(h.getCore(), params));
+ SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params);
+ FieldAnalysisRequest request = handler.resolveAnalysisRequest(req);
List<String> fieldNames = request.getFieldNames();
assertEquals("Expecting 2 field names", 2, fieldNames.size());
assertEquals("text", fieldNames.get(0));
@@ -78,25 +80,35 @@ public class FieldAnalysisRequestHandler
assertEquals("the quick red fox jumped over the lazy brown dogs", request.getFieldValue());
assertEquals("fox brown", request.getQuery());
assertFalse(request.isShowMatch());
+ req.close();
// testing overide of query value using analysis.query param
params.add(AnalysisParams.QUERY, "quick lazy");
- request = handler.resolveAnalysisRequest(new LocalSolrQueryRequest(h.getCore(), params));
+ req=new LocalSolrQueryRequest(h.getCore(), params);
+ request = handler.resolveAnalysisRequest(req);
assertEquals("quick lazy", request.getQuery());
+ req.close();
// testing analysis.showmatch param
params.add(AnalysisParams.SHOW_MATCH, "false");
- request = handler.resolveAnalysisRequest(new LocalSolrQueryRequest(h.getCore(), params));
+ req=new LocalSolrQueryRequest(h.getCore(), params);
+ request = handler.resolveAnalysisRequest(req);
assertFalse(request.isShowMatch());
+ req.close();
+
params.set(AnalysisParams.SHOW_MATCH, "true");
- request = handler.resolveAnalysisRequest(new LocalSolrQueryRequest(h.getCore(), params));
+ req=new LocalSolrQueryRequest(h.getCore(), params);
+ request = handler.resolveAnalysisRequest(req);
assertTrue(request.isShowMatch());
+ req.close();
// testing absence of query value
params.remove(CommonParams.Q);
params.remove(AnalysisParams.QUERY);
- request = handler.resolveAnalysisRequest(new LocalSolrQueryRequest(h.getCore(), params));
+ req=new LocalSolrQueryRequest(h.getCore(), params);
+ request = handler.resolveAnalysisRequest(req);
assertNull(request.getQuery());
+ req.close();
}
/**
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java Wed Oct 20 12:44:28 2010
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.*;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ContentStreamBase;
@@ -30,21 +31,22 @@ import org.apache.solr.request.SolrQuery
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* TODO -- this needs to actually test the results/query etc
*/
-public class MoreLikeThisHandlerTest extends AbstractSolrTestCase {
+public class MoreLikeThisHandlerTest extends SolrTestCaseJ4 {
- @Override public String getSchemaFile() { return "schema.xml"; }
- @Override public String getSolrConfigFile() { return "solrconfig.xml"; }
- @Override public void setUp() throws Exception {
- super.setUp();
+ @BeforeClass
+ public static void moreLikeThisBeforeClass() throws Exception {
+ initCore("solrconfig.xml", "schema.xml");
lrf = h.getRequestFactory("standard", 0, 20 );
}
-
-
+
+ @Test
public void testInterface() throws Exception
{
SolrCore core = h.getCore();
@@ -68,6 +70,9 @@ public class MoreLikeThisHandlerTest ext
mlt.handleRequestBody( req, new SolrQueryResponse() );
}
catch( Exception ex ) {} // expected
+ finally {
+ req.close();
+ }
assertU(adoc("id","42","name","Tom Cruise","subword","Top Gun","subword","Risky Business","subword","The Color of Money","subword","Minority Report","subword", "Days of Thunder","subword", "Eyes Wide Shut","subword", "Far and Away", "foo_ti","10"));
assertU(adoc("id","43","name","Tom Hanks","subword","The Green Mile","subword","Forest Gump","subword","Philadelphia Story","subword","Big","subword","Cast Away", "foo_ti","10"));
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java Wed Oct 20 12:44:28 2010
@@ -444,6 +444,7 @@ public class TestReplicationHandler exte
masterClient = createNewSolrServer(masterJetty.getLocalPort());
copyFile(new File(SLAVE_CONFIG), new File(slave.getConfDir(), "solrconfig.xml"), masterJetty.getLocalPort());
//start slave
+ slaveJetty.stop();
slaveJetty = createJetty(slave);
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java Wed Oct 20 12:44:28 2010
@@ -16,7 +16,7 @@
*/
package org.apache.solr.handler;
-import org.apache.solr.util.AbstractSolrTestCase;
+import org.apache.solr.SolrTestCaseJ4;
import java.io.StringReader;
import java.util.Collection;
@@ -24,26 +24,20 @@ import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.apache.solr.common.SolrInputDocument;
+import org.junit.BeforeClass;
+import org.junit.Test;
-public class XmlUpdateRequestHandlerTest extends AbstractSolrTestCase
-{
- private XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- protected XmlUpdateRequestHandler handler;
-
-@Override public String getSchemaFile() { return "schema.xml"; }
-@Override public String getSolrConfigFile() { return "solrconfig.xml"; }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
+public class XmlUpdateRequestHandlerTest extends SolrTestCaseJ4 {
+ private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ protected static XmlUpdateRequestHandler handler;
+
+ @BeforeClass
+ public static void beforeTests() throws Exception {
+ initCore("solrconfig.xml","schema.xml");
handler = new XmlUpdateRequestHandler();
}
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
+
+ @Test
public void testReadDoc() throws Exception
{
String xml =
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedSpellCheckComponentTest.java Wed Oct 20 12:44:28 2010
@@ -96,5 +96,9 @@ public class DistributedSpellCheckCompon
query("q", "*:*", "fl", "id,lowerfilt", "spellcheck.q","toyata", "spellcheck", "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
query("q", "*:*", "fl", "id,lowerfilt", "spellcheck.q","bluo", "spellcheck", "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true", SpellCheckComponent.SPELLCHECK_COUNT, "4");
query("q", "The quick reb fox jumped over the lazy brown dogs", "fl", "id,lowerfilt", "spellcheck", "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true", SpellCheckComponent.SPELLCHECK_COUNT, "4", SpellCheckComponent.SPELLCHECK_COLLATE, "true");
+
+ query("q", "lowerfilt:(+quock +reb)", "fl", "id,lowerfilt", "spellcheck", "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true", SpellCheckComponent.SPELLCHECK_COUNT, "10", SpellCheckComponent.SPELLCHECK_COLLATE, "true", SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "10", SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "10", SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "true");
+ query("q", "lowerfilt:(+quock +reb)", "fl", "id,lowerfilt", "spellcheck", "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true", SpellCheckComponent.SPELLCHECK_COUNT, "10", SpellCheckComponent.SPELLCHECK_COLLATE, "true", SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "10", SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "10", SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "false");
+ query("q", "lowerfilt:(+quock +reb)", "fl", "id,lowerfilt", "spellcheck", "true", "qt", "spellCheckCompRH", "shards.qt", "spellCheckCompRH", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true", SpellCheckComponent.SPELLCHECK_COUNT, "10", SpellCheckComponent.SPELLCHECK_COLLATE, "true", SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "0", SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1", SpellCheckComponent.SPELLCHECK_COLLATE_EXTENDED_RESULTS, "false");
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/DistributedTermsComponentTest.java Wed Oct 20 12:44:28 2010
@@ -1,6 +1,7 @@
package org.apache.solr.handler.component;
import org.apache.solr.BaseDistributedSearchTestCase;
+import org.junit.Test;
/**
* Test for TermsComponent distributed querying
@@ -12,6 +13,7 @@ public class DistributedTermsComponentTe
@Override
public void doTest() throws Exception {
+ del("*:*");
index(id, 18, "b_t", "snake spider shark snail slug seal");
index(id, 19, "b_t", "snake spider shark snail slug");
index(id, 20, "b_t", "snake spider shark snail");
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java Wed Oct 20 12:44:28 2010
@@ -50,14 +50,6 @@ public class QueryElevationComponentTest
initCore("solrconfig-elevate.xml","schema12.xml");
}
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- clearIndex();
- assertU(commit());
- }
-
@Test
public void testInterface() throws Exception
{
@@ -70,9 +62,12 @@ public class QueryElevationComponentTest
QueryElevationComponent comp = new QueryElevationComponent();
comp.init( args );
comp.inform( core );
-
- IndexReader reader = core.getSearcher().get().getReader();
+
+ SolrQueryRequest req = req();
+ IndexReader reader = req.getSearcher().getReader();
Map<String, ElevationObj> map = comp.getElevationMap( reader, core );
+ req.close();
+
// Make sure the boosts loaded properly
assertEquals( 3, map.size() );
assertEquals( 1, map.get( "XXXX" ).priority.size() );
@@ -101,29 +96,15 @@ public class QueryElevationComponentTest
assertEquals( "xxxx", comp.getAnalyzedQuery( "XXXX" ) );
assertEquals( "xxxxyyyy", comp.getAnalyzedQuery( "XXXX YYYY" ) );
- }
- @Test
- public void testEmptyQuery() throws Exception {
- SolrCore core = h.getCore();
-
- //String query = "title:ipod";
-
- Map<String,String> args = new HashMap<String, String>();
- 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']");
+ assertQ("Make sure QEC handles null queries", req("qt","/elevate", "q.alt","*:*", "defType","dismax"),
+ "//*[@numFound='0']");
}
@Test
public void testSorting() throws IOException
{
- SolrCore core = h.getCore();
-
assertU(adoc("id", "a", "title", "ipod", "str_s", "a" ));
assertU(adoc("id", "b", "title", "ipod ipod", "str_s", "b" ));
assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s", "c" ));
@@ -141,8 +122,10 @@ public class QueryElevationComponentTest
args.put( CommonParams.FL, "id,score" );
args.put( "indent", "true" );
//args.put( CommonParams.FL, "id,title,score" );
- SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
-
+ SolrQueryRequest req = new LocalSolrQueryRequest( h.getCore(), new MapSolrParams( args) );
+ IndexReader reader = req.getSearcher().getReader();
+ QueryElevationComponent booster = (QueryElevationComponent)req.getCore().getSearchComponent( "elevate" );
+
assertQ("Make sure standard sort works as expected", req
,"//*[@numFound='3']"
,"//result/doc[1]/str[@name='id'][.='a']"
@@ -151,11 +134,10 @@ public class QueryElevationComponentTest
);
// Explicitly set what gets boosted
- IndexReader reader = core.getSearcher().get().getReader();
- QueryElevationComponent booster = (QueryElevationComponent)core.getSearchComponent( "elevate" );
booster.elevationCache.clear();
booster.setTopQueryResults( reader, query, new String[] { "x", "y", "z" }, null );
+
assertQ("All six should make it", req
,"//*[@numFound='6']"
,"//result/doc[1]/str[@name='id'][.='x']"
@@ -230,6 +212,8 @@ public class QueryElevationComponentTest
,"//result/doc[3]/str[@name='id'][.='c']"
);
+
+ req.close();
}
// write a test file to boost some docs
@@ -253,31 +237,33 @@ public class QueryElevationComponentTest
@Test
public void testElevationReloading() throws Exception
{
- SolrCore core = h.getCore();
-
String testfile = "data-elevation.xml";
- File f = new File( core.getDataDir(), testfile );
+ File f = new File( h.getCore().getDataDir(), testfile );
writeFile( f, "aaa", "A" );
- QueryElevationComponent comp = (QueryElevationComponent)core.getSearchComponent("elevate");
+ QueryElevationComponent comp = (QueryElevationComponent)h.getCore().getSearchComponent("elevate");
NamedList<String> args = new NamedList<String>();
args.add( QueryElevationComponent.CONFIG_FILE, testfile );
comp.init( args );
- comp.inform( core );
-
- IndexReader reader = core.getSearcher().get().getReader();
- Map<String, ElevationObj> map = comp.getElevationMap(reader, core);
+ comp.inform( h.getCore() );
+
+ SolrQueryRequest req = req();
+ IndexReader reader = req.getSearcher().getReader();
+ Map<String, ElevationObj> map = comp.getElevationMap(reader, h.getCore());
assertTrue( map.get( "aaa" ).priority.containsKey( new BytesRef("A") ) );
assertNull( map.get( "bbb" ) );
+ req.close();
// now change the file
writeFile( f, "bbb", "B" );
assertU(adoc("id", "10000")); // will get same reader if no index change
assertU(commit());
-
- reader = core.getSearcher().get().getReader();
- map = comp.getElevationMap(reader, core);
+
+ req = req();
+ reader = req.getSearcher().getReader();
+ map = comp.getElevationMap(reader, h.getCore());
assertNull( map.get( "aaa" ) );
assertTrue( map.get( "bbb" ).priority.containsKey( new BytesRef("B") ) );
+ req.close();
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SearchHandlerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SearchHandlerTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SearchHandlerTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SearchHandlerTest.java Wed Oct 20 12:44:28 2010
@@ -20,17 +20,23 @@ package org.apache.solr.handler.componen
import java.util.ArrayList;
import java.util.List;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
-public class SearchHandlerTest extends AbstractSolrTestCase
+public class SearchHandlerTest extends SolrTestCaseJ4
{
- @Override public String getSchemaFile() { return "schema.xml"; }
- @Override public String getSolrConfigFile() { return "solrconfig.xml"; }
+ @BeforeClass
+ public static void beforeTests() throws Exception {
+ initCore("solrconfig.xml","schema.xml");
+ }
+
@SuppressWarnings("unchecked")
+ @Test
public void testInitalization()
{
SolrCore core = h.getCore();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java Wed Oct 20 12:44:28 2010
@@ -21,21 +21,15 @@ import java.io.File;
import java.util.*;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SpellingParams;
import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.spelling.AbstractLuceneSpellChecker;
-import org.apache.solr.spelling.IndexBasedSpellChecker;
import org.junit.BeforeClass;
import org.junit.Test;
+
import static org.junit.Assert.*;
@@ -43,341 +37,96 @@ import static org.junit.Assert.*;
* @since solr 1.3
*/
public class SpellCheckComponentTest extends SolrTestCaseJ4 {
+ static String rh = "spellCheckCompRH";
+
+
@BeforeClass
public static void beforeClass() throws Exception {
- initCore("solrconfig.xml","schema.xml");
- assertNull(h.validateUpdate(adoc("id", "0", "lowerfilt", "This is a title")));
- assertNull(h.validateUpdate(adoc("id", "1", "lowerfilt",
+ initCore("solrconfig-spellcheckcomponent.xml","schema.xml");
+ assertU(adoc("id", "0", "lowerfilt", "This is a title"));
+ assertU((adoc("id", "1", "lowerfilt",
"The quick reb fox jumped over the lazy brown dogs.")));
- assertNull(h.validateUpdate(adoc("id", "2", "lowerfilt", "This is a document")));
- assertNull(h.validateUpdate(adoc("id", "3", "lowerfilt", "another document")));
+ assertU((adoc("id", "2", "lowerfilt", "This is a document")));
+ assertU((adoc("id", "3", "lowerfilt", "another document")));
//bunch of docs that are variants on blue
- assertNull(h.validateUpdate(adoc("id", "4", "lowerfilt", "blue")));
- assertNull(h.validateUpdate(adoc("id", "5", "lowerfilt", "blud")));
- assertNull(h.validateUpdate(adoc("id", "6", "lowerfilt", "boue")));
- assertNull(h.validateUpdate(adoc("id", "7", "lowerfilt", "glue")));
- assertNull(h.validateUpdate(adoc("id", "8", "lowerfilt", "blee")));
- assertNull(h.validateUpdate(adoc("id", "9", "lowerfilt", "pixmaa")));
- assertNull(h.validateUpdate(commit()));
+ assertU((adoc("id", "4", "lowerfilt", "blue")));
+ assertU((adoc("id", "5", "lowerfilt", "blud")));
+ assertU((adoc("id", "6", "lowerfilt", "boue")));
+ assertU((adoc("id", "7", "lowerfilt", "glue")));
+ assertU((adoc("id", "8", "lowerfilt", "blee")));
+ assertU((adoc("id", "9", "lowerfilt", "pixmaa")));
+ assertU((commit()));
}
@Test
public void testExtendedResultsCount() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent speller = core.getSearchComponent("spellcheck");
- assertTrue("speller is null and it shouldn't be", speller != null);
-
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.QT, "spellCheckCompRH");
- params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- params.add(CommonParams.Q, "bluo");
- params.add(SpellCheckComponent.COMPONENT_NAME, "true");
- params.add(SpellCheckComponent.SPELLCHECK_COUNT, String.valueOf(5));
- params.add(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, String.valueOf(false));
- SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
- SolrQueryResponse rsp;
- rsp = new SolrQueryResponse();
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- String cmdExec = (String) values.get("command");
- assertEquals("build",cmdExec);
- NamedList spellCheck = (NamedList) values.get("spellcheck");
- NamedList suggestions = (NamedList) spellCheck.get("suggestions");
- NamedList blue = (NamedList) suggestions.get("bluo");
- assertEquals(5,blue.get("numFound"));
- Collection<String> theSuggestion = (Collection<String>) blue.get("suggestion");
- assertEquals(5,theSuggestion.size());
- //we know there are at least 5, but now only get 3
-
- params.remove(SpellCheckComponent.SPELLCHECK_COUNT);
- params.remove(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS);
- params.remove(SpellCheckComponent.SPELLCHECK_BUILD);
- params.add(SpellCheckComponent.SPELLCHECK_COUNT, "3");
- params.add(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, String.valueOf(true));
- params.add(SpellCheckComponent.SPELLCHECK_BUILD, "false");
- rsp = new SolrQueryResponse();
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- values = rsp.getValues();
-
- spellCheck = (NamedList) values.get("spellcheck");
- suggestions = (NamedList) spellCheck.get("suggestions");
- blue = (NamedList) suggestions.get("bluo");
- assertEquals(3, blue.get("numFound"));
-
- List<SimpleOrderedMap> theSuggestions = (List<SimpleOrderedMap>)blue.get("suggestion");
- assertEquals(3, theSuggestions.size());
-
- for (SimpleOrderedMap sug : theSuggestions) {
- assertNotNull(sug.get("word"));
- assertNotNull(sug.get("freq"));
- }
+ assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_BUILD, "true", "q","bluo", SpellCheckComponent.SPELLCHECK_COUNT,"5", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS,"false")
+ ,"/spellcheck/suggestions/[0]=='bluo'"
+ ,"/spellcheck/suggestions/[1]/numFound==5"
+ );
+
+ assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","bluo", SpellCheckComponent.SPELLCHECK_COUNT,"3", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS,"true")
+ ,"/spellcheck/suggestions/[1]/suggestion==[{'word':'blue','freq':1}, {'word':'blud','freq':1}, {'word':'boue','freq':1}]"
+ );
}
@Test
public void test() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent speller = core.getSearchComponent("spellcheck");
- assertTrue("speller is null and it shouldn't be", speller != null);
-
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.QT, "spellCheckCompRH");
- params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- params.add(CommonParams.Q, "documemt");
- params.add(SpellCheckComponent.COMPONENT_NAME, "true");
-
- SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
- SolrQueryResponse rsp = new SolrQueryResponse();
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- String cmdExec = (String) values.get("command");
- assertTrue("command is null and it shouldn't be", cmdExec != null);
- assertTrue(cmdExec + " is not equal to " + "build",
- cmdExec.equals("build") == true);
- NamedList spellCheck = (NamedList) values.get("spellcheck");
- assertNotNull(spellCheck);
- NamedList suggestions = (NamedList) spellCheck.get("suggestions");
- assertNotNull(suggestions);
- NamedList document = (NamedList) suggestions.get("documemt");
- assertEquals(1, document.get("numFound"));
- assertEquals(0, document.get("startOffset"));
- assertEquals(document.get("endOffset"), "documemt".length());
- Collection<String> theSuggestion = (Collection<String>) document.get("suggestion");
- assertEquals(1, theSuggestion.size());
- assertEquals("document", theSuggestion.iterator().next());
+ assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documemt")
+ ,"/spellcheck=={'suggestions':['documemt',{'numFound':1,'startOffset':0,'endOffset':8,'suggestion':['document']}]}"
+ );
}
@Test
public void testPerDictionary() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent speller = core.getSearchComponent("spellcheck");
- assertTrue("speller is null and it shouldn't be", speller != null);
-
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.QT, "spellCheckCompRH");
- params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- params.add(CommonParams.Q, "documemt");
- params.add(SpellCheckComponent.COMPONENT_NAME, "true");
- params.add(SpellingParams.SPELLCHECK_DICT, "perDict");
-
- params.add(SpellingParams.SPELLCHECK_PREFIX + ".perDict.foo", "bar");
- params.add(SpellingParams.SPELLCHECK_PREFIX + ".perDict.bar", "foo");
-
- SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
- SolrQueryResponse rsp = new SolrQueryResponse();
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
-
- NamedList spellCheck = (NamedList) values.get("spellcheck");
- NamedList suggestions = (NamedList) spellCheck.get("suggestions");
- assertNotNull("suggestions", suggestions);
- NamedList suggestion;
- Collection<String> theSuggestion;
- suggestion = (NamedList) suggestions.get("foo");
- assertEquals(1, suggestion.get("numFound"));
- assertEquals(0, suggestion.get("startOffset"));
- assertEquals(suggestion.get("endOffset"), 1);
- theSuggestion = (Collection<String>) suggestion.get("suggestion");
- assertEquals(1, theSuggestion.size());
- assertEquals("bar", theSuggestion.iterator().next());
-
- suggestion = (NamedList) suggestions.get("bar");
- assertEquals(1, suggestion.get("numFound"));
- assertEquals(2, suggestion.get("startOffset"));
- assertEquals(3, suggestion.get("endOffset"));
- theSuggestion = (Collection<String>) suggestion.get("suggestion");
- assertEquals(1, theSuggestion.size());
- assertEquals("foo", theSuggestion.iterator().next());
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_BUILD, "true", "q","documemt"
+ , SpellingParams.SPELLCHECK_DICT, "perDict", SpellingParams.SPELLCHECK_PREFIX + ".perDict.foo", "bar", SpellingParams.SPELLCHECK_PREFIX + ".perDict.bar", "foo")
+ ,"/spellcheck/suggestions/bar=={'numFound':1, 'startOffset':0, 'endOffset':1, 'suggestion':['foo']}"
+ ,"/spellcheck/suggestions/foo=={'numFound':1, 'startOffset':2, 'endOffset':3, 'suggestion':['bar']}"
+ );
}
@Test
public void testCollate() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent speller = core.getSearchComponent("spellcheck");
- assertTrue("speller is null and it shouldn't be", speller != null);
-
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.QT, "spellCheckCompRH");
- params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- params.add(CommonParams.Q, "documemt");
- params.add(SpellCheckComponent.COMPONENT_NAME, "true");
- params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
-
- SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
- SolrQueryResponse rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- NamedList spellCheck = (NamedList) values.get("spellcheck");
- NamedList suggestions = (NamedList) spellCheck.get("suggestions");
- String collation = (String) suggestions.get("collation");
- assertEquals("document", collation);
- params.remove(CommonParams.Q);
- params.add(CommonParams.Q, "documemt lowerfilt:broen^4");
- handler = core.getRequestHandler("spellCheckCompRH");
- rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- values = rsp.getValues();
- spellCheck = (NamedList) values.get("spellcheck");
- suggestions = (NamedList) spellCheck.get("suggestions");
- collation = (String) suggestions.get("collation");
- assertEquals("document lowerfilt:brown^4", collation);
-
- params.remove(CommonParams.Q);
- params.add(CommonParams.Q, "documemtsss broens");
- handler = core.getRequestHandler("spellCheckCompRH");
- rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- values = rsp.getValues();
- spellCheck = (NamedList) values.get("spellcheck");
- suggestions = (NamedList) spellCheck.get("suggestions");
- collation = (String) suggestions.get("collation");
- assertEquals("document brown",collation);
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellCheckComponent.SPELLCHECK_BUILD, "true", "q","documemt", SpellCheckComponent.SPELLCHECK_COLLATE, "true")
+ ,"/spellcheck/suggestions/collation=='document'"
+ );
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documemt lowerfilt:broen^4", SpellCheckComponent.SPELLCHECK_COLLATE, "true")
+ ,"/spellcheck/suggestions/collation=='document lowerfilt:brown^4'"
+ );
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documemtsss broens", SpellCheckComponent.SPELLCHECK_COLLATE, "true")
+ ,"/spellcheck/suggestions/collation=='document brown'"
+ );
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","pixma-a-b-c-d-e-f-g", SpellCheckComponent.SPELLCHECK_COLLATE, "true")
+ ,"/spellcheck/suggestions/collation=='pixmaa'"
+ );
}
- @Test
- public void testCollate2() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent speller = core.getSearchComponent("spellcheck");
- assertTrue("speller is null and it shouldn't be", speller != null);
-
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.QT, "spellCheckCompRH");
- params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- params.add(CommonParams.Q, "pixma-a-b-c-d-e-f-g");
- params.add(SpellCheckComponent.COMPONENT_NAME, "true");
- params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true");
-
- SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
- SolrQueryResponse rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- NamedList spellCheck = (NamedList) values.get("spellcheck");
- NamedList suggestions = (NamedList) spellCheck.get("suggestions");
- String collation = (String) suggestions.get("collation");
- assertEquals("pixmaa", collation);
- }
@Test
public void testCorrectSpelling() throws Exception {
- SolrCore core = h.getCore();
- Map<String, String> args = new HashMap<String, String>();
-
- args.put(CommonParams.Q, "lowerfilt:lazy lowerfilt:brown");
- args.put(CommonParams.QT, "spellCheckCompRH");
- args.put(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- args.put(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
- args.put(SpellCheckComponent.COMPONENT_NAME, "true");
- SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(
- args));
-
- assertQ("Make sure correct spellings are signalled in the response", req,
- "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='1']",
- "//*/lst[@name='suggestions']");
-
-
- args = new HashMap<String, String>();
-
- args.put(CommonParams.Q, "lakkle");
- args.put(CommonParams.QT, "spellCheckCompRH");
- args.put(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
- args.put(SpellCheckComponent.COMPONENT_NAME, "true");
- req = new LocalSolrQueryRequest(core, new MapSolrParams(
- args));
-
- assertQ("Make sure correct spellings are signalled in the response", req,
- "//*[@numFound='0']", "//*/lst[@name='suggestions']", "//*/bool[@name='correctlySpelled'][.='false']");
-
-
- args = new HashMap<String, String>();
-
- args.put(CommonParams.Q, "lowerfilt:lazy");
- args.put(CommonParams.QT, "spellCheckCompRH");
- args.put(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
- args.put(SpellCheckComponent.COMPONENT_NAME, "true");
- req = new LocalSolrQueryRequest(core, new MapSolrParams(
- args));
-
- assertQ("Make sure correct spellings are signalled in the response", req,
- "//*[@numFound='1']", "//*/lst[@name='suggestions']", "//*/bool[@name='correctlySpelled'][.='true']");
- }
-
- @Test
- public void testInit() throws Exception {
- SolrCore core = h.getCore();
- SpellCheckComponent scc = new SpellCheckComponent();
- NamedList args = new NamedList();
- NamedList spellchecker = new NamedList();
- spellchecker.add("classname", IndexBasedSpellChecker.class.getName());
- spellchecker.add("name", "default");
- spellchecker.add("field", "lowerfilt");
- spellchecker.add("spellcheckIndexDir", "./spellchecker");
-
- args.add("spellchecker", spellchecker);
- NamedList altSC = new NamedList();
- altSC.add("classname", IndexBasedSpellChecker.class.getName());
- altSC.add("name", "alternate");
- altSC.add("field", "lowerfilt");
- altSC.add("spellcheckIndexDir", "./spellchecker");
-
- args.add("spellchecker", altSC);
- args.add("queryAnalyzerFieldType", "lowerfilt");
- NamedList defaults = new NamedList();
- defaults.add(SpellCheckComponent.SPELLCHECK_COLLATE, true);
- defaults.add(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, false);
- defaults.add(SpellCheckComponent.SPELLCHECK_COUNT, 2);
- args.add("defaults", defaults);
- scc.init(args);
- scc.inform(core);
- //hmm, not sure what to assert here...
-
- //add the sc again and then init again, we should get an exception
- args.add("spellchecker", spellchecker);
- scc = new SpellCheckComponent();
- scc.init(args);
- try {
- scc.inform(core);
- assertTrue(false);
- } catch (Exception e) {
-
- }
-
-
+ // Make sure correct spellings are signaled in the response
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","lowerfilt:lazy lowerfilt:brown", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true")
+ ,"/spellcheck/suggestions=={'correctlySpelled':true}"
+ );
+ assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","lakkle", SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true")
+ ,"/spellcheck/suggestions/correctlySpelled==false"
+ );
}
@SuppressWarnings("unchecked")
@Test
public void testRelativeIndexDirLocation() throws Exception {
SolrCore core = h.getCore();
- Map<String, String> args = new HashMap<String, String>();
-
- args.put(CommonParams.Q, "test");
- args.put(CommonParams.QT, "spellCheckCompRH");
- args.put(SpellCheckComponent.SPELLCHECK_BUILD, "true");
- args.put(SpellCheckComponent.COMPONENT_NAME, "true");
- SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(
- args));
-
- File indexDir = new File(core.getDataDir() + File.separator
- + "spellchecker1");
- assertTrue(
- "spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml",
- indexDir.exists());
+ File indexDir = new File(core.getDataDir() + File.separator + "spellchecker1");
+ assertTrue(indexDir.exists());
- indexDir = new File(core.getDataDir() + File.separator
- + "spellchecker2");
- assertTrue(
- "spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml",
- indexDir.exists());
+ indexDir = new File(core.getDataDir() + File.separator + "spellchecker2");
+ assertTrue(indexDir.exists());
- indexDir = new File(core.getDataDir() + File.separator
- + "spellchecker3");
- assertTrue(
- "spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml",
- indexDir.exists());
+ indexDir = new File(core.getDataDir() + File.separator + "spellchecker3");
+ assertTrue(indexDir.exists());
}
@Test
@@ -396,6 +145,7 @@ public class SpellCheckComponentTest ext
spellchecker.add(AbstractLuceneSpellChecker.INDEX_DIR, "spellchecker1");
args.add("spellchecker", spellchecker);
+ // TODO: this is really fragile and error prone - find a higher level way to test this.
SpellCheckComponent checker = new SpellCheckComponent();
checker.init(args);
checker.inform(h.getCore());
@@ -414,6 +164,8 @@ public class SpellCheckComponentTest ext
} catch (NullPointerException e) {
fail("NullPointerException due to reload not initializing analyzers");
}
+
+ rb.req.close();
}
@SuppressWarnings("unchecked")
@@ -428,7 +180,4 @@ public class SpellCheckComponentTest ext
assertQ(req, "//arr[@name='suggestion'][.='lucenejava']");
}
-
- // TODO: add more tests for various spelling options
-
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java Wed Oct 20 12:44:28 2010
@@ -46,299 +46,124 @@ public class TermVectorComponentTest ext
public static void beforeClass() throws Exception {
initCore("solrconfig.xml","schema.xml");
- assertNull(h.validateUpdate(adoc("id", "0",
+ assertU(adoc("id", "0",
"test_posofftv", "This is a title and another title",
"test_basictv", "This is a title and another title",
"test_notv", "This is a title and another title",
"test_postv", "This is a title and another title",
"test_offtv", "This is a title and another title"
- )));
- assertNull(h.validateUpdate(adoc("id", "1",
+ ));
+ assertU(adoc("id", "1",
"test_posofftv", "The quick reb fox jumped over the lazy brown dogs.",
"test_basictv", "The quick reb fox jumped over the lazy brown dogs.",
"test_notv", "The quick reb fox jumped over the lazy brown dogs.",
"test_postv", "The quick reb fox jumped over the lazy brown dogs.",
"test_offtv", "The quick reb fox jumped over the lazy brown dogs."
- )));
- assertNull(h.validateUpdate(adoc("id", "2",
+ ));
+ assertU(adoc("id", "2",
"test_posofftv", "This is a document",
"test_basictv", "This is a document",
"test_notv", "This is a document",
"test_postv", "This is a document",
"test_offtv", "This is a document"
- )));
- assertNull(h.validateUpdate(adoc("id", "3",
+ ));
+ assertU(adoc("id", "3",
"test_posofftv", "another document",
"test_basictv", "another document",
"test_notv", "another document",
"test_postv", "another document",
"test_offtv", "another document"
- )));
+ ));
//bunch of docs that are variants on blue
- assertNull(h.validateUpdate(adoc("id", "4",
+ assertU(adoc("id", "4",
"test_posofftv", "blue",
"test_basictv", "blue",
"test_notv", "blue",
"test_postv", "blue",
"test_offtv", "blue"
- )));
- assertNull(h.validateUpdate(adoc("id", "5",
+ ));
+ assertU(adoc("id", "5",
"test_posofftv", "blud",
"test_basictv", "blud",
"test_notv", "blud",
"test_postv", "blud",
"test_offtv", "blud"
- )));
- assertNull(h.validateUpdate(adoc("id", "6",
+ ));
+ assertU(adoc("id", "6",
"test_posofftv", "boue",
"test_basictv", "boue",
"test_notv", "boue",
"test_postv", "boue",
"test_offtv", "boue"
- )));
- assertNull(h.validateUpdate(adoc("id", "7",
+ ));
+ assertU(adoc("id", "7",
"test_posofftv", "glue",
"test_basictv", "glue",
"test_notv", "glue",
"test_postv", "glue",
"test_offtv", "glue"
- )));
- assertNull(h.validateUpdate(adoc("id", "8",
+ ));
+ assertU(adoc("id", "8",
"test_posofftv", "blee",
"test_basictv", "blee",
"test_notv", "blee",
"test_postv", "blee",
"test_offtv", "blee"
- )));
- assertNull(h.validateUpdate(adoc("id", "9",
+ ));
+ assertU(adoc("id", "9",
"test_posofftv", "blah",
"test_basictv", "blah",
"test_notv", "blah",
"test_postv", "blah",
"test_offtv", "blah"
- )));
+ ));
assertNull(h.validateUpdate(commit()));
}
+ static String tv = "tvrh";
+
@Test
public void testBasics() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent tvComp = core.getSearchComponent("tvComponent");
- assertTrue("tvComp is null and it shouldn't be", tvComp != null);
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.Q, "id:0");
- params.add(CommonParams.QT, "tvrh");
- params.add(TermVectorParams.TF, "true");
- params.add(TermVectorComponent.COMPONENT_NAME, "true");
- SolrRequestHandler handler = core.getRequestHandler("tvrh");
- SolrQueryResponse rsp;
- rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- NamedList termVectors = (NamedList) values.get(TermVectorComponent.TERM_VECTORS);
- assertTrue("termVectors is null and it shouldn't be", termVectors != null);
- if (VERBOSE) System.out.println("TVs:" + termVectors);
- NamedList doc = (NamedList) termVectors.getVal(0);
- assertTrue("doc is null and it shouldn't be", doc != null);
- assertEquals(doc.size(), 5);
- NamedList field = (NamedList) doc.get("test_posofftv");
- assertTrue("field is null and it shouldn't be", field != null);
- assertTrue(field.size() + " does not equal: " + 2, field.size() == 2);
- NamedList titl = (NamedList) field.get("titl");
- assertTrue("titl is null and it shouldn't be", titl != null);
- assertTrue(titl.get("tf") + " does not equal: " + 2, ((Integer) titl.get("tf")) == 2);
- //there should not be any positions or offsets
- NamedList positions = (NamedList) titl.get("positions");
- assertTrue("positions is not null and it should be", positions == null);
- NamedList offsets = (NamedList) titl.get("offsets");
- assertTrue("offsets is not null and it should be", offsets == null);
- String uniqueKeyFieldName = (String) termVectors.getVal(1);
- assertTrue("uniqueKeyFieldName is null and it shouldn't be", uniqueKeyFieldName != null);
- assertTrue(uniqueKeyFieldName + " is not equal to " + "id", uniqueKeyFieldName.equals("id") == true);
-
+ assertJQ(req("json.nl","map", "qt",tv, "q", "id:0", TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true")
+ ,"/termVectors=={'doc-0':{'uniqueKey':'0'," +
+ " 'test_basictv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
+ " 'test_offtv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
+ " 'test_posofftv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
+ " 'test_postv':{'anoth':{'tf':1},'titl':{'tf':2}}}," +
+ " 'uniqueKeyFieldName':'id'}"
+ );
}
@Test
public void testOptions() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent tvComp = core.getSearchComponent("tvComponent");
- assertTrue("tvComp is null and it shouldn't be", tvComp != null);
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.Q, "id:0");
- params.add(CommonParams.QT, "tvrh");
- params.add(TermVectorParams.TF, "true");
- params.add(TermVectorParams.DF, "true");
- params.add(TermVectorParams.OFFSETS, "true");
- params.add(TermVectorParams.POSITIONS, "true");
- params.add(TermVectorParams.TF_IDF, "true");
- params.add(TermVectorComponent.COMPONENT_NAME, "true");
-
- SolrRequestHandler handler = core.getRequestHandler("tvrh");
- SolrQueryResponse rsp;
- rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- NamedList termVectors = (NamedList) values.get(TermVectorComponent.TERM_VECTORS);
- assertTrue("termVectors is null and it shouldn't be", termVectors != null);
- // System.out.println("TVs: " + termVectors);
- NamedList doc = (NamedList) termVectors.getVal(0);
- assertTrue("doc is null and it shouldn't be", doc != null);
- assertEquals(doc.size(), 5);
- NamedList offtv = (NamedList) doc.get("test_posofftv");
- assertTrue("offtv is null and it shouldn't be", offtv != null);
- assertTrue("offtv Size: " + offtv.size() + " is not: " + 2, offtv.size() == 2);
- NamedList another = (NamedList) offtv.get("anoth");
- NamedList offsets = (NamedList) another.get("offsets");
- assertTrue("offsets is null and it shouldn't be", offsets != null);
- assertTrue("offsets Size: " + offsets.size() + " is not greater than: " + 0, offsets.size() > 0);
- NamedList pos = (NamedList) another.get("positions");
- assertTrue("pos is null and it shouldn't be", pos != null);
- assertTrue("pos Size: " + pos.size() + " is not greater than: " + 0, pos.size() > 0);
- Integer df = (Integer) another.get("df");
- assertTrue("df is null and it shouldn't be", df != null);
- assertTrue(df + " does not equal: " + 2, df == 2);
- Double tfIdf = (Double) another.get("tf-idf");
- assertTrue("tfIdf is null and it shouldn't be", tfIdf != null);
- assertTrue(tfIdf + " does not equal: " + 0.5, tfIdf == 0.5);
+ assertJQ(req("json.nl","map", "qt",tv, "q", "id:0", TermVectorComponent.COMPONENT_NAME, "true"
+ , TermVectorParams.TF, "true", TermVectorParams.DF, "true", TermVectorParams.OFFSETS, "true", TermVectorParams.POSITIONS, "true", TermVectorParams.TF_IDF, "true")
+ ,"/termVectors/doc-0/test_posofftv/anoth=={'tf':1, 'offsets':{'start':20, 'end':27}, 'positions':{'position':1}, 'df':2, 'tf-idf':0.5}"
+ );
}
- /*
-<field name="test_basictv" type="text" termVectors="true"/>
- <field name="test_notv" type="text" termVectors="false"/>
- <field name="test_postv" type="text" termVectors="true" termPositions="true"/>
- <field name="test_offtv" type="text" termVectors="true" termOffsets="true"/>
- <field name="test_posofftv" type="text" termVectors="true"
- termPositions="true" termOffsets="true"/>
- */
@Test
public void testPerField() throws Exception {
- SolrCore core = h.getCore();
- SearchComponent tvComp = core.getSearchComponent("tvComponent");
- assertTrue("tvComp is null and it shouldn't be", tvComp != null);
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.Q, "id:0");
- params.add(CommonParams.QT, "tvrh");
- params.add(TermVectorParams.FIELDS, "test_basictv,test_notv,test_postv,test_offtv,test_posofftv");
- params.add(TermVectorParams.TF, "true");
- params.add(TermVectorParams.DF, "true");
- params.add(TermVectorParams.OFFSETS, "true");
- params.add(TermVectorParams.POSITIONS, "true");
- params.add(TermVectorParams.TF_IDF, "true");
- params.add(TermVectorComponent.COMPONENT_NAME, "true");
- //per field
- params.add("f.test_posofftv." + TermVectorParams.POSITIONS, "false");
- params.add("f.test_offtv." + TermVectorParams.OFFSETS, "false");
- params.add("f.test_basictv." + TermVectorParams.DF, "false");
- params.add("f.test_basictv." + TermVectorParams.TF, "false");
- params.add("f.test_basictv." + TermVectorParams.TF_IDF, "false");
- SolrRequestHandler handler = core.getRequestHandler("tvrh");
- SolrQueryResponse rsp;
- rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- NamedList values = rsp.getValues();
- NamedList termVectors = (NamedList) values.get(TermVectorComponent.TERM_VECTORS);
- assertTrue("termVectors is null and it shouldn't be", termVectors != null);
- if (VERBOSE) System.out.println("TVs: " + termVectors);
- NamedList doc = (NamedList) termVectors.get("doc-0");
- assertTrue("doc is null and it shouldn't be", doc != null);
- assertEquals(doc.size(), 5);
- NamedList vec;
- NamedList another;
- NamedList offsets;
- NamedList pos;
- Integer df;
- Double val;
- vec = (NamedList) doc.get("test_posofftv");
- assertNotNull(vec);
- assertEquals(vec.size(), 2);
- another = (NamedList) vec.get("anoth");
- offsets = (NamedList) another.get("offsets");
- assertNotNull(offsets);
- assertTrue(offsets.size() > 0);
- pos = (NamedList) another.get("positions");
- //positions should be null, since we turned them off
- assertNull(pos);
- df = (Integer) another.get("df");
- assertNotNull(df);
- assertTrue(df == 2);
- val = (Double) another.get("tf-idf");
- assertTrue("tfIdf is null and it shouldn't be", val != null);
- assertTrue(val + " does not equal: " + 0.5, val == 0.5);
- //Try out the other fields, too
- vec = (NamedList) doc.get("test_offtv");
- assertNotNull(vec);
- assertEquals(vec.size(), 2);
- another = (NamedList) vec.get("anoth");
- offsets = (NamedList) another.get("offsets");
- assertNull(offsets);
- pos = (NamedList) another.get("positions");
- //positions should be null, since we turned them off
- assertNull(vec.toString(), pos);
- df = (Integer) another.get("df");
- assertNotNull(df);
- assertTrue(df == 2);
- val = (Double) another.get("tf-idf");
- assertTrue("tfIdf is null and it shouldn't be", val != null);
- assertTrue(val + " does not equal: " + 0.5, val == 0.5);
- vec = (NamedList) doc.get("test_basictv");
- assertNotNull(vec);
- assertEquals(vec.size(), 2);
- another = (NamedList) vec.get("anoth");
- offsets = (NamedList) another.get("offsets");
- assertNull(offsets);
- pos = (NamedList) another.get("positions");
- assertNull(pos);
- df = (Integer) another.get("df");
- assertNull(df);
- val = (Double) another.get("tf-idf");
- assertNull(val);
- val = (Double) another.get("tf");
- assertNull(val);
- //Now validate we have error messages
- NamedList warnings = (NamedList) termVectors.get("warnings");
- assertNotNull(warnings);
- List<String> theList;
- theList = (List<String>) warnings.get("noTermVectors");
- assertNotNull(theList);
- assertEquals(theList.size(), 1);
- theList = (List<String>) warnings.get("noPositions");
- assertNotNull(theList);
- assertEquals(theList.size(), 2);
- theList = (List<String>) warnings.get("noOffsets");
- assertNotNull(theList);
- assertEquals(theList.size(), 2);
- }
-
- @Test
- public void testNoFields() throws Exception {
- ignoreException("undefined field: foo");
- SolrCore core = h.getCore();
- SearchComponent tvComp = core.getSearchComponent("tvComponent");
- assertTrue("tvComp is null and it shouldn't be", tvComp != null);
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add(CommonParams.Q, "id:0");
- params.add(CommonParams.QT, "tvrh");
- params.add(TermVectorParams.TF, "true");
- //Pass in a field that doesn't exist on the doc, thus, no vectors should be returned
- params.add(TermVectorParams.FIELDS, "foo");
- params.add(TermVectorComponent.COMPONENT_NAME, "true");
- SolrRequestHandler handler = core.getRequestHandler("tvrh");
- SolrQueryResponse rsp;
- rsp = new SolrQueryResponse();
- rsp.add("responseHeader", new SimpleOrderedMap());
- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
- Exception exception = rsp.getException();
- assertNotNull(exception);
- resetExceptionIgnores();
+ assertJQ(req("json.nl","map", "qt",tv, "q", "id:0", TermVectorComponent.COMPONENT_NAME, "true"
+ ,TermVectorParams.TF, "true", TermVectorParams.DF, "true", TermVectorParams.OFFSETS, "true", TermVectorParams.POSITIONS, "true", TermVectorParams.TF_IDF, "true"
+ ,TermVectorParams.FIELDS, "test_basictv,test_notv,test_postv,test_offtv,test_posofftv"
+ ,"f.test_posofftv." + TermVectorParams.POSITIONS, "false"
+ ,"f.test_offtv." + TermVectorParams.OFFSETS, "false"
+ ,"f.test_basictv." + TermVectorParams.DF, "false"
+ ,"f.test_basictv." + TermVectorParams.TF, "false"
+ ,"f.test_basictv." + TermVectorParams.TF_IDF, "false"
+ )
+ ,"/termVectors/doc-0/test_basictv=={'anoth':{},'titl':{}}"
+ ,"/termVectors/doc-0/test_postv/anoth=={'tf':1, 'positions':{'position':1}, 'df':2, 'tf-idf':0.5}"
+ ,"/termVectors/doc-0/test_offtv/anoth=={'tf':1, 'df':2, 'tf-idf':0.5}"
+ ,"/termVectors/warnings=={ 'noTermVectors':['test_notv'], 'noPositions':['test_basictv', 'test_offtv'], 'noOffsets':['test_basictv', 'test_postv']}"
+ );
}
-
-
+ // TODO: this test is really fragile since it pokes around in solr's guts and makes many assumptions.
+ // it should be rewritten to use the real distributed interface
@Test
public void testDistributed() throws Exception {
SolrCore core = h.getCore();
@@ -379,14 +204,13 @@ public class TermVectorComponentTest ext
ModifiableSolrParams solrParams = request.params;
log.info("Shard: " + Arrays.asList(request.shards) + " Params: " + solrParams);
}
+
+ rb.req.close();
}
}
-
-
-
/*
* <field name="test_basictv" type="text" termVectors="true"/>
<field name="test_notv" type="text" termVectors="false"/>
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/highlight/HighlighterTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/highlight/HighlighterTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/highlight/HighlighterTest.java Wed Oct 20 12:44:28 2010
@@ -700,6 +700,7 @@ public class HighlighterTest extends Sol
TestHarness.LocalRequestFactory lrf = h.getRequestFactory("standard", 0,
10, args);
+
SolrQueryRequest request = lrf.makeRequest("test");
SolrHighlighter highlighter = request.getCore().getHighlighter();
List<String> highlightFieldNames = Arrays.asList(highlighter
@@ -710,6 +711,7 @@ public class HighlighterTest extends Sol
highlightFieldNames.contains("text"));
assertFalse("Expected to not highlight on field \"weight\"",
highlightFieldNames.contains("weight"));
+ request.close();
args.put("hl.fl", "foo_*");
lrf = h.getRequestFactory("standard", 0, 10, args);
@@ -721,6 +723,7 @@ public class HighlighterTest extends Sol
.size());
assertEquals("Expected to highlight on field \"foo_s\"", "foo_s",
highlightFieldNames.get(0));
+ request.close();
}
@Test
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/JSONWriterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/JSONWriterTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/JSONWriterTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/JSONWriterTest.java Wed Oct 20 12:44:28 2010
@@ -65,7 +65,7 @@ public class JSONWriterTest extends Solr
buf = new StringWriter();
w.write(buf, req, rsp);
assertEquals(buf.toString(), "{\"data1\":\"NaN\",\"data2\":\"-Infinity\",\"data3\":\"Infinity\"}");
-
+ req.close();
}
@Test
@@ -80,6 +80,7 @@ public class JSONWriterTest extends Solr
rsp.add("data3", true);
w.write(buf, req, rsp);
assertEquals(buf.toString(), "a:3:{s:5:\"data1\";s:5:\"hello\";s:5:\"data2\";i:42;s:5:\"data3\";b:1;}");
+ req.close();
}
@Test
@@ -96,7 +97,7 @@ public class JSONWriterTest extends Solr
w.write(buf, req, rsp);
assertEquals(buf.toString(), "{\"nl\":[[\"data1\",\"hello\"],[null,42]]}");
-
+ req.close();
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/SimpleFacetsTest.java Wed Oct 20 12:44:28 2010
@@ -94,7 +94,8 @@ public class SimpleFacetsTest extends So
add_doc("id", "47",
"range_facet_f", "28.62",
"trait_s", "Pig",
- "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!");
+ "text", "line up and fly directly at the enemy death cannons, clogging them with wreckage!",
+ "zerolen_s","");
}
@Test
@@ -300,6 +301,16 @@ public class SimpleFacetsTest extends So
,"//int[2][@name='Obnoxious'][.='1']"
,"//int[3][@name='Tool'][.='2']"
);
+
+
+ assertQ(req("q", "id:[42 TO 47]"
+ ,"facet", "true"
+ ,"facet.method","fc"
+ ,"fq", "id:[42 TO 45]"
+ ,"facet.field", "zerolen_s"
+ )
+ ,"*[count(//lst[@name='zerolen_s']/int)=1]"
+ );
}
public static void indexDateFacets() {
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/TestBinaryResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/TestBinaryResponseWriter.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/TestBinaryResponseWriter.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/request/TestBinaryResponseWriter.java Wed Oct 20 12:44:28 2010
@@ -65,5 +65,7 @@ public class TestBinaryResponseWriter ex
assertEquals("Returned object must be a string", "java.lang.String", document.getFieldValue("uuid").getClass().getName());
assertEquals("Wrong UUID string returned", s, document.getFieldValue("uuid"));
}
+
+ req.close();
}
}
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/response/TestCSVResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/response/TestCSVResponseWriter.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/response/TestCSVResponseWriter.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/response/TestCSVResponseWriter.java Wed Oct 20 12:44:28 2010
@@ -160,6 +160,8 @@ public class TestCSVResponseWriter exten
w.write(buf, req, rsp);
String s = buf.toString();
assertTrue(s.indexOf("score") >=0 && s.indexOf("2.718") > 0 && s.indexOf("89.83") > 0 );
+
+ req.close();
}
}
\ No newline at end of file
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/LegacyDateFieldTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/LegacyDateFieldTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/LegacyDateFieldTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/LegacyDateFieldTest.java Wed Oct 20 12:44:28 2010
@@ -19,16 +19,12 @@ package org.apache.solr.schema;
import org.apache.solr.schema.DateField;
import org.apache.solr.util.DateMathParser;
-import org.apache.lucene.document.Fieldable;
import org.apache.lucene.util.LuceneTestCase;
-import org.junit.runner.RunWith;
import java.util.Date;
import java.util.TimeZone;
import java.util.Locale;
-import java.text.DateFormat;
-@RunWith(LuceneTestCase.LocalizedTestCaseRunner.class)
public class LegacyDateFieldTest extends LuceneTestCase {
// if and when this class is removed, make sure to refactor all
// appropriate code to DateFieldTest
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/NotRequiredUniqueKeyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/NotRequiredUniqueKeyTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/NotRequiredUniqueKeyTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/schema/NotRequiredUniqueKeyTest.java Wed Oct 20 12:44:28 2010
@@ -17,9 +17,12 @@
package org.apache.solr.schema;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.core.SolrCore;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.util.AbstractSolrTestCase;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* This is a simple test to make sure the unique key is not required
@@ -27,22 +30,14 @@ import org.apache.solr.util.AbstractSolr
*
* It needs its own file so it can load a special schema file
*/
-public class NotRequiredUniqueKeyTest extends AbstractSolrTestCase {
+public class NotRequiredUniqueKeyTest extends SolrTestCaseJ4 {
- @Override public String getSchemaFile() { return "schema-not-required-unique-key.xml"; }
- @Override public String getSolrConfigFile() { return "solrconfig.xml"; }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
+ @BeforeClass
+ public static void beforeTests() throws Exception {
+ initCore("solrconfig.xml","schema-not-required-unique-key.xml");
}
-
+ @Test
public void testSchemaLoading()
{
SolrCore core = h.getCore();
Modified: lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/QueryParsingTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/QueryParsingTest.java?rev=1025539&r1=1025538&r2=1025539&view=diff
==============================================================================
--- lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/QueryParsingTest.java (original)
+++ lucene/dev/branches/docvalues/solr/src/test/org/apache/solr/search/QueryParsingTest.java Wed Oct 20 12:44:28 2010
@@ -146,6 +146,7 @@ public class QueryParsingTest extends So
sort = QueryParsing.parseSort("", req);
assertNull(sort);
+ req.close();
}
@Test
@@ -194,6 +195,7 @@ public class QueryParsingTest extends So
} catch (SolrException e) {
}
+ req.close();
}
}