Haystack不返回Solr管理控制台亮点的结果 [英] Haystack Not Returning Results that Solr Admin Console Highlights

查看:191
本文介绍了Haystack不返回Solr管理控制台亮点的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近设置了solr和haystack来搜索我的一个django模型。我尝试修改由haystack构建的默认solr模式,以使用 NGramTokenizerFactory

 < fieldType name =textclass =solr.TextField> 
< analyzer type =index>
< tokenizer class =solr.NGramTokenizerFactoryminGramSize =3maxGramSize =32/>
< filter class =solr.LowerCaseFilterFactory/>
< / analyzer>
< analyzer type =query>
< tokenizer class =solr.NGramTokenizerFactoryminGramSize =3maxGramSize =32/>
< filter class =solr.LowerCaseFilterFactory/>
< / analyzer>
< / fieldType>

我在数据库中有一堆或两个单词条目,我想与用户查询。所以例如,我可能有一个标题为dog的对象,另一个标题为cat。如果用户搜索狗猫,那么我想要返回该查询的狗和猫对象。



同样,如果我搜索我的酷网站,我希望返回带有网站的字段。



我尝试使用solr管理界面检查以确保我的查询得到匹配。一切似乎都可以:
问题是当我使用haystack默认搜索界面搜索相同的查询:



如您所见,没有找到结果。我尝试使用KeywordFactory和一堆不同的solr配置。如果我没有错误,那么查询应该得到匹配。我不知道为什么干草堆空了。



感谢任何帮助/建议,如果这是最好的方法来进行这样的搜索。

解决方案

几个月前,我与 django-haystack 和solr合作。我也有一个问题,对solr做一些特殊的查询。
实际上它应该通过添加下一行来解决 settings.py

 code> HAYSTACK_DEFAULT_OPERATOR ='OR'#实际上没有影响... 

但它



所以,在我的情况下,它是通过子类化 SearchView 类来解决的。这是我项目的小片段:

 #views.py:
from haystack.views import SearchView

class PeriodicalSearchView(SearchView):
def get_results(self):

通过窗体获取结果
如果没有查询以

如果没有(self.form.is_valid()和self.form.cleaned_data ['q']):
return self.form.no_query_found( )

query = self.form.cleaned_data ['q']

words = iter(set(query.split()))
word = words。 next()
sqs = self.form.searchqueryset.filter(text = word)#实际上我还有一个字段...
用于单词:
sqs = sqs.filter_or (title = word).filter_or(text = word)

如果self.load_all:
sqs = sqs.load_all()

返回sqs

def __call __(self,request,template_name = None):

生成对th的实际响应e search。
依赖于内部的,可覆盖的方法来构造响应。

如果template_name:
self.template = template_name

返回超级(PeriodicalSearchView,self).__调用__(请求)

和urls.py

  #urls.py:
from .views import PeriodicalSearchView

urlpatterns = patterns('',
url(r'^ search / $',PeriodicalSearchView(template ='template_search) html'),
name ='haystack_search'),

就是这样。


I've recently set up solr and haystack to search one of my django models. I attempted to modify the default solr schema built by haystack to use the NGramTokenizerFactory:

<fieldType name="text" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="32" />
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
      <tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="32" />
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

I have a bunch of one or two word entries in my database which I would like to match against the user's query. So for example, I might have one object with title "dog" and another with title "cat". If the user searches for "dog cat" then I would like to return both the dog and cat objects for that query.

Similarly, if I search for "my cool website" I would like the field with "website" to be returned.

I tried using the solr admin interface to check to make sure my queries were getting matched. Everything seems okay there: : The issue is when I use the haystack default search interface to search for that same query:

As you can see, no results are found. I tried using KeywordFactory and a bunch of different solr configurations. If I'm not mistaken then the query should be getting matched. I'm not sure why haystack is coming up empty though.

Thanks for any help / suggestions on if this is the best way to go about such a search.

解决方案

Few month ago I worked with django-haystack and solr. I also had a problems with making some special queries to solr. Actually it should be solved by addng next line to settings.py:

HAYSTACK_DEFAULT_OPERATOR = 'OR' # actually has no effect...

But it does not work for me.

So, in my case it was solved by subclassing SearchView class. This is small snippet from my project:

# views.py:
from haystack.views import SearchView

class PeriodicalSearchView(SearchView):
  def get_results(self):
    """
    Fetches the results via the form.
    Returns an empty list if there's no query to search with.
    """
    if not (self.form.is_valid() and self.form.cleaned_data['q']):
        return self.form.no_query_found()

    query = self.form.cleaned_data['q']

    words = iter(set(query.split()))
    word = words.next()
    sqs = self.form.searchqueryset.filter(text=word) # actually I have one more field here...
    for word in words:
        sqs = sqs.filter_or(title=word).filter_or(text=word)

    if self.load_all:
        sqs = sqs.load_all()

    return sqs

  def __call__(self, request, template_name=None):
    """
    Generates the actual response to the search.
    Relies on internal, overridable methods to construct the response.
    """
    if template_name:
        self.template = template_name

    return super(PeriodicalSearchView, self).__call__(request)

And urls.py

# urls.py:
from .views import PeriodicalSearchView

urlpatterns = patterns('',
    url(r'^search/$', PeriodicalSearchView(template='template_search.html'), 
    name='haystack_search'),
)

And that's it.

这篇关于Haystack不返回Solr管理控制台亮点的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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