Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solrj: how to specify path

I'm trying to use the TermsComponent to implement autosuggest with Solrj, but I don't see how to specify the path (i.e. the /terms portion of http://localhost:8983/solr/terms).

How can I specify the path using Solrj?

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

Thanks

like image 810
George Armhold Avatar asked Feb 25 '23 00:02

George Armhold


1 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 is assuming that you have the TermsComponent wired in at "/terms"; the default solrconfig.xml has it there.

And for the bonus: you can add multiple fields simply by adding multiple strings for TERMS_FIELD (or multiple URL &terms.fl=foo params).

Thank you Mauricio, for pointing me in the right direction.

like image 71
George Armhold Avatar answered Mar 03 '23 02:03

George Armhold