使用Lucene对图书馆构建Document(文档)和Field(字段)

/*
 * 下面的代码演示的是:如何向图书馆的书构建Document和Filed.
 * */
package ch2.lucenedemo.process;


import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;


public class Book {

Document bookdoc = new Document();

//创建书号Filed字段
Field bookNo = new Field("booknumber", "FB309663004", Field.Store.YES, Field.Index.UN_TOKENIZED);

//创建书名Field字段
Field bookName = new Field("bookname", "钢铁是怎样炼成的", Field.Store.YES, Field.Index.TOKENIZED);

//创建作者Field
Field author = new Field("author", "匿 名", Field.Store.YES, Field.Index.UN_TOKENIZED);

//创建发行的日期
Field publishdate = new Field("publishdate", "1999-01-01", Field.Store.YES, Field.Index.NO);


//创建摘要
Field bookabstract = new Field("abstract", "钢铁是怎样炼成的,这部小说是非常不错,是苏联的小说", Field.Store.YES, Field.Index.TOKENIZED);

//创建价格
Field price = new Field("price", "25.00", Field.Store.YES, Field.Index.NO);


public Book(){
//把所有的Field加入到Document中
bookdoc.add(bookNo);
bookdoc.add(bookName);
bookdoc.add(author);
bookdoc.add(publishdate);
bookdoc.add(bookabstract);
bookdoc.add(price);
}
}

你可能感兴趣的:(使用Lucene对图书馆构建Document(文档)和Field(字段))