Haystack more_like_this返回全部 [英] Haystack more_like_this returns all

查看:235
本文介绍了Haystack more_like_this返回全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django,haystack,solr来进行搜索。我可以搜索,现在我想找到类似的项目使用more_like_this。当我尝试使用more_like_this功能时,我会得到所有的模型类型的对象,而不是只匹配它的那些对象。以下是一些代码,显示如何使用它:

  def resource_view(request,slug):
resource = Resource.objects.get(slug = slug)
versions = Version.objects.get_for_object(resource)
related = SearchQuerySet()。more_like_this(resource)
add_comment_form = AddCommentForm()
return render_to_response('resources / resource.html',
{'resource':resource,
'versions':versions,
'related':related,
'add_comment_form ':add_comment_form},
context_instance = RequestContext(request))

显然我需要启用mlt在solrconfig.xml文件中。任何人都知道如何做,还是有用的文章/教程?

解决方案

陈旧的问题,但这里的答案无论如何:正如John已经指出的那样,你需要将更多的这个处理程序(MLT)添加到你的solr配置文件中。这应该做,把它放在你的solrconfig.xml的某个地方,并重新加载SOLR(Tomcat):

 < requestHandler name = / mltclass =solr.MoreLikeThisHandler> 
< lst name =defaults>
< str name =mlt.mintf> 1< / str>
< str name =mlt.mindf> 1< / str>
< str name =mlt.minwl> 3< / str>
< str name =mlt.maxwl> 15< / str>
< str name =mlt.maxqt> 20< / str>
< str name =mlt.match.include> false< / str>
< / lst>
< / requestHandler>


I am using Django, haystack, solr, to do searching. Ive am able to search and now I would like to find similar items using more_like_this. When I try to use the more_like_this functionality I get back all of the objects that are of that model type instead of just the ones that closely match it. Here is some code to show you how I am using it:

def resource_view(request, slug):
    resource = Resource.objects.get(slug=slug)
    versions = Version.objects.get_for_object(resource)
    related = SearchQuerySet().more_like_this(resource)
    add_comment_form = AddCommentForm()
    return render_to_response('resources/resource.html',
                              {'resource': resource,
                               'versions': versions,
                               'related': related,
                               'add_comment_form': add_comment_form},
                              context_instance=RequestContext(request))

Apparently I need to enable mlt in the solrconfig.xml file. Anyone know how to do this, or an article/tutorial that is helpful?

解决方案

stale question, but here's the answer anyway:

As John already pointed out, you need to add the more like this handler (MLT) to your solr config. This should do, put it somewhere in your solrconfig.xml, and reload SOLR (Tomcat):

<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
<lst name="defaults">
  <str name="mlt.mintf">1</str>
  <str name="mlt.mindf">1</str>
  <str name="mlt.minwl">3</str>
  <str name="mlt.maxwl">15</str>
  <str name="mlt.maxqt">20</str>
  <str name="mlt.match.include">false</str>
</lst>
</requestHandler>

这篇关于Haystack more_like_this返回全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆