首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Lucene.Net进行多词自动提示

使用Lucene.Net进行多词自动提示
EN

Stack Overflow用户
提问于 2010-06-09 03:45:39
回答 2查看 1.8K关注 0票数 4

我目前正在开发一个搜索应用程序,它使用Lucene.Net将数据库中的数据索引到索引文件中。我有一个产品目录,其中有名称,简短和详细的描述,sku和其他字段。数据使用StandardAnalyzer存储在索引中。我试图为文本字段添加自动建议,并使用TermEnum从索引中获得所有关键字术语及其分数。但返回的条款是单期的。例如,如果我输入co,返回的建议是服装、计数、集合、牛仔、组合等。但我希望建议返回短语。例如,如果我搜索co,建议应该是牛仔服装,成人服装,密码锁等。

以下是用于获取建议的代码:

代码语言:javascript
复制
public string[] GetKeywords(string strSearchExp)
{

IndexReader rd = IndexReader.Open(mIndexLoc);
TermEnum tenum = rd.Terms(new Term("Name", strSearchExp));
string[] strResult = new string[10];
int i = 0;
Dictionary<string, double> KeywordList = new Dictionary<string, double>();
do
{
    //terms = tenum.Term();
    if (tenum.Term() != null)
    {
        //strResult[i] = terms.text.ToString();
        KeywordList.Add(tenum.Term().text.ToString(), tenum.DocFreq());
    }
} while (tenum.Next() && tenum.Term().text.StartsWith(strSearchExp) && tenum.Term().text.Length > 1);

var sortedDict = (from entry in KeywordList orderby entry.Value descending select entry);

foreach (KeyValuePair<string, double> data in sortedDict)
{
    if (data.Key.Length > 1)
    {
        strResult[i] = data.Key;
        i++;
    }
    if (i >= 10)    //Exit the for Loop if the count exceeds 10
        break;
}
tenum.Close();
rd.Close();
return strResult;

}

有没有人能给我指路来实现这个目标?谢谢你调查这个。

EN

回答 2

Stack Overflow用户

发布于 2010-06-13 00:09:43

您可以简单地使用Field.Index.NOT_ANALYZED参数或KeywordAnalyzer在不同的字段中索引您的产品名称,然后对其运行通配符查询或前缀查询。

票数 1
EN

Stack Overflow用户

发布于 2010-06-10 05:15:06

正如你所说,“退还的条款是单期的”。因此,您需要创建由短语组成的术语。

您可以使用内置的ShingleFilter标记筛选器来创建短语术语:

http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/analysis/shingle/ShingleFilter.html

你可能想要使用一个单独的字段,因为我不确定ShingleFilter是否真的产生单个术语-你可能会想要尝试一下。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3000694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档