Haystack more_like_this returns all

亡梦爱人 提交于 2019-12-22 21:55:44

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/4064753/haystack-more-like-this-returns-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!