📄 productdocument.java
字号:
package com.luceneheritrixbook.index;
import org.apache.lucene.document.*;
import com.luceneheritrixbook.core.Product;
public class ProductDocument {
private static final String PRODUCT_ID = "productid";
private static final String INDEX_TIME = "indextime";
private static final String PRODUCT_URL = "producturl";
private static final String CATEGORY = "category";
private static final String PRODUCT_NAME = "name";
private static final String PRODUCT_TYPE = "type";
public static Document buildProductDocument(Product product, int id) {
Document doc = new Document();
Field identifier = new Field(PRODUCT_ID, id + "", Field.Store.YES,
Field.Index.UN_TOKENIZED);
long mills = System.currentTimeMillis();
Field indextime = new Field(INDEX_TIME, mills + "", Field.Store.YES,
Field.Index.UN_TOKENIZED);
Field producturl = new Field(PRODUCT_URL, product.getOriginalUrl(),
Field.Store.YES, Field.Index.UN_TOKENIZED);
Field category = new Field(CATEGORY, product.getCategory(),
Field.Store.YES, Field.Index.TOKENIZED);
Field name = new Field(PRODUCT_NAME, product.getName(),
Field.Store.YES, Field.Index.TOKENIZED);
Field type = new Field(PRODUCT_TYPE, product.getType(),
Field.Store.YES, Field.Index.TOKENIZED);
String text = product.getCategory();
text += " " + product.getName();
text += " " + product.getType();
Field all = new Field("all", text, Field.Store.YES, Field.Index.TOKENIZED);
// add all
doc.add(identifier);
doc.add(indextime);
doc.add(producturl);
doc.add(category);
doc.add(name);
doc.add(type);
doc.add(all);
return doc;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -