Lucene查询以匹配多个单词,例如mysql的"LIKE%my string%" [英] Lucene Query to match multiple words like mysql's "LIKE %my string%"

查看:376
本文介绍了Lucene查询以匹配多个单词,例如mysql的"LIKE%my string%"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Lucene中匹配多个单词,就像在MySQL中一样.

I'm trying to match multiple words in Lucene as I could do in MySQL.

这比我想的要难:

用PHP编写: 我对完美匹配的查询是:

written in PHP: my query for perfect match is:

$words = explode($words, " ");
(text:(' . implode(" ", $words) . ')

但是如果文本是我写的一堆单词",那么直到我写完所有内容后,文本才会匹配

but if text is "a bunch of words I wrote", it won't match until I have written everything

是否存在强迫Lucene完全像MySQL一样的%a bunc%"行为并检索漏洞短语的方法?

Does exist any way to force Lucene to behave exactly like MySQL's like "%a bunc%" and retrieve the hole phrase?

预先感谢

我不是直接使用Lucene,而是将Solr用作REST服务.因此,我正在寻找普通语法"来解决此问题,例如:select?q = :并且查询为:(全选)(如果我有很多单词的话)如前所述,在文本字段中,我找不到任何将它们视为唯一词的方法. 如果这是一个独特的词,我可以执行"text:(beginningOfW *)",它将找到它, 如果是多个单词,如果我写"text:(W *开头)",它将仅找到以W开头的单词,而忽略其他单词.

I'm not using Lucene directly, I use Solr as a REST service. So I'm looking for the "plain grammar" to solve this problem like: select?q=: and the query is : ( select all ) if I have many words in the text field, as told before, I don't find any way to consider them as a unique word. If it were a unique word, I could do "text:(beginningOfW*)" and it would find it, If it is a multiple words, If I write "text:(beginning Of W*)" it will find only words beginning with W, and ignore the other words.

推荐答案

是的,Lucene是全文搜索引擎API.我认为您正在寻找WildCardQuery:

Yes, Lucene is full text search engine API. I think you are looking for WildCardQuery:

Term term = new Term("whichField", "searchString");
Query query = new WildcardQuery(term);
Hits hits = indexSearcher.search(query);

这篇关于Lucene查询以匹配多个单词,例如mysql的"LIKE%my string%"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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