搜索词开头的通配符-Lucene [英] Wildcard at the Beginning of a searchterm -Lucene

查看:140
本文介绍了搜索词开头的通配符-Lucene的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,lucene(.net)在搜索词开头不支持通配符 -> http://lucene.apache.org/java/2_0_0/queryparsersyntax.html 注意:您不能使用*或?符号作为搜索的第一个字符."

例如 * myword

也许是因为很难在搜索项之前搜索所有内容".

尽管如此,我们仍在寻找一种在开始时使用通配符的方法. 有人知道这是否可能吗?

一个想法是一个搜索项,b 搜索项,.... z *搜索项 ...但是对我来说似乎有点随机.

预先感谢

解决方案

您的问题已用Lucene.NET标记,因此我认为您是指.NET版本而不是Java版本.

是的,您可以通过以下方式在搜索字词的开头添加通配符

:

var queryParser = new QueryParser(LuceneVersion, "content", new StandardAnalyzer(LuceneVersion));
queryParser.SetAllowLeadingWildcard(true);

,但是您需要了解性能后果.在此博客中找到更详细的源代码.. >

由于Lucene.NET是Java版本的端口,因此我怀疑您可以对Java版本使用相同的方法.不过,我没有对此进行验证.

As far as i know lucene(.net) doesn't support the wildcard at the beginning of a searchterm --> http://lucene.apache.org/java/2_0_0/queryparsersyntax.html "Note: You cannot use a * or ? symbol as the first character of a search."

for example *myword

maybe because it's quiet difficult to search "everything" before the searchterm.

Despite that, We are looknig for a way to use the wildcard at the beginning. Does anyone know if this is possible?

One Thought was asearchterm, bsearchterm, ....z*searchterm ... but that seems a bit random to me.

thanks in advance

解决方案

Your question is tagged with Lucene.NET so I assume you mean the .NET version rather than the Java version.

Yes, you can have wildcards at the beginning of a search term by via

var queryParser = new QueryParser(LuceneVersion, "content", new StandardAnalyzer(LuceneVersion));
queryParser.SetAllowLeadingWildcard(true);

but you need to be aware of the performance consequences. Find more detailed source code in this blog.

Since Lucene.NET is a port of the Java version, I suspect you could use the same approach for the Java version. I didn't verify this, though.

这篇关于搜索词开头的通配符-Lucene的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆