如何在Lucene.Net中找到同义词

时间:2021-06-21 03:06:03

I need lucene to search for synonyms as well as the actual keyword. that is if I search for "CI", I want it to search for CI OR "continues integration". at the moment I search for keywords I have the synonyms for and replace them with the "OR-ed" version, but I suspect there should be a better way to do this. my method will not work for complex queries where you have something like "x AND y OR NOT z".

我需要lucene来搜索同义词以及实际的关键字。也就是说,如果我搜索“CI”,我希望它搜索CI或“继续集成”。目前我搜索关键字我有同义词并用“OR-ed”版本替换它们,但我怀疑应该有更好的方法来做到这一点。我的方法不适用于你有“x AND y OR NOT z”之类的复杂查询。

2 个解决方案

#1


2  

That's pretty much how I was planning on implementing this functionality. I was planning on building my own version of this but then I ran across this site WordNet.Net which seems to try to address the issue of building the synonyms. There is a wordnet extension to Lucene.Net which rewrites the query, so I'm guessing that is really the standard way of handling this.

这就是我计划实现此功能的方式。我打算建立我自己的版本,但后来我跑过这个网站WordNet.Net似乎试图解决构建同义词的问题。 Lucene.Net有一个wordnet扩展,它重写了查询,所以我猜这真的是处理这个问题的标准方法。

#2


0  

At least in the Java version of Lucene, you could write yourself a recursive function that digs through the BooleanQuery Query objects that the QueryParser will build; every time it finds a TermQuery, it could replace it with a BooleanQuery that OR's the original term with the new term you want added into the query.

至少在Lucene的Java版本中,你可以编写一个递归函数,挖掘QueryParser将构建的BooleanQuery Query对象;每次找到TermQuery时,它都可以用一个BooleanQuery替换它,或者是原始术语,并且要添加到查询中的新术语。

#1


2  

That's pretty much how I was planning on implementing this functionality. I was planning on building my own version of this but then I ran across this site WordNet.Net which seems to try to address the issue of building the synonyms. There is a wordnet extension to Lucene.Net which rewrites the query, so I'm guessing that is really the standard way of handling this.

这就是我计划实现此功能的方式。我打算建立我自己的版本,但后来我跑过这个网站WordNet.Net似乎试图解决构建同义词的问题。 Lucene.Net有一个wordnet扩展,它重写了查询,所以我猜这真的是处理这个问题的标准方法。

#2


0  

At least in the Java version of Lucene, you could write yourself a recursive function that digs through the BooleanQuery Query objects that the QueryParser will build; every time it finds a TermQuery, it could replace it with a BooleanQuery that OR's the original term with the new term you want added into the query.

至少在Lucene的Java版本中,你可以编写一个递归函数,挖掘QueryParser将构建的BooleanQuery Query对象;每次找到TermQuery时,它都可以用一个BooleanQuery替换它,或者是原始术语,并且要添加到查询中的新术语。