Search in sources :

Example 66 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class RuntimeLibSearchComponent method prepare.

@Override
public void prepare(ResponseBuilder rb) throws IOException {
    SolrParams params = rb.req.getParams();
    if (params.getBool(COMPONENT_NAME, true)) {
        rb.rsp.add(COMPONENT_NAME, RuntimeLibSearchComponent.class.getName());
        rb.rsp.add("loader", getClass().getClassLoader().getClass().getName());
        rb.rsp.add("Version", "2");
    }
    super.process(rb);
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams)

Example 67 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestExtendedDismaxParser method testAutoGeneratePhraseQueries.

public void testAutoGeneratePhraseQueries() throws Exception {
    ModifiableSolrParams noSowParams = new ModifiableSolrParams();
    noSowParams.add("df", "text");
    ModifiableSolrParams sowFalseParams = new ModifiableSolrParams();
    sowFalseParams.add("sow", "false");
    sowFalseParams.add("df", "text");
    ModifiableSolrParams sowTrueParams = new ModifiableSolrParams();
    sowTrueParams.add("sow", "true");
    sowTrueParams.add("df", "text");
    for (SolrParams params : Arrays.asList(noSowParams, sowFalseParams)) {
        try (SolrQueryRequest req = req(params)) {
            // "text" has autoGeneratePhraseQueries="true"
            QParser qParser = QParser.getParser("text:grackle", "edismax", req);
            Query q = qParser.getQuery();
            assertEquals("+(text:\"crow blackbird\" text:grackl)", q.toString());
        }
    }
    try (SolrQueryRequest req = req(sowTrueParams)) {
        QParser qParser = QParser.getParser("text:grackle", "edismax", req);
        Query q = qParser.getQuery();
        assertEquals("+spanOr([spanNear([text:crow, text:blackbird], 0, true), text:grackl])", q.toString());
    }
    for (SolrParams params : Arrays.asList(noSowParams, sowTrueParams, sowFalseParams)) {
        try (SolrQueryRequest req = req(params)) {
            // "text_sw" doesn't specify autoGeneratePhraseQueries => default false
            QParser qParser = QParser.getParser("text_sw:grackle", "edismax", req);
            Query q = qParser.getQuery();
            assertEquals("+((+text_sw:crow +text_sw:blackbird) text_sw:grackl)", q.toString());
        }
    }
    Stream.of(noSowParams, sowTrueParams, sowFalseParams).forEach(p -> p.add("qf", "text text_sw"));
    for (SolrParams params : Arrays.asList(noSowParams, sowFalseParams)) {
        try (SolrQueryRequest req = req(params)) {
            QParser qParser = QParser.getParser("grackle", "edismax", req);
            Query q = qParser.getQuery();
            assertEquals("+((text:\"crow blackbird\" text:grackl)" + " | ((+text_sw:crow +text_sw:blackbird) text_sw:grackl))", q.toString());
            qParser = QParser.getParser("grackle wi fi", "edismax", req);
            q = qParser.getQuery();
            assertEquals("+(((text:\"crow blackbird\" text:grackl) text:wifi)" + " | (((+text_sw:crow +text_sw:blackbird) text_sw:grackl) text_sw:wifi))", q.toString());
        }
    }
    try (SolrQueryRequest req = req(sowTrueParams)) {
        QParser qParser = QParser.getParser("grackle", "edismax", req);
        Query q = qParser.getQuery();
        assertEquals("+(spanOr([spanNear([text:crow, text:blackbird], 0, true), text:grackl])" + " | ((+text_sw:crow +text_sw:blackbird) text_sw:grackl))", q.toString());
        qParser = QParser.getParser("grackle wi fi", "edismax", req);
        q = qParser.getQuery();
        assertEquals("+((spanOr([spanNear([text:crow, text:blackbird], 0, true), text:grackl])" + " | ((+text_sw:crow +text_sw:blackbird) text_sw:grackl)) (text:wi | text_sw:wi) (text:fi | text_sw:fi))", q.toString());
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Query(org.apache.lucene.search.Query) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) DisjunctionMaxQuery(org.apache.lucene.search.DisjunctionMaxQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 68 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestFiltering method testHossssSanity.

public void testHossssSanity() throws Exception {
    clearIndex();
    SolrParams match_0 = params("q", "{!frange v=val_i l=0 u=1}", "fq", "{!frange v=val_i l=1 u=1}", "fq", "{!frange v=val_i l=0 u=1}", "fq", "-_query_:\"{!frange v=val_i l=1 u=1}\"", "fq", "-_query_:\"{!frange v=val_i l=0 u=1}\"");
    SolrParams match_1 = params("q", "{!frange v=val_i l=0 u=1}", "fq", "{!frange v=val_i l=0 u=1}", "fq", "{!frange v=val_i l=0 u=1}", "fq", "-_query_:\"{!frange v=val_i l=1 u=1}\"", "fq", "-_query_:\"{!frange v=val_i l=1 u=1}\"");
    final int numDocs = 10;
    for (int i = 0; i < numDocs; i++) {
        String val = Integer.toString(i);
        assertU(adoc("id", val, f, val));
    }
    assertU(commit());
    // sanity check
    assertJQ(req("q", "*:*"), "/response/numFound==" + numDocs);
    // 1 then 0
    assertJQ(req(match_1), "/response/numFound==1");
    assertJQ(req(match_0), "/response/numFound==0");
    // clear caches
    assertU(commit());
    // 0 then 1
    assertJQ(req(match_0), "/response/numFound==0");
    assertJQ(req(match_1), "/response/numFound==1");
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams)

Example 69 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestPseudoReturnFields method testAugmentersGlobsExplicitAndScoreOhMy.

public void testAugmentersGlobsExplicitAndScoreOhMy() throws Exception {
    Random random = random();
    // NOTE: 'ssto' is the missing one
    final List<String> fl = Arrays.asList("id", "[docid]", "[explain]", "score", "val_*", "subj*");
    final int iters = atLeast(random, 10);
    for (int i = 0; i < iters; i++) {
        Collections.shuffle(fl, random);
        final SolrParams singleFl = params("q", "*:*", "rows", "1", "fl", StringUtils.join(fl.toArray(), ','));
        final ModifiableSolrParams multiFl = params("q", "*:*", "rows", "1");
        for (String item : fl) {
            multiFl.add("fl", item);
        }
        for (SolrParams p : Arrays.asList(singleFl, multiFl)) {
            assertQ(p.toString(), req(p), "//result[@numFound='5']", "//result/doc/str[@name='id']", "//result/doc/float[@name='score']", "//result/doc/str[@name='subject']", "//result/doc/int[@name='val_i']", "//result/doc/int[@name='[docid]']", "//result/doc/str[@name='[explain]']", "//result/doc[count(*)=6]");
        }
    }
}
Also used : Random(java.util.Random) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 70 with SolrParams

use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.

the class TestPseudoReturnFields method testAugmentersGlobsExplicitAndScoreOhMyRTG.

public void testAugmentersGlobsExplicitAndScoreOhMyRTG() throws Exception {
    Random random = random();
    // NOTE: 'ssto' is the missing one
    final List<String> fl = Arrays.asList("id", "[explain]", "score", "val_*", "subj*", "abs(val_i)", "[docid]");
    final int iters = atLeast(random, 10);
    for (int i = 0; i < iters; i++) {
        Collections.shuffle(fl, random);
        final SolrParams singleFl = params("fl", StringUtils.join(fl.toArray(), ','));
        final ModifiableSolrParams multiFl = params();
        for (String item : fl) {
            multiFl.add("fl", item);
        }
        // RTG behavior should be consistent, (committed or otherwise) 
        for (String id : Arrays.asList("42", "99")) {
            for (SolrParams p : Arrays.asList(singleFl, multiFl)) {
                assertQ(id + ": " + p, req(p, "qt", "/get", "id", id, "wt", "xml"), "count(//doc)=1", "//doc/str[@name='id']", "//doc/int[@name='[docid]'][.>=-1]", "//doc/float[@name='abs(val_i)'][.='1.0']", // RTG: [explain] and score should be missing (ignored)
                "//doc/int[@name='val_i'][.=1]", "//doc/str[@name='subject']", "//doc[count(*)=5]");
            }
        }
    }
}
Also used : Random(java.util.Random) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

SolrParams (org.apache.solr.common.params.SolrParams)310 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)179 SolrException (org.apache.solr.common.SolrException)78 Test (org.junit.Test)45 Tuple (org.apache.solr.client.solrj.io.Tuple)43 SolrDocument (org.apache.solr.common.SolrDocument)42 ArrayList (java.util.ArrayList)41 NamedList (org.apache.solr.common.util.NamedList)40 MapSolrParams (org.apache.solr.common.params.MapSolrParams)37 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)37 IOException (java.io.IOException)35 SolrDocumentList (org.apache.solr.common.SolrDocumentList)34 HashMap (java.util.HashMap)33 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)30 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)27 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)26 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)24 Map (java.util.Map)22 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)22 SolrCore (org.apache.solr.core.SolrCore)20