- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
LuceneWhitespaceAnalyzerText.java
上传用户:cctqzzy
上传日期:2022-03-14
资源大小:12198k
文件大小:1k
源码类别:
搜索引擎
开发平台:
Java
- package chapter8;
- import java.io.IOException;
- import org.apache.lucene.document.Field;
- import org.apache.lucene.document.Document;
- import org.apache.lucene.index.IndexWriter;
- import org.apache.lucene.analysis.Analyzer;
- import org.apache.lucene.analysis.WhitespaceAnalyzer;
- import org.apache.lucene.analysis.TokenStream;
- import org.apache.lucene.analysis.Token;
- import java.util.*;
- import java.io.*;
- public class LuceneWhitespaceAnalyzerText {
- private static String Dest_Index_Path = "D:\workshop\TextIndex";
- static protected String textdetail = "Lucene works very well,it is very useful." ;
- public static void main(String[] args) {
- try {
- Analyzer TextAnalyzer = new WhitespaceAnalyzer();
- IndexWriter TextIndex = new IndexWriter(Dest_Index_Path,TextAnalyzer,true);
- Document document = new Document();
- Field field_content = new Field("content", textdetail,
- Field.Store.YES,Field.Index.TOKENIZED);
- document.add(field_content);
- TextIndex.addDocument(document);
- ArrayList ItemList = new ArrayList();
- TokenStream stream = TextAnalyzer.tokenStream("content", new StringReader(textdetail));
- while(true)
- {
- Token item = stream.next();
- if(null == item ) break;
- System.out.print("{"+item.termText()+"} ");
- }
- TextIndex.optimize();
- TextIndex.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println("");
- System.out.println("Index success");
- }
- }