从列表中识别文档中是否存在关键字

发布于 2025-01-04 17:40:26 字数 301 浏览 1 评论 0原文

我想根据预先确定的列表为 Lucene 文档创建标签列表。

因此,如果我们有一个文档,其文本为

寻找具有 Lucene 经验的 Java 程序员

并且我们有关键字列表(大约 1000 项)

java、php、lucene、c# [.. .]

我想识别文档中存在关键字Java和Lucene。 仅执行 java OR php OR lucene 是行不通的,因为那样我将不知道哪个关键字生成了命中。

关于如何在 Lucene 中实现这一点有什么建议吗?

I want to create a tag list for a Lucene document based on a pre-determined list.

So, if we have a document with the text

Looking for a Java programmer with experience in Lucene

and we have the keyword list (about 1000 items)

java, php, lucene, c# [...]

I want to identify that the keywords Java and Lucene exist in the document.
Just doing a java OR php OR lucene will not work because then I will not know which keyword generated the hit.

Any suggestions on how to implement this in Lucene?

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

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

发布评论

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

评论(2

梦里人 2025-01-11 17:40:26

我假设您有一个或多个索引字段,并且您希望根据关键字与文档的索引术语的交集来构建标签云。

您的问题与突出显示非常相似,因此相同的想法适用,您可以:

  • 重新分析 Lucene 文档的存储字段,
  • 使用 术语矢量,用于快速访问文档的存储字段。

请注意,如果要使用术语向量,则需要在编译时启用它们(请参阅 Field.TermVector.YES 文档字段构造函数)。

I assume that you have one or more indexed fields, and you want to build your tag cloud based on the intersection of your keywords and the indexed terms for a document.

Your problem is very similar to highlighting, so the same ideas apply, you can either:

  • re-analyze the stored fields of your Lucene document,
  • use term vectors for fast access to your documents' stored fields.

Note that if you want to use term vectors, you need to enable them at compile time (see Field.TermVector.YES documentation and Field constructor).

从来不烧饼 2025-01-11 17:40:26

是的,这有效

FullTextSession fts = Search.getFullTextSession(getSessionFactory().getCurrentSession());

Query q = fts.getSearchFactory().buildQueryBuilder()
    .forEntity(Offer.class).get()
    .keyword()
    .onField("id")
    .matching(myId)
    .createQuery();
Object[] dId = (Object[]) fts.createFullTextQuery(q, Offer.class)
    .setProjection(ProjectionConstants.DOCUMENT_ID)
    .uniqueResult();

if(dId != null){

    IndexReader indexReader = fts.getSearchFactory().getIndexReaderAccessor().open(Offer.class);

    TermFreqVector freq = indexReader.getTermFreqVector((Integer) dId[0], "description");

}

您必须记住在该字段的休眠搜索注释中使用 TermVector.YES 对该字段进行索引。

Yes, this works

FullTextSession fts = Search.getFullTextSession(getSessionFactory().getCurrentSession());

Query q = fts.getSearchFactory().buildQueryBuilder()
    .forEntity(Offer.class).get()
    .keyword()
    .onField("id")
    .matching(myId)
    .createQuery();
Object[] dId = (Object[]) fts.createFullTextQuery(q, Offer.class)
    .setProjection(ProjectionConstants.DOCUMENT_ID)
    .uniqueResult();

if(dId != null){

    IndexReader indexReader = fts.getSearchFactory().getIndexReaderAccessor().open(Offer.class);

    TermFreqVector freq = indexReader.getTermFreqVector((Integer) dId[0], "description");

}

You have to remember to index the field with TermVector.YES in your hibernate search annotation for the field.

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