Chuanzhi podcast-itcastbbs (6)

Source: Internet
Author: User

(20:40:15)

Reprinted
Tags:

It
 

Lucene:

1. Example: Eclipse help;

2. Create an index: only text data can be indexed.
 
 HTML (remove tags), PDF, etc. can be converted to text using corresponding tools;
 
3. Principle: Dictionary
 Key ---> recordnum
 AB ---> 5, 7, 10
 Document;
  5
  7
  10

4. Use:

 4.1 create a Java project;
 4.2 Add *. jar; [No configuration file] the current version is 2.4;
  Core; Word divider; Highlight;
 4.3 write code test;
  Firsttest
   Stringindexpath = "C:/javasedemoindex /";
   Analyzeranalyzer = new standardanalyer ();
  
   @ Test
   Testcreateindex (){
    Stringtitle = "XXX ";
    Stringcontent = "Yyy ";
    
    // 1. Create an index   
    Maxfieldlengthmaxfieldlength = maxfieldlength. Limited;
    
    // If the index library does not exist, it is created;
    Indexwriterindexwriter = new indexwriter (indexpath, analyzer, maxfieldlength );
    
    
    // Document, Field
    Documentdoc = new document ();
    Doc. Add (Newfield ("title", title, store. Yes, index. Analyzed ));
    Doc. Add (Newfield ("content", content, store. Yes, index. Analyzed ));
    
    Indexwriter. adddocument (DOC );
    
    
    // Close after use
    Indexwriter. Close (); 
   }
   
   
   Voidtestsearch (){
   
    Stringquerystring = "document ";   
    Indexsearcherindexsearcher = new indexsearcher (indexpath );
    
    Stringdefafielfieldname = "content ";
    Queryparserqueryparser = new queryparser (defaultfieldname, analyzer );
    
    QueryQuery= Queryparser. parse (querystring );  // Query Conditions
    FilterFilter= NULL;  // Filter Condition
    IntNdocs= 100;  // Returns the number of matched results.
    
    // Return results
    Topdocstopdocs = indexsearcher. Search (query, filter, ndocs );
    System. Out. println ("total [" + topdocs. totalhits + "matching records ");
    
    List <document> docs = newarraylist <document> ();
    For (scoredoc: topdocs. scoredocs ){
     Intdocnum = scoredoc.doc; // Document ID in the index Library
    
     Documentdoc = indexsearcher.doc (docnum); // retrieve the corresponding document by serial number
     
     Doc. Add (DOC );
    }   
    Indexsearcher. Close ();
    

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.