Search code examples
autocompletesolrautosuggestsolrj

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


Solution

  • 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.