use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestExternalFeatures method testFeaturesUseStopwordQueryReturnEmptyFeatureVector.
@Test
public void testFeaturesUseStopwordQueryReturnEmptyFeatureVector() throws Exception {
final SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.add("fl", "*,score,fv:[fv]");
query.add("rows", "1");
// Stopword only query passed in
query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query='a' efi.userTitlePhrase1='b' efi.userTitlePhrase2='c'}");
final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector("matchedTitle", "0.0", "titlePhraseMatch", "0.0", "titlePhrasesMatch", "0.0");
final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();
final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);
// Features are query title matches, which remove stopwords, leaving blank query, so no matches
assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestEmbeddedSolrServerConstructors method testNodeConfigConstructor.
@Test
public void testNodeConfigConstructor() throws Exception {
Path path = createTempDir();
SolrResourceLoader loader = new SolrResourceLoader(path);
NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader).setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString()).build();
try (EmbeddedSolrServer server = new EmbeddedSolrServer(config, "newcore")) {
CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
createRequest.setCoreName("newcore");
createRequest.setConfigSet("minimal");
server.request(createRequest);
SolrInputDocument doc = new SolrInputDocument();
doc.addField("articleid", "test");
server.add("newcore", doc);
server.commit();
assertEquals(1, server.query(new SolrQuery("*:*")).getResults().getNumFound());
assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound());
}
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class AbstractCloudBackupRestoreTestCase method getShardToDocCountMap.
private Map<String, Integer> getShardToDocCountMap(CloudSolrClient client, DocCollection docCollection) throws SolrServerException, IOException {
Map<String, Integer> shardToDocCount = new TreeMap<>();
for (Slice slice : docCollection.getActiveSlices()) {
String shardName = slice.getName();
try (HttpSolrClient leaderClient = new HttpSolrClient.Builder(slice.getLeader().getCoreUrl()).withHttpClient(client.getHttpClient()).build()) {
long docsInShard = leaderClient.query(new SolrQuery("*:*").setParam("distrib", "false")).getResults().getNumFound();
shardToDocCount.put(shardName, (int) docsInShard);
}
}
return shardToDocCount;
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestTolerantSearch method testGetTopIdsPhaseError.
@SuppressWarnings("unchecked")
public void testGetTopIdsPhaseError() throws SolrServerException, IOException {
BadResponseWriter.failOnGetTopIds = true;
BadResponseWriter.failOnGetFields = false;
SolrQuery query = new SolrQuery();
query.setQuery("subject:batman OR subject:superman");
query.addField("id");
query.addField("subject");
query.set("distrib", "true");
query.set("shards", shard1 + "," + shard2);
query.set(ShardParams.SHARDS_INFO, "true");
query.set("debug", "true");
query.set("stats", "true");
query.set("stats.field", "id");
query.set("mlt", "true");
query.set("mlt.fl", "title");
query.set("mlt.count", "1");
query.set("mlt.mintf", "0");
query.set("mlt.mindf", "0");
query.setHighlight(true);
query.addFacetField("id");
query.setFacet(true);
ignoreException("Dummy exception in BadResponseWriter");
try {
collection1.query(query);
fail("Should get an exception");
} catch (Exception e) {
//expected
}
query.set(ShardParams.SHARDS_TOLERANT, "true");
QueryResponse response = collection1.query(query);
assertTrue(response.getResponseHeader().getBooleanArg(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
NamedList<Object> shardsInfo = ((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
boolean foundError = false;
for (int i = 0; i < shardsInfo.size(); i++) {
if (shardsInfo.getName(i).contains("collection2")) {
assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
foundError = true;
break;
}
}
assertTrue(foundError);
assertEquals(1, response.getResults().get(0).getFieldValue("id"));
assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
unIgnoreException("Dummy exception in BadResponseWriter");
}
use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.
the class TestTolerantSearch method testGetFieldsPhaseError.
@SuppressWarnings("unchecked")
public void testGetFieldsPhaseError() throws SolrServerException, IOException {
BadResponseWriter.failOnGetFields = true;
BadResponseWriter.failOnGetTopIds = false;
SolrQuery query = new SolrQuery();
query.setQuery("subject:batman OR subject:superman");
query.addField("id");
query.addField("subject");
query.set("distrib", "true");
query.set("shards", shard1 + "," + shard2);
query.set(ShardParams.SHARDS_INFO, "true");
query.set("debug", "true");
query.set("stats", "true");
query.set("stats.field", "id");
query.set("mlt", "true");
query.set("mlt.fl", "title");
query.set("mlt.count", "1");
query.set("mlt.mintf", "0");
query.set("mlt.mindf", "0");
query.setHighlight(true);
query.addFacetField("id");
query.setFacet(true);
ignoreException("Dummy exception in BadResponseWriter");
try {
collection1.query(query);
fail("Should get an exception");
} catch (Exception e) {
//expected
}
query.set(ShardParams.SHARDS_TOLERANT, "true");
QueryResponse response = collection1.query(query);
assertTrue(response.getResponseHeader().getBooleanArg(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
NamedList<Object> shardsInfo = ((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
boolean foundError = false;
for (int i = 0; i < shardsInfo.size(); i++) {
if (shardsInfo.getName(i).contains("collection2")) {
assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
foundError = true;
break;
}
}
assertTrue(foundError);
assertEquals(1, response.getResults().get(0).getFieldValue("id"));
assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
unIgnoreException("Dummy exception in BadResponseWriter");
}
Aggregations