将 Solr 的TermsComponent 中的术语限制为源自某些文档的术语

发布于 2024-10-21 03:07:54 字数 1392 浏览 1 评论 0原文

我正在使用 SolrsTermsComponent 来实现自动完成功能。我的文档包含我在“标签”字段中索引的标签。现在我可以使用TermsComponent 找出所有存储的文档中使用了哪些标签。到目前为止,这效果很好。

然而,还有一些额外的要求:每个文档都有一个所有者字段,其中包含拥有该文档的用户的 ID。自动完成列表应仅包含请求自动完成的用户实际拥有的文档中的标签。

我尝试设置查询参数,但是这似乎被TermsComponent忽略了:

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;
}

那么有没有办法限制TermsComponent返回的标签,或者我是否必须手动查询用户的所有标签并自己过滤它们?

I am using Solrs TermsComponent to implement an autocomplete feature. My documents contain tags which I have indexed in a "tags" field. Now I can use TermsComponent to find out which tags are used in all the stored documents. This works pretty well so far.

However there is some additional requirement: Every document has an owner field which contains the ID of the user who owns it. The autocomplete list should only contain tags from documents, that the user who is requesting the autocomplete is actually owning.

I have tried to set the query parameter, however this seems to be ignored by the TermsComponent:

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 of limiting the tags returned by TermsComponent, or do I manually have to query all the tags of the user and filter them myself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不吻晚风 2024-10-28 03:07:54

根据 这个那个 在 Solr 邮件列表上发帖,无法对术语组件进行过滤,因为它对原始索引数据进行操作。

显然,Solr 开发人员正在开发一个支持过滤的真正的自动建议组件

根据您的要求,您可能可以使用 分面自动完成组件而不是术语组件。它完全支持过滤查询,以将符合条件的标签集减少到索引中文档的子集。

According to this and that post on the Solr mailing list, filtering on the terms component is not possible because it operates on raw index data.

Apparently, the Solr developers are working on a real autosuggest component that supports your filtering.

Depending on your requirements you might be able to use the faceting component for autocomplete instead of the terms component. It fully supports filter queries for reducing the set of eligible tags to a subset of the documents in the index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文