Search in sources :

Example 21 with SolrQuery

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

the class TestExternalFeatures method featureExtraction_valueFeatureImplicitlyNotRequired_shouldNotScoreFeature.

@Test
public void featureExtraction_valueFeatureImplicitlyNotRequired_shouldNotScoreFeature() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("rows", "1");
    final String docs0fvalias_dense_csv = FeatureLoggerTestUtils.toFeatureVector("occurrences", "0.0", "originalScore", "0.0");
    final String docs0fvalias_sparse_csv = FeatureLoggerTestUtils.toFeatureVector("originalScore", "0.0");
    final String docs0fvalias_default_csv = chooseDefaultFeatureVector(docs0fvalias_dense_csv, docs0fvalias_sparse_csv);
    // Efi is explicitly not required, so we do not score the feature
    query.remove("fl");
    query.add("fl", "fvalias:[fv store=fstore3]");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='" + docs0fvalias_default_csv + "'");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 22 with SolrQuery

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

the class TestExternalFeatures method testEfiInTransformerShouldNotChangeOrderOfRerankedResults.

@Test
public void testEfiInTransformerShouldNotChangeOrderOfRerankedResults() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("fl", "*,score");
    query.add("rows", "3");
    // Regular scores
    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=='2'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==1.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/id=='3'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==1.0");
    query.remove("fl");
    query.add("fl", "*,score,[fv]");
    query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query=w3 efi.userTitlePhrase1=w4 efi.userTitlePhrase2=w5}");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='3'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.7693934");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==0.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==0.0");
    // Adding an efi in the transformer should not affect the rq ranking with a
    // different value for efi of the same parameter
    query.remove("fl");
    query.add("fl", "*,score,[fv efi.user_query=w2 efi.userTitlePhrase1=w4 efi.userTitlePhrase2=w5]");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='3'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==0.7693934");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[1]/score==0.0");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[2]/score==0.0");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 23 with SolrQuery

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

the class TestExternalFeatures method featureExtraction_valueFeatureExplicitlyNotRequired_shouldNotScoreFeature.

@Test
public void featureExtraction_valueFeatureExplicitlyNotRequired_shouldNotScoreFeature() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("rows", "1");
    final String docs0fvalias_dense_csv = FeatureLoggerTestUtils.toFeatureVector("occurrences", "0.0", "originalScore", "0.0");
    final String docs0fvalias_sparse_csv = FeatureLoggerTestUtils.toFeatureVector("originalScore", "0.0");
    final String docs0fvalias_default_csv = chooseDefaultFeatureVector(docs0fvalias_dense_csv, docs0fvalias_sparse_csv);
    // Efi is explicitly not required, so we do not score the feature
    query.remove("fl");
    query.add("fl", "fvalias:[fv store=fstore3]");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fvalias=='" + docs0fvalias_default_csv + "'");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 24 with SolrQuery

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

the class TestExternalFeatures method featureExtraction_valueFeatureRequired_shouldThrowException.

@Test
public void featureExtraction_valueFeatureRequired_shouldThrowException() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("rows", "1");
    // Using nondefault store should still result in error with no efi when it is required (myPop)
    query.remove("fl");
    query.add("fl", "fvalias:[fv store=fstore4]");
    assertJQ("/query" + query.toQueryString(), "/error/msg=='Exception from createWeight for ValueFeature [name=popularity, params={value=${myPop}, required=true}] ValueFeatureWeight requires efi parameter that was not passed in request.'");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 25 with SolrQuery

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

the class TestExternalValueFeatures method efiFeatureProcessing_oneEfiMissing_shouldNotCalculateMissingFeature.

@Test
public void efiFeatureProcessing_oneEfiMissing_shouldNotCalculateMissingFeature() throws Exception {
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("fl", "*,score,features:[fv]");
    query.add("rows", "3");
    query.add("rq", "{!ltr reRankDocs=3 model=external_model_binary_feature efi.user_device_tablet=1}");
    final String docs0features_dense_csv = FeatureLoggerTestUtils.toFeatureVector("user_device_smartphone", "0.0", "user_device_tablet", "1.0");
    final String docs0features_sparse_csv = FeatureLoggerTestUtils.toFeatureVector("user_device_tablet", "1.0");
    final String docs0features_default_csv = chooseDefaultFeatureVector(docs0features_dense_csv, docs0features_sparse_csv);
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/id=='1'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/features=='" + docs0features_default_csv + "'");
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/score==65.0");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Aggregations

SolrQuery (org.apache.solr.client.solrj.SolrQuery)327 Test (org.junit.Test)174 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)129 SolrServerException (org.apache.solr.client.solrj.SolrServerException)53 SolrInputDocument (org.apache.solr.common.SolrInputDocument)52 SolrDocument (org.apache.solr.common.SolrDocument)47 ArrayList (java.util.ArrayList)46 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)45 IOException (java.io.IOException)36 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)33 SolrDocumentList (org.apache.solr.common.SolrDocumentList)33 SolrClient (org.apache.solr.client.solrj.SolrClient)27 LinearModel (org.apache.solr.ltr.model.LinearModel)24 Map (java.util.Map)23 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 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 SolrException (org.apache.solr.common.SolrException)18