简体   繁体   中英

Solr Rest API issue - Java

I have created new Rest API using solr 6.5 . Please find below steps 1. Custom Search Handler with query parameter

<requestHandler name="/select" class="com.test.solr.TestSearchHandler" default="true">
<lst name="defaults">
  <str name="wt">json</str>
  <str name="indent">true</str>
  <str name="fl">test1,test2</str>
  <str name="df">acSearch</str>
  <str name="sort">score desc</str>
</lst>
<arr name="components">
  <str>query</str>
</arr>

Custom class has below impmenetaion

   private ModifiableSolrParams createNewSolrParams(SolrQueryRequest request) {
    SolrParams oldParams = request.getParams();
    ModifiableSolrParams newParams = new ModifiableSolrParams(oldParams);
    setUpQueryExpression(newParams, oldParams);
    return newParams;
}


private void setUpQueryExpression(ModifiableSolrParams newParams, SolrParams oldParams) {
    String query = oldParams.get("query");
    newParams.remove("query");
    newParams.set(CommonParams.Q, query);
}

Its working for below url i am getting response

http://localhost:8330/autocomplete-service/core_autocomplete/select?query=test1:Airport *

But not working for below url

http://localhost:8330/nghp-autocomplete-service/nghp_autocomplete/select?query=Airport *

How to avoid key value pair in query

Working query=test1:Airport* Needed query=Airport*

Search is happening for word not for Phrase. Example Airport is searching Airport India is now working.

Please let me know how to fix.

Under your request handler, you're setting the default query to acSearch:

<str name="df">acSearch</str>

The handler will only search with that field in mind. I would get rid of this line entirely so that your request handler will have the full-text searching ability.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM