提交 f5d3a52a 编写于 作者: 黄勇

【I】使用 Search 插件

上级 493a53e3
......@@ -65,6 +65,11 @@
<artifactId>smart-plugin-i18n</artifactId>
<version>${smart.version}</version>
</dependency>
<dependency>
<groupId>com.smart</groupId>
<artifactId>smart-plugin-search</artifactId>
<version>${smart.version}</version>
</dependency>
</dependencies>
<build>
......
package com.smart.sample.search;
import com.smart.framework.DataSet;
import com.smart.framework.annotation.Bean;
import com.smart.framework.util.CollectionUtil;
import com.smart.plugin.search.IndexFieldName;
import com.smart.plugin.search.SearchEngine;
import com.smart.plugin.search.bean.IndexData;
import com.smart.plugin.search.bean.IndexDocument;
import com.smart.plugin.search.bean.IndexField;
import com.smart.plugin.search.bean.SearchResult;
import com.smart.sample.entity.Product;
import java.util.List;
import org.apache.lucene.document.Document;
@Bean
public class ProductSearchEngine implements SearchEngine {
@Override
public IndexData createIndexData() {
IndexData indexData = new IndexData();
List<Product> productList = DataSet.selectList(Product.class, "", "");
if (CollectionUtil.isNotEmpty(productList)) {
for (Product product : productList) {
IndexDocument indexDocument = new IndexDocument();
indexDocument.addIndexField(new IndexField(IndexFieldName.title, product.getName()));
indexDocument.addIndexField(new IndexField(IndexFieldName.content, product.getDescription()));
indexData.addIndexDocument(indexDocument);
}
}
return indexData;
}
@Override
public SearchResult createSearchResult(Document document) {
SearchResult searchResult = new SearchResult();
searchResult.setTitle(document.get("name"));
searchResult.setContent(document.get("description"));
return searchResult;
}
}
......@@ -14,4 +14,6 @@ jdbc.max.idle=10
i18n.reloadable=true
sample.upload_path=/www/upload/
\ No newline at end of file
sample.upload_path=/www/upload/
search.index_dir=D:/temp/index/smart
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册