How to realize the like matching effect of database by lucene full-text search
This article introduces the relevant knowledge of "lucene full-text search how to achieve the like matching effect of the database". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In general, full-text search is based on fuzzy matching of Chinese word segmentation. For example, the taste of searching for that restaurant is better, and the words such as restaurant taste will be searched out in the article. This is consistent with the performance of mainstream search engines such as Baidu and Google.
In practice, some customers want a wildcard query like a database, such as like'% Hotel%'. Although this is not the way lucene works, it is not impossible if you have to achieve such an effect.
First, do not use word segmentation when creating an index on lucene; then use WildcardQuery wildcard search.
Modify com.jspxcms.core.fulltext.FInfo in jspxcms
Public static Document doc (Info info) {... String title = info.getFullTitleOrTitle (); if (StringUtils.isNotBlank (title)) {/ / the title is not participle. Change ANALYZED to NOT_ANALYZED doc.add (new Field (TITLE, title, YES, NOT_ANALYZED);}. String text = info.getPlainText (); if (StringUtils.isNotBlank (text)) {/ / the text is not segmented. Change ANALYZED to NOT_ANALYZED doc.add (new Field (TEXT, text, YES, NOT_ANALYZED);}. Public static Query query (...) {if (StringUtils.isNotBlank (Q)) {Q = QueryParser.escape (Q); BooleanQuery bq = new BooleanQuery (); bq.add (new WildcardQuery (new Term (TITLE, "*" + Q + "*)), SHOULD); bq.add (new Term (TEXT," * "+ Q +" *)), SHOULD) Query.add (bq, MUST); / / Query qy = MultiFieldQueryParser.parse (LUCENE_36, Q, / / new String [] {TITLE, KEYWORD, DESCRIPTION, TEXT}, / / new Occur [] {SHOULD, SHOULD}, / / analyzer); / / query.add (qy, MUST) }}...}
When the modification is complete, restart tomcat, and then regenerate the full-text index.
This is the end of the content of "how to achieve the like matching effect of the database by lucene full-text search". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!