Full-text search based on e.net by Baidu counterfeited (1)

Source: Internet
Author: User

Lucene. Net

Lucene.net is from Lucene. net is an open source full-text search engine development kit, that is, it is not a complete full-text search engine, but a full-text search engine architecture, is a Library. you can also think of it as a simple and easy-to-use API that encapsulates the index and search functions (providing a complete query engine and index engine ). With this set of APIS, you can do a lot of searching, and it is very convenient .. Developers can implement full-text search based on e.net.

Note: Lucene. Net can only search text information. If it is not text information, convert it to text information. For example, to retrieve an Excel file, use NPOI to read the Excel file as a string and then throw the string to Lucene. Net. Lucene. Net saves the text that is thrown to it to speed up retrieval.

For more conceptual knowledge, refer to this blog: http://blog.csdn.net/xiucool/archive/2008/11/28/3397182.aspx

This Demo example shows:

OK. Next I will explain how Corporal can achieve this effect step by step.

Lucene. Net core-word segmentation algorithm Analyzer)

Learning Lucune. Net, word segmentation is the core. Of course, you can expand word segmentation on your own, but this requires high algorithm requirements. Different Word Segmentation Algorithms in Lucene. Net are different classes. All Word Segmentation Algorithms inherit from the Analyzer class. Different word segmentation algorithms have different advantages and disadvantages.

The built-in StandardAnalyzer is used to split English words by spaces, punctuation marks, and so on. The Chinese words are segmented by a single word. One Chinese character is counted as one word.

 
  1. Analyzer analyzer = new StandardAnalyzer ();
  2. TokenStream tokenStream = analyzer. TokenStream ("", new StringReader ("Hello Lucene. Net, I love 1 You China "));
  3. Lucene. Net. Analysis. Token token = null;
  4. While (token = tokenStream. Next ())! = Null)
  5. {
  6. Console. WriteLine (token. TermText ());
  7. }

Result After word segmentation:

The binary word segmentation algorithm calculates one word for every two Chinese characters. "I love you China" is segmented into "I Love You china". Click to view the binary word segmentation algorithm CJKAnalyzer.

 
  1. Analyzer analyzer = new CJKAnalyzer ();
  2. TokenStream tokenStream = analyzer. TokenStream ("", new StringReader ("I Love You China People's Republic of China "));
  3. Lucene. Net. Analysis. Token token = null;
  4. While (token = tokenStream. Next ())! = Null)
  5. {
  6. Response. Write (token. TermText () + "<br/> ");
  7. }

At this time, you must be thinking that there is no good binary word splitting algorithm, and you really want to expand Analyzer on your own, but it is not an algorithm professional. What should I do?

The fall of heaven, pangu word segmentation,Click to download.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.