
使用SolrQuery对象,
SolrQuery solrQuery = new SolrQuery()
solrQuery.setQuery("*:*")
String key = "java3"
solrQuery.addFilterQuery("content:" + "*"+key+"*" )试试吧
public class ProductSearchService {
//通过spring注入HttpSolrServer对象
@Autowired
private HttpSolrServer httpSolrServer
/**
*
* @描述:根据商品类型、商品颜色、价格区间组合条件到solr中查询数据
* @创建人:
* @创建时间:2015年11月04日 上午10:49:19
* @param productType 商品的类型
* @param minPrice 价格区间底价
* @param maxPrice 价格区间顶价
* @param color 商品的颜色
* @return 查询得到的所有商品列表
* @throws SolrServerException
*/
public List<Product>queryProduct(String productType,String color, Float minPrice, Float maxPrice) throws SolrServerException {
// 创建查询对象
SolrQuery solrQuery = new SolrQuery()
// 创建组合条件串
StringBuilder params = new StringBuilder("productType:" + productType)
// 组合商品颜色条件
if (color != null) {
params.append(" AND color:" + color)
}
// 组合价格区间条件
if (minPrice.intValue() != 0 || maxPrice != 0) {
params.append(" AND spPrice:[" + minPrice + " TO "
+ maxPrice + "]")
}
solrQuery.setQuery(params.toString())
// 执行查询并获取查询数据
QueryResponse queryResponse = this.httpSolrServer.query(solrQuery)
List<Product>products = queryResponse.getBeans(Product.class)
return products
}
}
一条索引包含了
Tips
solrJ 创建core只是把自己的文件夹加入到solr中,各种文件还要自建立
<field name="5#城市" type="string" indexed="false" stored="true"/>
pf 查询字段 qf 设置字段性对查询字段的比重 bf 设置权重的值
Searchers are presented with the indexed terms, along with numerical counts of how many matching documents were found were each term. Faceting makes it easy for users to explore search results, narrowing in on exactly the results they are looking for
简单说,solr的facet特性会搜索特定的facet.item,返回query中查询字段在item字段上的统计值且仅仅返回统计数量.
facet.poivt 实现了多维统计.例如统计班级学生的成绩分布,可以设置poivt=class,poivt=socore 返回的结果就是每个班各个成绩段学生的数量
在SolrJ中使用facet功能需要手动开启: query.setFacet(true) .然后根据需要 query.set(,) 添加条件.
facet 简单使用
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)