Touch e.net

Source: Internet
Author: User

Julia recently took over the job at e.net and asked me to check it. So I checked it. I have seen birdshover's lucene.net series before, But I just took a look at it and now I have studied it.

1. What is Lucene?

Lucene is a Java-based full-text information retrieval toolkit. It is not a complete search application.ProgramBut provides indexing and searching functions for your applications. Lucene is currently an open-source project in the Apache Jakarta family. It is also the most popular Java-based open-source full-text retrieval toolkit.

Currently, many application search functions are based on Lucene, such as the search function of the eclipse help system. Lucene canText TypeSo long as you can convert the data format you want to index into text, Lucene can index and search your documents. For example, if you want to index some HTML and PDF documents, you must first convert the HTML and PDF documents into text formats, and then hand the converted content to Lucene for indexing, then, save the created index file to the disk or memory, and query the index file based on the query conditions entered by the user. Without specifying the format of the document to be indexed, Lucene can be applied to almost all search applications.

Search for the relationship between applications and Lucene

Lucene.net is the. NET version of Lucene.

2. What can Lucene do?

Simply put, Lucene mainly does two things:

    1. Create an index
    2. Query by index

Lucene is highly efficient in full-text search.

Apache Lucene is an open source search engine. It can be used to easily add full-text search functions to Java software. Lucene's most important task is to index every word in a file. indexing greatly improves the search efficiency compared to the traditional one-word comparison. Lucene provides a set of interpretations, filters, and analyzes files, to orchestrate and use an index API, apart from being efficient and simple, it is the most important thing to enable users to customize their functions at any time as needed.

3. How does Lucene work?

First, create an index.

In this example, the data source is a database.

Code
 Public     Static     Void  Build (  String  Constring,  String  Indexlocation ){  Analyzer Analyzer =  New     Standardanalyzer  ();  Indexwriter  Writer =  New     Indexwriter  (Indexlocation, analyzer );  Sqldatareader  SDR =  Dbhelper  . Executereader (constring,  Commandtype . Text,  "Select Top 100 ID, title, content from article"  );  While  (SDR. Read ()){  Document  Doc =  New     Document  ();  // Create record object  Doc. Add (  New     Field (  "ID"  , SDR [  "ID"  ]. Tostring (),  Field  .  Store  . Yes,  Field  .  Index  . No ));  // Storage, not indexed  Doc. Add (  New     Field (  "Title"  , SDR [  "Title"  ]. Tostring (),  Field  .  Store  . No,  Field  .  Index  . Tokenized ));  // No storage, Word Segmentation Index  Doc. Add (  New    Field  (  "Content"  , SDR [  "Content"  ]. Tostring (),  Field  .  Store  . No,  Field  .  Index  . Tokenized ));  // No storage, Word Segmentation Index  Writer. adddocument (DOC );  // Load records } SDR. Close (); writer. Optimize (); writer. Close ();} 

First, create a analyzer, which is a standard analyzer (other analyzer will be mentioned later ). Then create a write index object based on this analyzer. Read the records in the article table in the database through the dbhelper class. Here we read the first one hundred records. (Here I will directly use ADO. Net (enterprise database daab), and there is no entities .) Each time a record is read, a document object is created and a field is added to the object. Notes,During field construction, the following two Parameters specify whether to store and whether to indexThis is the key. From the ing relationship with the database, it is easy to think that the document is equivalent to a record, and the field is equivalent to a field. Finally, add the created "record" to the writer.

Finally, perform optimize and close the object to release resources.

This is a simple example of creating an index.

Tomorrow I will talk about how to search based on indexes.

So today we are here ~~~

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.