Indexing and retrieving Chinese files using Lucene 3.0.0

Source: Internet
Author: User

I. My original procedure.

In fact, my original program is quite simple, completely modified from the demo inside the Searchfiles and indexfiles. The only difference is that it refers to the SMARTCN word breaker.

I post the code that modifies that point.

Indexhchinese.java:

Date start = new Date();
try {
   IndexWriter writer = new IndexWriter(FSDirectory.open(INDEX_DIR), 
           new SmartChineseAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
   indexDocs(writer, docDir);
   System.out.println("Indexing to directory '" +INDEX_DIR+ "'...");
   System.out.println("Optimizing...");
   //writer.optimize();
   writer.close();

   Date end = new Date();
   System.out.println(end.getTime() - start.getTime() + " total milliseconds");

}
     SearchChinese.java
Analyzer analyzer = new SmartChineseAnalyzer(Version.LUCENE_CURRENT);

BufferedReader in = null;
if (queries != null) {
   in = new BufferedReader(new FileReader(queries));
} else {
   in = new BufferedReader(new InputStreamReader(System.in, "GBK"));
}

Here, I have developed the input of the query is encoded using GBK.

Then I am full of confidence after running ... Found unable to retrieve the Chinese, the English search inside is normal.

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.