【问题标题】:Apache Solr query not working properlyApache Solr 查询无法正常工作
【发布时间】:2017-05-03 19:47:11
【问题描述】:

查询不能使用HttpSolrClient.query(core, query)

核心:apparel-Product

查询:q=autosuggest_en:cap&qt=/suggest&spellcheck.dictionary=en&spellcheck.q=cap

回复:{responseHeader={status=0,QTime=1},spellcheck={suggestions={},collations={}}}

但是相同的查询从 URL 中获取结果

http://localhost:8983/solr/apparel-Product/select?indent=on&q=autosuggest_en:cap&qt=/suggest&spellcheck.dictionary=en&spellcheck.q=cap&wt=json

【问题讨论】:

  • 您使用的是哪个版本的 solrj?

标签: java solr


【解决方案1】:

你的意思是你正在传递一个像

这样的字符串
q=autosuggest_en:cap&qt=/suggest&spellcheck.dictionary=en&spellcheck.q=cap

在查询对象中?您不能这样做,您需要单独设置其他参数(qt、拼写检查等)。

this method 为例,四处寻找一些示例。

【讨论】:

    【解决方案2】:

    您不能将 Solr 查询参数传递给 SolrQuery 对象,将它们连接起来,因为它们在查询字符串中,请使用 SolrQuery 对象方法。

    这个例子应该符合你的要求:

    SolrClient client = new HttpSolrClient("http://my-solr-server:8983/solr");
    
    SolrQuery solrQuery = new SolrQuery();
    
    solrQuery.setQuery("utosuggest_en:cap"); // q parameter
    solrQuery.setRequestHandler("/suggest"); // qt parameter
    solrQuery.setParam("spellcheck.dictionary", "en"); // spellcheck.dictionary parameter
    solrQuery.setParam("spellcheck.q", "cap"); // spellcheck.dictionary parameter
    
    client.query("apparel-Product", solrQuery)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      • 2016-12-01
      • 2013-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多