我将数据保存在solr中:
String solrUrl = "http://localhost:8984/solr";
SolrServer solrServer = new HttpSolrServer( solrUrl );
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "1");
doc.addField("first_name", "Ann");
doc.addField("last_name", "Smit");
doc.addField("email", "[email protected]");
try {
solrServer.add(doc);
solrServer.commit();
} catch (SolrServerException e) {/* */}
然后从solr中选择数据:
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.addFilterQuery("first_name:Ann*");
query.addFilterQuery("last_name:Ann*");
query.setFields("id","first_name","last_name","email");
QueryResponse response = null;
try {
response = solrServer.query(query);
} catch (SolrServerException e) {/* */ }
SolrDocumentList list = response.getResults();
我有搜索条件:名字或姓氏应包含值
Ann
。如何为选择的保存数据设置FilterQuery
? 最佳答案
应使用:
SolrQuery parameters = new SolrQuery();
query.setQuery("first_name:qwe2 OR last_name:qwe2");
query.setFields("id","first_name","last_name","email");
QueryResponse response = null;
try {
response = solrServer.query(parameters);
} catch (SolrServerException e) {/* */ }
SolrDocumentList list = response.getResults();
关于java - 如何使用Java从Solr中选择?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27012774/