Search in sources :

Example 91 with LocalSolrQueryRequest

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']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 92 with LocalSolrQueryRequest

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']");
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 93 with LocalSolrQueryRequest

use of org.apache.solr.request.LocalSolrQueryRequest in project lucene-solr by apache.

the class IndexSchemaTest method testDynamicCopy.

/**
   * This test assumes the schema includes:
   * &lt;dynamicField name="dynamic_*" type="string" indexed="true" stored="true"/&gt;
   * &lt;dynamicField name="*_dynamic" type="string" indexed="true" stored="true"/&gt;
   */
@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();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) SolrCore(org.apache.solr.core.SolrCore) Test(org.junit.Test)

Example 94 with LocalSolrQueryRequest

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();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 95 with LocalSolrQueryRequest

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();
    }
}
Also used : Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) HashMap(java.util.HashMap) NamedList(org.apache.solr.common.util.NamedList) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrDocument(org.apache.solr.common.SolrDocument) Sort(org.apache.lucene.search.Sort) SolrDocumentList(org.apache.solr.common.SolrDocumentList) DocList(org.apache.solr.search.DocList) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) DocList(org.apache.solr.search.DocList)

Aggregations

LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)107 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)61 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)49 SolrCore (org.apache.solr.core.SolrCore)47 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 Test (org.junit.Test)41 HashMap (java.util.HashMap)32 NamedList (org.apache.solr.common.util.NamedList)26 ArrayList (java.util.ArrayList)23 MapSolrParams (org.apache.solr.common.params.MapSolrParams)21 SolrException (org.apache.solr.common.SolrException)18 List (java.util.List)15 LinkedHashMap (java.util.LinkedHashMap)11 SolrParams (org.apache.solr.common.params.SolrParams)10 SearchComponent (org.apache.solr.handler.component.SearchComponent)10 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)10 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)10 Map (java.util.Map)9 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)9 IOException (java.io.IOException)8