use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestOriginalScoreFeature method implTestOriginalScoreResponseDocsCheck.
public static void implTestOriginalScoreResponseDocsCheck(String modelName, String origScoreFeatureName, String nonScoringFeatureName, String nonScoringFeatureValue) throws Exception {
final SolrQuery query = new SolrQuery();
query.setQuery("title:w1");
query.add("fl", "*, score");
query.add("rows", "4");
query.add("wt", "json");
final int doc0Id = 1;
final int doc1Id = 8;
final int doc2Id = 6;
final int doc3Id = 7;
assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='" + doc0Id + "'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='" + doc1Id + "'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='" + doc2Id + "'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='" + doc3Id + "'");
final String res = restTestHarness.query("/query" + query.toQueryString());
final Map<String, Object> jsonParse = (Map<String, Object>) ObjectBuilder.fromJSON(res);
final String doc0Score = ((Double) ((Map<String, Object>) ((ArrayList<Object>) ((Map<String, Object>) jsonParse.get("response")).get("docs")).get(0)).get("score")).toString();
final String doc1Score = ((Double) ((Map<String, Object>) ((ArrayList<Object>) ((Map<String, Object>) jsonParse.get("response")).get("docs")).get(1)).get("score")).toString();
final String doc2Score = ((Double) ((Map<String, Object>) ((ArrayList<Object>) ((Map<String, Object>) jsonParse.get("response")).get("docs")).get(2)).get("score")).toString();
final String doc3Score = ((Double) ((Map<String, Object>) ((ArrayList<Object>) ((Map<String, Object>) jsonParse.get("response")).get("docs")).get(3)).get("score")).toString();
final boolean debugQuery = random().nextBoolean();
if (debugQuery) {
query.add(CommonParams.DEBUG_QUERY, "true");
}
query.remove("fl");
query.add("fl", "*, score, fv:[fv]");
query.add("rq", "{!ltr model=" + modelName + " reRankDocs=4}");
assertJQ("/query" + query.toQueryString(), "/response/numFound/==4");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='" + doc0Id + "'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='" + doc1Id + "'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='" + doc2Id + "'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='" + doc3Id + "'");
implTestOriginalScoreResponseDocsCheck(modelName, query, 0, doc0Id, origScoreFeatureName, doc0Score, nonScoringFeatureName, nonScoringFeatureValue, debugQuery);
implTestOriginalScoreResponseDocsCheck(modelName, query, 1, doc1Id, origScoreFeatureName, doc1Score, nonScoringFeatureName, nonScoringFeatureValue, debugQuery);
implTestOriginalScoreResponseDocsCheck(modelName, query, 2, doc2Id, origScoreFeatureName, doc2Score, nonScoringFeatureName, nonScoringFeatureValue, debugQuery);
implTestOriginalScoreResponseDocsCheck(modelName, query, 3, doc3Id, origScoreFeatureName, doc3Score, nonScoringFeatureName, nonScoringFeatureValue, debugQuery);
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestLTRWithFacet method testRankingSolrFacet.
@Test
public void testRankingSolrFacet() throws Exception {
// before();
loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), "{\"q\":\"{!func}pow(popularity,2)\"}");
loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), new String[] { "powpularityS" }, "{\"weights\":{\"powpularityS\":1.0}}");
final SolrQuery query = new SolrQuery();
query.setQuery("title:a1");
query.add("fl", "*, score");
query.add("rows", "4");
query.add("facet", "true");
query.add("facet.field", "description");
assertJQ("/query" + query.toQueryString(), "/response/numFound/==8");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='2'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='4'");
// Normal term match
assertJQ("/query" + query.toQueryString(), "" + "/facet_counts/facet_fields/description==" + "['b', 4, 'e', 2, 'c', 1, 'd', 1]");
query.add("rq", "{!ltr model=powpularityS-model reRankDocs=4}");
query.set("debugQuery", "on");
assertJQ("/query" + query.toQueryString(), "/response/numFound/==8");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='4'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==16.0");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='3'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==9.0");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='2'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==4.0");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='1'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==1.0");
assertJQ("/query" + query.toQueryString(), "" + "/facet_counts/facet_fields/description==" + "['b', 4, 'e', 2, 'c', 1, 'd', 1]");
// aftertest();
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestLTRWithSort method testRankingSolrSort.
@Test
public void testRankingSolrSort() throws Exception {
// before();
loadFeature("powpularityS", SolrFeature.class.getCanonicalName(), "{\"q\":\"{!func}pow(popularity,2)\"}");
loadModel("powpularityS-model", LinearModel.class.getCanonicalName(), new String[] { "powpularityS" }, "{\"weights\":{\"powpularityS\":1.0}}");
final SolrQuery query = new SolrQuery();
query.setQuery("title:a1");
query.add("fl", "*, score");
query.add("rows", "4");
// Normal term match
assertJQ("/query" + query.toQueryString(), "/response/numFound/==8");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='2'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='4'");
//Add sort
query.add("sort", "description desc");
assertJQ("/query" + query.toQueryString(), "/response/numFound/==8");
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='5'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='8'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='7'");
query.add("rq", "{!ltr model=powpularityS-model reRankDocs=4}");
query.set("debugQuery", "on");
assertJQ("/query" + query.toQueryString(), "/response/numFound/==8");
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=='5'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==25.0");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/id=='1'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[3]/score==1.0");
// aftertest();
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestParallelWeightCreation method testLTRScoringQueryParallelWeightCreationResultOrder.
@Test
public void testLTRScoringQueryParallelWeightCreationResultOrder() throws Exception {
setuptest("solrconfig-ltr_Th10_10.xml", "schema.xml");
assertU(adoc("id", "1", "title", "w1 w3", "description", "w1", "popularity", "1"));
assertU(adoc("id", "2", "title", "w2", "description", "w2", "popularity", "2"));
assertU(adoc("id", "3", "title", "w3", "description", "w3", "popularity", "3"));
assertU(adoc("id", "4", "title", "w3 w3", "description", "w4", "popularity", "4"));
assertU(adoc("id", "5", "title", "w5", "description", "w5", "popularity", "5"));
assertU(commit());
loadFeatures("external_features.json");
loadModels("external_model.json");
// check to make sure that the order of results will be the same when using parallel weight creation
final SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.add("fl", "*,score");
query.add("rows", "4");
query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3}");
// SOLR-10710, feature based on query with term w3 now scores higher on doc 4, updated
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='4'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/id=='3'");
assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='1'");
aftertest();
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestLTRQParserExplain method multipleAdditiveTreesScoreExplainMissingEfiFeatureShouldReturnDefaultScore.
@Test
public void multipleAdditiveTreesScoreExplainMissingEfiFeatureShouldReturnDefaultScore() throws Exception {
loadFeatures("external_features_for_sparse_processing.json");
loadModels("multipleadditivetreesmodel_external_binary_features.json");
SolrQuery query = new SolrQuery();
query.setQuery("title:bloomberg");
query.setParam("debugQuery", "on");
query.add("rows", "4");
query.add("rq", "{!ltr reRankDocs=4 model=external_model_binary_feature efi.user_device_tablet=1}");
query.add("fl", "*,score");
final String tree1 = "(weight=1.0,root=(feature=user_device_smartphone,threshold=0.5,left=0.0,right=50.0))";
final String tree2 = "(weight=1.0,root=(feature=user_device_tablet,threshold=0.5,left=0.0,right=65.0))";
final String trees = "[" + tree1 + "," + tree2 + "]";
query.add("wt", "json");
assertJQ("/query" + query.toQueryString(), "/debug/explain/7=='\n" + "65.0 = MultipleAdditiveTreesModel(name=external_model_binary_feature,trees=" + trees + ") model applied to features, sum of:\n" + " 0.0 = tree 0 | \\'user_device_smartphone\\':0.0 <= 0.500001, Go Left | val: 0.0\n" + " 65.0 = tree 1 | \\'user_device_tablet\\':1.0 > 0.500001, Go Right | val: 65.0\n'}");
assertJQ("/query" + query.toQueryString(), "/debug/explain/9=='\n" + "65.0 = MultipleAdditiveTreesModel(name=external_model_binary_feature,trees=" + trees + ") model applied to features, sum of:\n" + " 0.0 = tree 0 | \\'user_device_smartphone\\':0.0 <= 0.500001, Go Left | val: 0.0\n" + " 65.0 = tree 1 | \\'user_device_tablet\\':1.0 > 0.500001, Go Right | val: 65.0\n'}");
}
Aggregations