Search in sources :

Example 96 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestValueFeature method testValueFeatureRequiredShouldReturn400StatusCode.

@Test
public void testValueFeatureRequiredShouldReturn400StatusCode() throws Exception {
    loadFeature("c8", ValueFeature.class.getCanonicalName(), "c8", "{\"value\":\"${val8}\",\"required\":true}");
    loadModel("m8", LinearModel.class.getCanonicalName(), new String[] { "c8" }, "c8", "{\"weights\":{\"c8\":1.0}}");
    final SolrQuery query = new SolrQuery();
    query.setQuery("title:w1");
    query.add("fl", "*, score,fvonly:[fvonly]");
    query.add("rows", "4");
    query.add("wt", "json");
    query.add("rq", "{!ltr model=m8 reRankDocs=4}");
    assertJQ("/query" + query.toQueryString(), "/responseHeader/status==400");
}
Also used : LinearModel(org.apache.solr.ltr.model.LinearModel) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 97 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestMultipleAdditiveTreesModel method multipleAdditiveTreesTestExplain.

@Ignore
@Test
public void multipleAdditiveTreesTestExplain() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("fl", "*,score,[fv]");
    query.add("rows", "3");
    query.add("rq", "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=w3}");
    // test out the explain feature, make sure it returns something
    query.setParam("debugQuery", "on");
    String qryResult = JQ("/query" + query.toQueryString());
    qryResult = qryResult.replaceAll("\n", " ");
    assertThat(qryResult, containsString("\"debug\":{"));
    qryResult = qryResult.substring(qryResult.indexOf("debug"));
    assertThat(qryResult, containsString("\"explain\":{"));
    qryResult = qryResult.substring(qryResult.indexOf("explain"));
    assertThat(qryResult, containsString("multipleadditivetreesmodel"));
    assertThat(qryResult, containsString(MultipleAdditiveTreesModel.class.getCanonicalName()));
    assertThat(qryResult, containsString("-100.0 = tree 0"));
    assertThat(qryResult, containsString("50.0 = tree 0"));
    assertThat(qryResult, containsString("-20.0 = tree 1"));
    assertThat(qryResult, containsString("'matchedTitle':1.0 > 0.5"));
    assertThat(qryResult, containsString("'matchedTitle':0.0 <= 0.5"));
    assertThat(qryResult, containsString(" Go Right "));
    assertThat(qryResult, containsString(" Go Left "));
    assertThat(qryResult, containsString("'this_feature_doesnt_exist' does not exist in FV"));
}
Also used : StringContains.containsString(org.junit.internal.matchers.StringContains.containsString) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 98 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestMultipleAdditiveTreesModel method testMultipleAdditiveTreesScoringWithAndWithoutEfiFeatureMatches.

@Test
public void testMultipleAdditiveTreesScoringWithAndWithoutEfiFeatureMatches() throws Exception {
    loadFeatures("multipleadditivetreesmodel_features.json");
    loadModels("multipleadditivetreesmodel.json");
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("rows", "3");
    query.add("fl", "*,score");
    // Regular scores
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==1.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==1.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==1.0");
    // No match scores since user_query not passed in to external feature info
    // and feature depended on it.
    query.add("rq", "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=dsjkafljjk}");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==-120.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==-120.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==-120.0");
    // Matched user query since it was passed in
    query.remove("rq");
    query.add("rq", "{!ltr reRankDocs=3 model=multipleadditivetreesmodel efi.user_query=w3}");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='3'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==30.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==-120.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==-120.0");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 99 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestRankingFeature method testRankingSolrFeature.

@Test
public void testRankingSolrFeature() throws Exception {
    // before();
    loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), "{\"q\":\"{!func}pow(popularity,2)\"}");
    loadFeature("unpopularityS", SolrFeature.class.getCanonicalName(), "{\"q\":\"{!func}div(1,popularity)\"}");
    loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), new String[] { "powpularityS" }, "{\"weights\":{\"powpularityS\":1.0}}");
    loadModel("unpopularityS-model", LinearModel.class.getCanonicalName(), new String[] { "unpopularityS" }, "{\"weights\":{\"unpopularityS\":1.0}}");
    final SolrQuery query = new SolrQuery();
    query.setQuery("title:w1");
    query.add("fl", "*, score");
    query.add("rows", "4");
    assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='8'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='6'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='7'");
    // Normal term match
    query.add("rq", "{!ltr model=powpularityS-model reRankDocs=4}");
    query.set("debugQuery", "on");
    assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='8'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==64.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='7'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==49.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='6'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==36.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='1'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==1.0");
    query.remove("rq");
    query.add("rq", "{!ltr model=unpopularityS-model reRankDocs=4}");
    assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==1.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='6'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='7'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='8'");
    //bad solr ranking feature
    loadFeature("powdesS", SolrFeature.class.getCanonicalName(), "{\"q\":\"{!func}pow(description,2)\"}");
    loadModel("powdesS-model", LinearModel.class.getCanonicalName(), new String[] { "powdesS" }, "{\"weights\":{\"powdesS\":1.0}}");
    query.remove("rq");
    query.add("rq", "{!ltr model=powdesS-model reRankDocs=4}");
    assertJQ("/query" + query.toQueryString(), "/error/msg/=='" + FeatureException.class.getCanonicalName() + ": " + "java.lang.UnsupportedOperationException: " + "Unable to extract feature for powdesS'");
// aftertest();
}
Also used : LinearModel(org.apache.solr.ltr.model.LinearModel) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 100 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestUserTermScoreWithQ method testUserTermScoreWithQ.

@Test
public void testUserTermScoreWithQ() throws Exception {
    // before();
    loadFeature("SomeTermQ", SolrFeature.class.getCanonicalName(), "{\"q\":\"{!terms f=popularity}88888\"}");
    loadModel("Term-modelQ", LinearModel.class.getCanonicalName(), new String[] { "SomeTermQ" }, "{\"weights\":{\"SomeTermQ\":1.0}}");
    final SolrQuery query = new SolrQuery();
    query.setQuery("title:w1");
    query.add("fl", "*, score");
    query.add("rows", "4");
    query.add("rq", "{!ltr model=Term-modelQ reRankDocs=4}");
    query.set("debugQuery", "on");
    assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==0.0");
}
Also used : LinearModel(org.apache.solr.ltr.model.LinearModel) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Aggregations

SolrQuery (org.apache.solr.client.solrj.SolrQuery)316 Test (org.junit.Test)174 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)123 SolrInputDocument (org.apache.solr.common.SolrInputDocument)52 SolrServerException (org.apache.solr.client.solrj.SolrServerException)50 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)45 SolrDocument (org.apache.solr.common.SolrDocument)45 ArrayList (java.util.ArrayList)44 IOException (java.io.IOException)33 SolrDocumentList (org.apache.solr.common.SolrDocumentList)33 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)32 SolrClient (org.apache.solr.client.solrj.SolrClient)27 LinearModel (org.apache.solr.ltr.model.LinearModel)24 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)23 Replica (org.apache.solr.common.cloud.Replica)23 Slice (org.apache.solr.common.cloud.Slice)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)21 Map (java.util.Map)20 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 SolrException (org.apache.solr.common.SolrException)18