Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solrj with Solr Suggester

Tags:

java

solr

solrj

What is the correct way of getting results from solrj using Solr Suggester?

This is my request:

SolrQuery query = new SolrQuery();
query.setRequestHandler("/suggest");
query.setParam("suggest", "true");
query.setParam("suggest.build", "true");
query.setParam("suggest.dictionary", "mySuggester");
query.setParam("suggest.q", "So");
QueryResponse response = server.query(query);

However I found it extremely difficult to get the response. The way I got the response is with this:

NamedList obj = (NamedList)((Map)response.getResponse().get("suggest")).get("mySuggester");
SimpleOrderedMap obj2 = (SimpleOrderedMap) obj.get("So");
List<SimpleOrderedMap> obj3 = (List<SimpleOrderedMap>) obj2.get("suggestions");

This seems to assume a lot about the objects I am getting from the response and will be difficult to anticipate errors.

Is there a better and cleaner way than this?

like image 432
Ammar Avatar asked Feb 12 '15 19:02

Ammar


People also ask

What is SOLR suggester?

Solr has a "suggester" component called SuggestComponent. You use this component to give users automatic suggestions for query terms. For example, you create a text box that has an autocomplete feature and suggested terms appear as a user types a query term in the text box.

What version of Lucene does SOLR use?

Solr is the popular, blazing-fast, open source enterprise search platform built on Apache Lucene™.

What is the API library for SOLR search?

Solr uses the Lucene Java search library at its core for full-text indexing and search, and has REST-like JSON APIs that make it easy to use from virtually any programming language.

Is Solr open-source search engine?

Solr is a leading open source search engine from the Apache Software Foundation's Lucene project. Thanks to its flexibility, scalability, and cost-effectiveness, Solr is widely used by large and small enterprises. What is Elasticsearch?


1 Answers

In new versions have a SuggesterResponse:

https://lucene.apache.org/solr/5_3_1/solr-solrj/org/apache/solr/client/solrj/response/SuggesterResponse.html

like image 90
oniram Avatar answered Sep 19 '22 21:09

oniram