短语查询和使用 shingle 过滤器有什么区别?
我目前正在使用 lucene 索引网页。目的是能够快速提取哪个页面包含某个表达(通常是 1、2 或 3 个单词),以及该页面中还包含哪些其他单词(或其中 1 到 3 个单词的组)。 这将用于构建/丰富/更改同义词库(固定词汇)。
从我找到的文章来看,问题似乎是找到 n-grams (或卵石)。
Lucene 有一个 ShingleFilter ,一个ShingleMatrixFilter,和一个ShingleAnalyzerWrapper,这似乎与此任务相关。
从这个演示中,我了解到Lucene还可以搜索以固定数字分隔的术语单词(称为 slops)。 此处提供了一个示例。
但是,我不清楚这些方法之间的区别?它们是根本不同的,还是您必须做出的性能/索引大小选择?
ShingleMatrixFilter和ShingleFilter有什么区别?
希望 Lucene 大师能够找到这个问题,并回答;-)!
I'm currently indexing webpage using lucene. The aim is to be able to quickly extract which page contain a certain expression (usually 1, 2 or 3 words), and which other words (or group of 1to 3 of them) are also in the page.
This will be used to build / enrich / alter a thesaurus (fixed vocabulary).
From the articles I found, it seems the problem is to find n-grams (or shingle).
Lucene has a ShingleFilter, a ShingleMatrixFilter, and a ShingleAnalyzerWrapper, which seem related to this task.
From this presentation, I learned that Lucene can also search for terms separated by a fixed number of words (called slops). An example is provided here.
However, I don't understand clearly the difference between those approach? Are they fundamentally different, or is it a performance / index size choice that you have to make?
What is the difference between ShingleMatrixFilter and ShingleFilter?
Hope a Lucene guru will FIND this question, and and answer ;-) !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用短语与木瓦之间的差异主要涉及性能和评分。
在索引中存在单个单词的典型情况下使用短语查询(例如“foo bar”)时,短语查询必须遍历“foo”和“bar”的倒排索引并找到包含这两个术语的文档,然后在每个文档中遍历他们的位置列表,以查找“foo”出现在“bar”之前的位置。
这对性能和评分都有一定的成本:
另一方面,如果您使用 shingles,您也会对单词 n-gram 进行索引,换句话说,如果您的 shingles 大小达到 2,那么索引中还会有诸如“foo bar”之类的术语。这意味着对于这个短语查询,它将被解析为简单的 TermQuery,而不使用任何位置列表。由于它现在是一个“真正的术语”,因此 IDF 短语将是准确的,因为我们确切地知道这个“术语”存在多少文档。
但使用 shingles 也有一些成本:
一般来说,使用 Shingles 或 CommonGrams 之类的词索引只是一种权衡(相当专业),以降低位置查询的成本或增强短语评分。
但是这个东西有现实世界的用例,这里有一个很好的例子:
http://www.hathitrust.org/blogs/大规模搜索/慢速查询和常用词-第 2 部分
The differences between using phrase versus shingle mainly involve performance and scoring.
When using phrase queries (say "foo bar") in the typical case where single words are in the index, phrase queries have to walk the inverted index for "foo" and for "bar" and find the documents that contain both terms, then walk their positions lists within each one of those documents to find the places where "foo" appeared right before "bar".
This has some cost to both performance and scoring:
On the other hand, if you use shingles, you are also indexing word n-grams, in other words, if you are shingling up to size 2, you will also have terms like "foo bar" in the index. This means for this phrase query, it will be parsed as a simple TermQuery, without using any positions lists. And since its now a "real term", the phrase IDF will be exact, because we know exactly how many documents this "term" exists.
But using shingles has some costs as well:
In general, indexing word-ngrams with things like Shingles or CommonGrams is just a tradeoff (fairly expert), to reduce the cost of positional queries or to enhance phrase scoring.
But there are real-world use cases for this stuff, a good example is available here:
http://www.hathitrust.org/blogs/large-scale-search/slow-queries-and-common-words-part-2