我需要在solrj
中实现此查询&sort=query($manu_sort,0) desc, query($manu_service_sort,0) desc, query($seller_sort,0) desc, _s_name asc, sku asc &manu_sort=ManufacturerName:"Service Champ" &manu_service_sort=ManufacturerName:"SERVICE CHAMP" &seller_sort=BestSeller:true
当我直接添加到代码
时 customSort = "&sort=query($manu_sort,0) desc, query($manu_service_sort,0) desc, query($seller_sort,0) desc, _s_name asc, sku asc &manu_sort=ManufacturerName:"Service Champ" &manu_service_sort=ManufacturerName:"SERVICE CHAMP" &seller_sort=BestSeller:true";
queryQ = queryQ+customSort;
solrQuery.setQuery(queryQ);
QueryResponse e = this.provider.get(this).query(solrQuery, METHOD.POST);
这会引发错误
no field name specified in query and no default specified via 'df' param
任何人都可以帮助吗?
我无法获取您的查询...但是可以建议一个可能对您有帮助的示例代码。
String solrUrl = "http://localhost:8983/solr/";
HttpSolrClient httpSolrClient = new HttpSolrClient.Builder(solrUrl).build();
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.set("defType","edismax");
//query.set("qf","file_name^10 content_text^1");
query.addFilterQuery("name : abcdef");
//sorting & direction
query.addSort("Name_of_field_For_sorting", SolrQuery.ORDER.desc);
// set the debug
//query.set("debug", "true");
//for faceting
//query.setFacet(true);
//query.addFacetField("name_of_the_Field")
//query.setFacetLimit(10);
//set the fields
query.setFields(new String[] {"id", "name"});
// for highlighting
query.setHighlight(true);
query.addHighlightField("Name_of_field_to_be_Highlighted");
query.addHighlightField("content_text");
query.setHighlightSimplePre("<hlt>");
query.setHighlightSimplePost("</hlt>");
query.setHighlight(true).setHighlightSnippets(2);
query.setHighlightFragsize(150);
query.setStart(0);
query.setRows(10);
QueryResponse response = httpSolrClient.query(query);
SolrDocumentList results = response.getResults();
//iterate the results
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
另一种尝试可能是下面的。
SolrQuery query = new SolrQuery();
String nested = "";
nested += "Field_name:";
nested += "Field_Value";
nested += " AND _query_:"{!dismax qf=Field_name1=";
nested += "Field_Value1";
nested += "}"";
query.setQuery(nested);
String fieldList = "id,name,category";
query.set("fl", fieldList);
QueryResponse response = httpSolrClient.query(query);