Lucene wildcard queries

I have this question regarding Lucene.

I have a form, and I get text from it, and I want to perform a full text search in several fields. Suppose I get the text "textToLook" from the input.

I have a Lucene Analyzer with several filters. One of them is lowerCaseFilter, so when I create the index, the words will decrease.

Imagine I want to search two fields, field1 and field2, so the lucene query will look something like this (note that "textToLook" is now "texttolook"):

field1: texttolook* field2:texttolook*

In my class, I have something like this to create a query. I work when there is no template.

String text = "textToLook";
String[] fields = {"field1", "field2"};
//analyser is the same as the one used for indexing
Analyzer analyzer = fullTextEntityManager.getSearchFactory().getAnalyzer("customAnalyzer");
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, analyzer);
org.apache.lucene.search.Query queryTextoLibre = parser.parse(text);

Using this code, the query will look like this:

field1: texttolook field2:texttolook

but if I set the text to textToLook *, I get

field1: texttolook* field2:texttolook*

, .

- lucene :

" , , , , lowercasing"

, , .

, , , , "*", Query MultiFieldQueryParser. "textToLower", , , "texttolower". "textotolower *".

? ? ?

+3
1

QueryParser.setLowercaseExpandedTerms(true)?

http://wiki.apache.org/lucene-java/LuceneFAQ#Are_Wildcard.2C_Prefix.2C_and_Fuzzy_queries_case_sensitive.3F

** **

, . , , .

QueryParser

protected Query getWildcardQuery(String field, String termStr) throws ParseException

termStr , WildcardQuery.

, , . , , faq:

, " *" "", "", " *", .

+1

Source: https://habr.com/ru/post/1736648/


All Articles