use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class CopyFieldTest method testSourceGlobMatchesNoDynamicOrExplicitField.
@Test
public void testSourceGlobMatchesNoDynamicOrExplicitField() {
// SOLR-4650: copyField source globs should not have to match an explicit or dynamic field
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertNull("'testing123_*' should not be (or match) a dynamic or explicit field", schema.getFieldOrNull("testing123_*"));
assertTrue("schema should contain dynamic field '*_s'", schema.getDynamicPattern("*_s").equals("*_s"));
assertU(adoc("id", "5", "sku1", "10-1839ACX-93", "testing123_s", "AAM46"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "text:AAM46");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku2 copied to text", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']");
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class CopyFieldTest method testExplicitSourceGlob.
@Test
public void testExplicitSourceGlob() {
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
assertTrue("schema should contain explicit field 'sku1'", schema.getFields().containsKey("sku1"));
assertTrue("schema should contain explicit field 'sku2'", schema.getFields().containsKey("sku2"));
assertNull("'sku*' should not be (or match) a dynamic field", schema.getDynamicPattern("sku*"));
assertTrue("schema should contain dynamic field '*_s'", schema.getDynamicPattern("*_s").equals("*_s"));
final String subsetPattern = "*_dest_sub_s";
final String dynamicPattern1 = schema.getDynamicPattern(subsetPattern);
assertTrue("'" + subsetPattern + "' should match dynamic field '*_s', but instead matches '" + dynamicPattern1 + "'", dynamicPattern1.equals("*_s"));
final String dest_sub_no_ast_s = "dest_sub_no_ast_s";
// Should not be an explicit field
assertFalse(schema.getFields().containsKey(dest_sub_no_ast_s));
final String dynamicPattern2 = schema.getDynamicPattern(dest_sub_no_ast_s);
assertTrue("'" + dest_sub_no_ast_s + "' should match dynamic field '*_s', but instead matches '" + dynamicPattern2 + "'", dynamicPattern2.equals("*_s"));
assertU(adoc("id", "5", "sku1", "10-1839ACX-93", "sku2", "AAM46"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "text:AAM46");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku2 copied to text", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']");
args = new HashMap<>();
args.put(CommonParams.Q, "1_s:10-1839ACX-93");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku1 copied to dynamic dest *_s", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='5']", "//result/doc[1]/arr[@name='sku1']/str[.='10-1839ACX-93']");
args = new HashMap<>();
args.put(CommonParams.Q, "1_dest_sub_s:10-1839ACX-93");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku1 copied to *_dest_sub_s (*_s subset pattern)", req, "//*[@numFound='1']");
args = new HashMap<>();
args.put(CommonParams.Q, "dest_sub_no_ast_s:AAM46");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("sku2 copied to dest_sub_no_ast_s (*_s subset pattern no asterisk)", req, "//*[@numFound='1']");
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class IndexSchemaTest method testDynamicCopy.
/**
* This test assumes the schema includes:
* <dynamicField name="dynamic_*" type="string" indexed="true" stored="true"/>
* <dynamicField name="*_dynamic" type="string" indexed="true" stored="true"/>
*/
@Test
public void testDynamicCopy() {
SolrCore core = h.getCore();
assertU(adoc("id", "10", "title", "test", "aaa_dynamic", "aaa"));
assertU(commit());
Map<String, String> args = new HashMap<>();
args.put(CommonParams.Q, "title:test");
args.put("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("Make sure they got in", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
args = new HashMap<>();
args.put(CommonParams.Q, "aaa_dynamic:aaa");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic source", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
args = new HashMap<>();
args.put(CommonParams.Q, "dynamic_aaa:aaa");
args.put("indent", "true");
req = new LocalSolrQueryRequest(core, new MapSolrParams(args));
assertQ("dynamic destination", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
clearIndex();
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class IndexSchemaRuntimeFieldTest method testRuntimeFieldCreation.
@Test
public void testRuntimeFieldCreation() {
// any field manipulation needs to happen when you know the core will not
// be accepting any requests. Typically this is done within the inform()
// method. Since this is a single threaded test, we can change the fields
// willi-nilly
SolrCore core = h.getCore();
IndexSchema schema = core.getLatestSchema();
final String fieldName = "runtimefield";
SchemaField sf = new SchemaField(fieldName, schema.getFieldTypes().get("string"));
schema.getFields().put(fieldName, sf);
// also register a new copy field (from our new field)
schema.registerCopyField(fieldName, "dynamic_runtime");
schema.refreshAnalyzers();
assertU(adoc("id", "10", "title", "test", fieldName, "aaa"));
assertU(commit());
SolrQuery query = new SolrQuery(fieldName + ":aaa");
query.set("indent", "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, query);
assertQ("Make sure they got in", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
// Check to see if our copy field made it out safely
query.setQuery("dynamic_runtime:aaa");
assertQ("Make sure they got in", req, "//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='10']");
clearIndex();
}
use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.
the class CarrotClusteringEngineTest method checkEngine.
private List<NamedList<Object>> checkEngine(CarrotClusteringEngine engine, int expectedNumDocs, int expectedNumClusters, Query query, SolrParams clusteringParams) throws IOException {
// Get all documents to cluster
RefCounted<SolrIndexSearcher> ref = h.getCore().getSearcher();
DocList docList;
try {
SolrIndexSearcher searcher = ref.get();
docList = searcher.getDocList(query, (Query) null, new Sort(), 0, numberOfDocs);
assertEquals("docList size", expectedNumDocs, docList.matches());
ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.add(clusteringParams);
// Perform clustering
LocalSolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), solrParams);
Map<SolrDocument, Integer> docIds = new HashMap<>(docList.size());
SolrDocumentList solrDocList = ClusteringComponent.docListToSolrDocumentList(docList, searcher, engine.getFieldsToLoad(req), docIds);
@SuppressWarnings("unchecked") List<NamedList<Object>> results = (List<NamedList<Object>>) engine.cluster(query, solrDocList, docIds, req);
req.close();
assertEquals("number of clusters: " + results, expectedNumClusters, results.size());
checkClusters(results, false);
return results;
} finally {
ref.decref();
}
}
Aggregations