luence

@SuppressWarnings({ "unchecked", "deprecation" })
public static List<Goods> SearchForContent(String indexPath, String keyword, int start, int max,
String orderByField, String orderByType) throws Exception
{

List<Goods> goodsList = new ArrayList<Goods>();
String path = indexPath + "index";
IndexSearcher indexSearcher = new IndexSearcher(path);
IndexSearcher indexSearchers[] = { indexSearcher };
MultiSearcher searcher = new MultiSearcher(indexSearchers);
if (searcher != null)
{
String[] fields = { "saleName", "advertiseWords" };
BooleanClause.Occur[] clauses = { BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD };
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
keyword = LabelUtil.filter(keyword);
Query query = MultiFieldQueryParser.parse(keyword, fields, clauses, analyzer);
boolean orderby = true;
if ("asc".equalsIgnoreCase(orderByType))
{
orderby = false;
}
SortField sortField = new SortField(orderByField, orderby);
Sort sort = new Sort(sortField);
Hits top = null;
if ("sales".equals(orderByField))
{
top = searcher.search(query);
}
else
{
top = searcher.search(query, sort);
}
SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter(LS, LE);
Highlighter highlighter = new Highlighter(simpleHTMLFormatter, new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(100));
if (max > top.length())
max = top.length();
for (int i = start; i < max; i++)
{
Document doc = top.doc(i);
List<Field> list = doc.getFields();
Goods good = new Goods();
for (Field d : list)
{
String filedName = d.name();
String value = d.stringValue();
if ("goodsId".equals(filedName))
{
String goodsId = RequestUtil.VailStr(value, "");
good.setGoods_id(Long.parseLong(goodsId));
}
if ("saleName".equals(filedName))
{
String filterStr = LabelUtil.filter(RequestUtil.VailStr(d.stringValue(), ""));
String highliStr = highlighter.getBestFragment(LuceneContacts.analyzer, d.name(), filterStr);
if (StringUtil.isEmpty(highliStr))
{
good.setSale_name(RequestUtil.VailStr(value, ""));
}
else
{
good.setSale_name(highliStr);
}
}
if ("name".equals(filedName))
{
good.setName(RequestUtil.VailStr(value, ""));
}
if ("advertiseWords".equals(filedName))
{
String filterStr = LabelUtil.filter(RequestUtil.VailStr(d.stringValue(), ""));
String highliStr = highlighter.getBestFragment(LuceneContacts.analyzer, d.name(), filterStr);
if (StringUtil.isEmpty(highliStr))
{
good.setAdvertise_words(RequestUtil.VailStr(value, ""));
}
else
{
good.setAdvertise_words(highliStr);
}
}
if ("price".equals(filedName))
{
if (value != null && !"".equals(value) && !"null".equals(value))
{
good.setPrice(new BigDecimal(value));
}
else
{
good.setPrice(new BigDecimal(0));
}
}
if ("onShelfTime".equals(filedName))
{
Date date = null;
if (value != null && !"".equals(value))
{
date = new Date(RequestUtil.FormatDaeHH(value));
}
good.setOn_shelf_time(date);
}
if ("primaryPicName".equals(filedName))
{
good.setPrimaryPicName(RequestUtil.VailStr(value, ""));
}
if ("imgPath".equals(filedName))
{
good.setImgPath(RequestUtil.VailStr(value, ""));
}
if ("picType".equals(filedName))
{
good.setPicType(RequestUtil.VailStr(value, ""));
}
}
goodsList.add(good);
}
searcher.close();
}
return goodsList;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值