Limiting conditions in the Solr Terms. In accordance with the conditions arising from certain documents

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?

+7
source share
1 answer

According to this, and which posted a mailing list on Solr, filtering on the term component is not possible because it works with raw index data.

Solr developers seem to be working on a real autosuggest component that supports your filtering.

Depending on your requirements, you can use the facet component to autocomplete instead of the term components. It fully supports filter queries to reduce the set of matching tags by a subset of the documents in the index.

+7
source

All Articles