Lucene Query to match multiple words like mysql

2019-09-01 06:52发布

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

It's harder than I thought:

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

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

Thanks in advance

EDIT:

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.

标签: php mysql lucene
1条回答
来,给爷笑一个
2楼-- · 2019-09-01 07:39

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);
查看更多
登录 后发表回答