Solr 相似度判断moreLikeThis
来源:互联网 发布:香港人在哪注册域名 编辑:程序博客网 时间:2024/06/08 01:38
/**
* 获取相似性数据
* @param id
* @param mindf
* @param mintf
* @param count
* @return
*/
public List<LableGroup> getRelated(String id, int mindf, int mintf, int count) {
List<LableGroup> lableGroups = new ArrayList<LableGroup>();
SolrQuery solrQuery = new SolrQuery();
try {
solrQuery.setQuery("id:" + id)
.setParam("fl", "id,title,url,score")
.setParam("mlt", "true")
.setParam("mlt.fl", "title")
.setParam("mlt.mindf", String.valueOf(mindf))
.setParam("mlt.mintf", String.valueOf(mintf))
.setParam("mlt.count", String.valueOf(count));
QueryResponse response = server.query(solrQuery);
if (null == response) return lableGroups;
@SuppressWarnings("unchecked")
SimpleOrderedMap<SolrDocumentList> solrDocumentLists = (SimpleOrderedMap<SolrDocumentList>) response.getResponse().get("moreLikeThis");
for (int i=0; i<solrDocumentLists.size(); i++) {
SolrDocumentList solrDocumentList = solrDocumentLists.getVal(i);
for (SolrDocument doc : solrDocumentList) {
String doc_id = doc.getFieldValue("id").toString();
String doc_title = doc.getFieldValue("title").toString();
String doc_url = doc.getFieldValue("url").toString();
String doc_score = doc.getFieldValue("score").toString();
// 判断相似度
if (Double.parseDouble(doc_score) > 1) {
LableGroup lableGroup = new LableGroup();
lableGroup.setId(doc_id);
lableGroup.setTitle(doc_title);
lableGroup.setUrl(doc_url);
lableGroups.add(lableGroup);
}
}
}
} catch (Exception e) {
log.error("获取相似性数据error", e);
}
return lableGroups;
* 获取相似性数据
* @param id
* @param mindf
* @param mintf
* @param count
* @return
*/
public List<LableGroup> getRelated(String id, int mindf, int mintf, int count) {
List<LableGroup> lableGroups = new ArrayList<LableGroup>();
SolrQuery solrQuery = new SolrQuery();
try {
solrQuery.setQuery("id:" + id)
.setParam("fl", "id,title,url,score")
.setParam("mlt", "true")
.setParam("mlt.fl", "title")
.setParam("mlt.mindf", String.valueOf(mindf))
.setParam("mlt.mintf", String.valueOf(mintf))
.setParam("mlt.count", String.valueOf(count));
QueryResponse response = server.query(solrQuery);
if (null == response) return lableGroups;
@SuppressWarnings("unchecked")
SimpleOrderedMap<SolrDocumentList> solrDocumentLists = (SimpleOrderedMap<SolrDocumentList>) response.getResponse().get("moreLikeThis");
for (int i=0; i<solrDocumentLists.size(); i++) {
SolrDocumentList solrDocumentList = solrDocumentLists.getVal(i);
for (SolrDocument doc : solrDocumentList) {
String doc_id = doc.getFieldValue("id").toString();
String doc_title = doc.getFieldValue("title").toString();
String doc_url = doc.getFieldValue("url").toString();
String doc_score = doc.getFieldValue("score").toString();
// 判断相似度
if (Double.parseDouble(doc_score) > 1) {
LableGroup lableGroup = new LableGroup();
lableGroup.setId(doc_id);
lableGroup.setTitle(doc_title);
lableGroup.setUrl(doc_url);
lableGroups.add(lableGroup);
}
}
}
} catch (Exception e) {
log.error("获取相似性数据error", e);
}
return lableGroups;
}
注:
id:文档唯一主键;
fl:需要返回的字段;
mlt:在查询时,打开/关闭(MoreLikeThisComponent)的布尔值。
mtl.fl:根据哪些字段判断相似度;
mlt.mindf:最小文档频率,所在文档的个数小于这个值的词将不用于相似判断;
mlt.mintf:最小分词频率,在单个文档中出现频率小于这个值的词将不用于相似判断;
mlt.count:返回相似文章个数;
- Solr 相似度判断moreLikeThis
- solr 相似查询 -- MoreLikeThis
- Solr 相似页面MoreLikeThis
- solr学习之九:MoreLikeThis相似查询
- solr学习之九:MoreLikeThis相似查询
- MoreLikeThis 相似检索
- MoreLikeThis 相似检索
- solr高亮(highlight),拼写检查(spellCheck),匹配相似(moreLikeThis) 应用实践
- Solrj 取出商品相似度moreLikeThis的方法
- MoreLikeThis实现检索相似文档
- solr MoreLikeThis的原理分析
- Solr相似度算法:BM25Similarity
- Solr Cookbook学习记录 - MoreLikeThis学习
- 转载:solr MoreLikeThis的原理分析
- sql判断字符串相似度
- solr的相似匹配
- solr 相似匹配
- Solr之相似匹配。
- PB树型结构遍历
- Mac OS X: Best Way to Make an ISO from a CD or DVD
- C#异步回调实例 持续获取CPU、内存使用率
- freetype 使用小结
- Window系统上编写Linux_c语言程序的环境搭建
- Solr 相似度判断moreLikeThis
- PB编写登录程序
- adaboost人脸检测
- 判断点是否在矩形内
- sqlite官方网站
- 数据结构之快速排序(C语言)
- MyEclipse6.0反编译插件jadclipse安装
- 国外的英文JAVA论坛
- 出现java.sql.SQLException: After end of result set的原因