Solrj: how to specify the path

I am trying to use TermsComponent to implement autosuggest using Solrj, but I do not see how to specify the path (i.e. /terms part of http://localhost:8983/solr/terms ).

How can I indicate the path using Solrj?

Bonus: is there a way to specify multiple fields for the terms.fl parameter?

thanks

+4
source share
3 answers

Here we go:

  SolrQuery query = new SolrQuery(); query.setParam(CommonParams.QT, "/terms"); query.setParam(TermsParams.TERMS, true); query.setParam(TermsParams.TERMS_LIMIT, "10"); query.setParam(TermsParams.TERMS_FIELD, "title", "description"); // or whatever fields you want query.setParam(TermsParams.TERMS_PREFIX_STR, typedInput); 

This assumes that you have Conditions that are connected to "/ terms"; there is a default solrconfig.xml file.

And for a bonus: you can add multiple fields by simply adding multiple lines for TERMS_FIELD (or multiple URLs &terms.fl=foo params).

Thanks to Mauricio for pointing me in the right direction.

+4
source

Direct support for TermComponent is not available in SolrJ 1.4.1, but look at the corresponding patch , it is quite easy to implement it yourself.

Since TermComponent is a standard component, you do not need to use / terms, you can bind it to standard request handlers .

+2
source

I spend so much time working with the Terms.

At the end of the day, I realized that there is another set of commands that you need to invoke in order to get the results from the requestHandler request / terms.

I tried to get the results using

 HttpSolrServer server = new HttpSolrServ(solrUrl); List<SolrDocument> list = server.query(query).getResults() 

However, the right way to get results from TermComponent is

 HttpSolrServer server = new HttpSolrServ(solrUrl); TermsResponse termResp = server.query(query).getTermsResponse(); List<Term> tList = termResp.getTerms("fieldNAME"); 

I hope this can help someone else in the future.

+2
source

Source: https://habr.com/ru/post/1340860/


All Articles