使用 Lucene .NET 自动完成地址

发布于 2024-12-07 09:33:12 字数 545 浏览 3 评论 0原文

我还没能确定这一点。我尝试了几种不同的分析仪,它们都让我接近,但不完全是我想要的。目前还不能选择使用 SOLR。

我想要的一个例子:

    Input: 200
    Matches:  200 E Dragon Dr.
              200 W Paragon Rd.
              200 Lick Skillet Dr.

    Input: 200 E
    Matches:  200 E Dragon Dr.
              200 E Toll Rd.

    Input: 200 E D
    Matches: 200 E Dragon Dr.

如果我使用简单的分析器,那么它在数字上将不匹配。空白分析器仅使用数字即可获得所需的效果,但是一旦我添加 E,它就不会按我的预期返回。最好的分析器是什么,或者我使用了错误的查询?

谢谢,

编辑:

我已经接受了下面的答案,并进行了大量的谷歌搜索,我正在接近使用查询解析器和空白分析器。我只是让查询解析器确定最佳查询,它似乎可以工作。

I have not been able to get this nailed down. I have tried several different analyzers and they all get me close, but not exactly what I want. Using SOLR is not an option at the moment.

An examples of what I would like:

    Input: 200
    Matches:  200 E Dragon Dr.
              200 W Paragon Rd.
              200 Lick Skillet Dr.

    Input: 200 E
    Matches:  200 E Dragon Dr.
              200 E Toll Rd.

    Input: 200 E D
    Matches: 200 E Dragon Dr.

If I use the simple analyzer then it will not match on the number. The whitespace analyzer gets the desired effect with just the number, but once I add the E it does not return as I expect. What would be the best analyzer or am I using the wrong queries?

Thanks,

EDIT:

I have taken the below answer and did a ton of googling and I am getting close just using the query parser and the whitespaceanalyzer. I am just letting the query parser determine the best query and it seems to work.

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

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

发布评论

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

评论(1

初吻给了烟 2024-12-14 09:33:12

尝试使用关键字分析器和查询解析器来搜索 Lucene 中的地址字段。我正在使用 MultiFieldQueryParser,但您也可以使用常规查询解析器:

public StartsWithQuery Prefix(string prefix, string[] fields, Dictionary<string,string> filterFields = null )
        {
           if(!string.IsNullOrEmpty(prefix))
           {


               var parser = new MultiFieldQueryParser(Version.LUCENE_29, fields, new KeywordAnalyzer());
               var boolQuery = new BooleanQuery();

               boolQuery.Add(parser.Parse(prefix + "*"), BooleanClause.Occur.MUST);
               if (filterFields != null)
               {
                   foreach (var field in filterFields)
                   {
                        boolQuery.Add(new TermQuery(new Term(field.Key, field.Value)), BooleanClause.Occur.MUST);

                   }
               }

           }

            return this;
        }

try using a keyword analyzer and a query parser to search an address field in Lucene. I am using a MultiFieldQueryParser, but you could use a regular query parser too:

public StartsWithQuery Prefix(string prefix, string[] fields, Dictionary<string,string> filterFields = null )
        {
           if(!string.IsNullOrEmpty(prefix))
           {


               var parser = new MultiFieldQueryParser(Version.LUCENE_29, fields, new KeywordAnalyzer());
               var boolQuery = new BooleanQuery();

               boolQuery.Add(parser.Parse(prefix + "*"), BooleanClause.Occur.MUST);
               if (filterFields != null)
               {
                   foreach (var field in filterFields)
                   {
                        boolQuery.Add(new TermQuery(new Term(field.Key, field.Value)), BooleanClause.Occur.MUST);

                   }
               }

           }

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