I use Solrs TermsComponent to implement autocomplete function. My documents contain tags that I indexed in the tags field. Now I can use the TermsComponent to find out which tags are used in all saved documents. This is still very good.
However, there are some additional requirements: each document has an owner field that contains the identifier of the user to whom it belongs. The autocomplete list should only contain tags from documents that are actually owned by the user who requests autocomplete.
I tried to set the query parameter, however this is apparently ignored by the term Component:
public static List<String> findUniqueTags(String beginningWith, User owner) throws IOException { SolrParams q = new SolrQuery().setQueryType("/terms") .setQuery("owner:" + owner.id.toString()) .set(TermsParams.TERMS, true).set(TermsParams.TERMS_FIELD, "tags") .set(TermsParams.TERMS_LOWER, beginningWith) .set(TermsParams.TERMS_LOWER_INCLUSIVE, false) .set(TermsParams.TERMS_PREFIX_STR, beginningWith); QueryResponse queryResponse; try { queryResponse = getSolrServer().query(q); } catch (SolrServerException e) { Logger.error(e, "Error when querying server."); throw new IOException(e); } NamedList tags = (NamedList) ((NamedList)queryResponse.getResponse().get("terms")).get("tags"); List<String> result = new ArrayList<String>(); for (Iterator iterator = tags.iterator(); iterator.hasNext();) { Map.Entry tag = (Map.Entry) iterator.next(); result.add(tag.getKey().toString()); } return result; }
So, is there a way to limit the tags returned by TermComponent, or do I have to manually request all user tags and filter them myself?
Jan ThomΓ€
source share