Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the like matching effect of database by lucene full-text search

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report