首页 > 解决方案 > solrj 设置查询字段

问题描述

我正在使用以下有效的 solr 查询

https://host:port/solr/ref_cm/select?defType=edismax&q=abc&qf=a+b+c+d

我可以知道如何使用 solrj 进行设置。我在下面尝试了“qf”,但它不起作用(即使从 url 它可以工作)

final Map<String, String> queryParamMap = new HashMap<String, String>();

queryParamMap.put("q", query);
queryParamMap.put("defType", "edismax");
queryParamMap.put("qf","a, b, c, d");

感谢任何指针

标签: javasolrsolrj

解决方案


You can try below part of the code. it should work for you.

The code queryParamMap.put("qf", "a b c d") would work instead of queryParamMap.put("qf","a, b, c, d").

The full code would be something like below.

ModifiableSolrParams queryParamMap= new ModifiableSolrParams();
queryParamMap.set("q", "test");
queryParamMap.set("defType", "edismax");
queryParamMap.set("qf", "a b c d");
QueryResponse qResp = cloudSolrClient.query(queryParamMap);
SolrDocumentList docList = qResp.getResults();
int numFound = (int) docList.getNumFound();

推荐阅读