Search in sources :

Example 76 with ModifiableSolrParams

use of org.apache.solr.common.params.ModifiableSolrParams 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 77 with ModifiableSolrParams

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

the class TestHashQParserPlugin method testHashPartition.

@Test
public void testHashPartition() throws Exception {
    Random random = random();
    HashSet<String> set = new HashSet();
    for (int i = 0; i < 50; i++) {
        int v = random.nextInt(1000000);
        String val = Integer.toString(v);
        if (!set.contains(val)) {
            set.add(val);
            String[] doc = { "id", val, "a_s", val, "a_i", val, "a_l", val };
            assertU(adoc(doc));
            if (i % 10 == 0)
                assertU(commit());
        }
    }
    assertU(commit());
    //Test with 3 worker and String hash ID.
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=0 workers=3 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_s");
    params.add("rows", "50");
    HashSet set1 = new HashSet();
    String response = h.query(req(params));
    Iterator<String> it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set1.add(s);
        }
    }
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=1 workers=3 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_s");
    params.add("rows", "50");
    HashSet set2 = new HashSet();
    response = h.query(req(params));
    it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set2.add(s);
        }
    }
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=2 workers=3 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_s");
    params.add("rows", "50");
    HashSet set3 = new HashSet();
    response = h.query(req(params));
    it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set3.add(s);
        }
    }
    assert (set1.size() > 0);
    assert (set2.size() > 0);
    assert (set3.size() > 0);
    assert (set1.size() + set2.size() + set3.size() == set.size());
    assertNoOverLap(set1, set2);
    assertNoOverLap(set1, set3);
    assertNoOverLap(set2, set3);
    //Test with 2 workers and int partition Key
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=0 workers=2 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_i");
    params.add("rows", "50");
    set1 = new HashSet();
    response = h.query(req(params));
    it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set1.add(s);
        }
    }
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=1 workers=2 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_i");
    params.add("rows", "50");
    set2 = new HashSet();
    response = h.query(req(params));
    it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set2.add(s);
        }
    }
    assert (set1.size() > 0);
    assert (set2.size() > 0);
    assert (set1.size() + set2.size() == set.size());
    assertNoOverLap(set1, set2);
    //Test with 2 workers and compound partition Key
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=0 workers=2 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_s,       a_i,      a_l");
    params.add("rows", "50");
    set1 = new HashSet();
    response = h.query(req(params));
    it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set1.add(s);
        }
    }
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!hash worker=1 workers=2 cost=" + getCost(random) + "}");
    params.add("partitionKeys", "a_s, a_i, a_l");
    params.add("rows", "50");
    set2 = new HashSet();
    response = h.query(req(params));
    it = set.iterator();
    while (it.hasNext()) {
        String s = it.next();
        String results = h.validateXPath(response, "*[count(//int[@name='id'][.='" + s + "'])=1]");
        if (results == null) {
            set2.add(s);
        }
    }
    assert (set1.size() > 0);
    assert (set2.size() > 0);
    assert (set1.size() + set2.size() == set.size());
    assertNoOverLap(set1, set2);
}
Also used : Random(java.util.Random) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 78 with ModifiableSolrParams

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

the class TestReRankQParserPlugin method testRerankQueryParsingShouldFailWithoutMandatoryReRankQueryParameter.

@Test
public void testRerankQueryParsingShouldFailWithoutMandatoryReRankQueryParameter() throws Exception {
    assertU(delQ("*:*"));
    assertU(commit());
    String[] doc = { "id", "1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc));
    assertU(commit());
    String[] doc1 = { "id", "2", "term_s", "YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc1));
    assertU(commit());
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=200}");
    params.add("q", "term_s:YYYY");
    params.add("start", "0");
    params.add("rows", "2");
    try {
        h.query(req(params));
        fail("A syntax error should be thrown when " + ReRankQParserPlugin.RERANK_QUERY + " parameter is not specified");
    } catch (SolrException e) {
        assertTrue(e.code() == SolrException.ErrorCode.BAD_REQUEST.code);
    }
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 79 with ModifiableSolrParams

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

the class TestReRankQParserPlugin method testReRankQueries.

@Test
public void testReRankQueries() throws Exception {
    assertU(delQ("*:*"));
    assertU(commit());
    String[] doc = { "id", "1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc));
    assertU(commit());
    String[] doc1 = { "id", "2", "term_s", "YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc1));
    String[] doc2 = { "id", "3", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc2));
    assertU(commit());
    String[] doc3 = { "id", "4", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000" };
    assertU(adoc(doc3));
    String[] doc4 = { "id", "5", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc4));
    assertU(commit());
    String[] doc5 = { "id", "6", "term_s", "YYYY", "group_s", "group2", "test_ti", "10", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc5));
    assertU(commit());
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=200}");
    params.add("q", "term_s:YYYY");
    params.add("rqq", "{!edismax bf=$bff}*:*");
    params.add("bff", "field(test_ti)");
    params.add("start", "0");
    params.add("rows", "6");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='3.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']", "//result/doc[5]/float[@name='id'][.='1.0']", "//result/doc[6]/float[@name='id'][.='5.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with sort by score.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("sort", "score desc");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with compound sort.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("sort", "score desc,test_ti asc");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with elevation
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=50}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "1");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='2.0']", "//result/doc[3]/float[@name='id'][.='6.0']", "//result/doc[4]/float[@name='id'][.='5.0']", "//result/doc[5]/float[@name='id'][.='4.0']", "//result/doc[6]/float[@name='id'][.='3.0']");
    //Test TermQuery rqq
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test Elevation
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "1,4");
    assertQ(req(params), "*[count(//doc)=6]", //Elevated
    "//result/doc[1]/float[@name='id'][.='1.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='4.0']", //Boosted during rerank.
    "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']", "//result/doc[5]/float[@name='id'][.='5.0']", "//result/doc[6]/float[@name='id'][.='3.0']");
    //Test Elevation swapped
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=6]", //Elevated
    "//result/doc[1]/float[@name='id'][.='4.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='1.0']", //Boosted during rerank.
    "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']", "//result/doc[5]/float[@name='id'][.='5.0']", "//result/doc[6]/float[@name='id'][.='3.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=4 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=6]", //Elevated
    "//result/doc[1]/float[@name='id'][.='4.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='1.0']", "//result/doc[3]/float[@name='id'][.='6.0']", "//result/doc[4]/float[@name='id'][.='5.0']", "//result/doc[5]/float[@name='id'][.='3.0']", //Not in reRankeDocs
    "//result/doc[6]/float[@name='id'][.='2.0']");
    //Test Elevation with start beyond the rerank docs
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='3.0']", //Was not in reRankDocs
    "//result/doc[2]/float[@name='id'][.='2.0']");
    //Test Elevation with zero results
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}nada");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=0]");
    //Pass in reRankDocs lower then the length being collected.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=1 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=0 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=2 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:4^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test reRankWeight of 0, reranking will have no effect.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=0}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "5");
    assertQ(req(params), "*[count(//doc)=5]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']");
    MetricsMap metrics = (MetricsMap) h.getCore().getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.queryResultCache");
    Map<String, Object> stats = metrics.getValue();
    long inserts = (Long) stats.get("inserts");
    assertTrue(inserts > 0);
    //Test range query
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "test_ti:[0 TO 2000]");
    params.add("rqq", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "6");
    assertQ(req(params), "*[count(//doc)=5]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='2.0']", "//result/doc[5]/float[@name='id'][.='1.0']");
    stats = metrics.getValue();
    long inserts1 = (Long) stats.get("inserts");
    //Last query was added to the cache
    assertTrue(inserts1 > inserts);
    //Run same query and see if it was cached. This tests the query result cache hit with rewritten queries
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "test_ti:[0 TO 2000]");
    params.add("rqq", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "6");
    assertQ(req(params), "*[count(//doc)=5]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='2.0']", "//result/doc[5]/float[@name='id'][.='1.0']");
    stats = metrics.getValue();
    long inserts2 = (Long) stats.get("inserts");
    //Last query was NOT added to the cache
    assertTrue(inserts1 == inserts2);
    //Test range query embedded in larger query
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    // function query for predictible scores (relative to id) independent of similarity
    params.add("q", "{!func}id");
    // constant score for each clause (unique per doc) for predictible scores independent of similarity
    // NOTE: biased in favor of doc id == 2
    params.add("rqq", "id:1^=10 id:2^=40 id:3^=30 id:4^=40 id:5^=50 id:6^=60");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "6");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", // reranked out of orig order
    "//result/doc[4]/float[@name='id'][.='2.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with start beyond reRankDocs
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "id:1^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "5");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
    //Test ReRankDocs > docs returned
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50");
    params.add("rqq", "id:1^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "1");
    assertQ(req(params), "*[count(//doc)=1]", "//result/doc[1]/float[@name='id'][.='1.0']");
    //Test with zero results
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "term_s:NNNN");
    params.add("rqq", "id:1^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "5");
    assertQ(req(params), "*[count(//doc)=0]");
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 80 with ModifiableSolrParams

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

the class TestReRankQParserPlugin method testOverRank.

@Test
public void testOverRank() throws Exception {
    assertU(delQ("*:*"));
    assertU(commit());
    //Test the scenario that where we rank more documents then we return.
    String[] doc = { "id", "1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc));
    String[] doc1 = { "id", "2", "term_s", "YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc1));
    String[] doc2 = { "id", "3", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc2));
    String[] doc3 = { "id", "4", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000" };
    assertU(adoc(doc3));
    String[] doc4 = { "id", "5", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc4));
    String[] doc5 = { "id", "6", "term_s", "YYYY", "group_s", "group2", "test_ti", "10", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc5));
    String[] doc6 = { "id", "7", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc6));
    String[] doc7 = { "id", "8", "term_s", "YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc7));
    String[] doc8 = { "id", "9", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc8));
    String[] doc9 = { "id", "10", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000" };
    assertU(adoc(doc9));
    String[] doc10 = { "id", "11", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc10));
    assertU(commit());
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=11 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60 id:7^70 id:8^80 id:9^90 id:10^100 id:11^110");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "2");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='8.0']", "//result/doc[2]/float[@name='id'][.='2.0']");
    //Test Elevation
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=11 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60 id:7^70 id:8^80 id:9^90 id:10^100 id:11^110");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "3");
    params.add("qt", "/elevate");
    params.add("elevateIds", "1,4");
    assertQ(req(params), "*[count(//doc)=3]", //Elevated
    "//result/doc[1]/float[@name='id'][.='1.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='4.0']", //Boosted during rerank.
    "//result/doc[3]/float[@name='id'][.='8.0']");
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Aggregations

ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)524 Test (org.junit.Test)168 ArrayList (java.util.ArrayList)87 NamedList (org.apache.solr.common.util.NamedList)76 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)74 SolrException (org.apache.solr.common.SolrException)68 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)66 HashMap (java.util.HashMap)61 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)58 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)57 List (java.util.List)56 IOException (java.io.IOException)55 Map (java.util.Map)52 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)52 SolrInputDocument (org.apache.solr.common.SolrInputDocument)51 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)48 Tuple (org.apache.solr.client.solrj.io.Tuple)47 SolrParams (org.apache.solr.common.params.SolrParams)42 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 SolrRequest (org.apache.solr.client.solrj.SolrRequest)36