1 public void createIndex() throws IOException {
2 DIRECTORY = FSDirectory.open(new File("/home/andy/work/lucene/index/1"));
3 Analyzer chineseanalyzer = new SmartChineseAnalyzer(Version.LUCENE_42);
4 IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_42,chineseanalyzer);
5 InfoStream printStream = new PrintStreamInfoStream(System.out);
6 indexWriterConfig.setInfoStream(printStream);
7 FieldType nameType = new FieldType();
8 nameType.setIndexed(true);
9 nameType.setStored(true);
10 IndexWriter indexWriter = null;
11 try {
12 indexWriter = new IndexWriter(DIRECTORY, indexWriterConfig);
13 Document document = new Document();
14 document.add(new Field("name","hp",nameType));
15 document.add(new Field("company","ibm oracle ibm",nameType));
16 indexWriter.addDocument(document);
17
18 document = new Document();
19 document.add(new Field("name","hp",nameType));
20 document.add(new Field("company","ibm dell oracle",nameType));
21 indexWriter.addDocument(document);
22
23 indexWriter.commit();
24 } catch (IOException e) {
25 e.printStackTrace();
26 } finally {
27 if (null != indexWriter) {
28 indexWriter.close();
29 }
30 }
31
32 }