简体   繁体   English

django haystack模块使用whoosh搜索

[英]django haystack module search with whoosh

I'm trying to add a module wide search for my App and found haystack-search. 我正在尝试为我的App添加模块范围的搜索,并发现了haystack-search。 I took whoosh to store the search information. 我带飞快移动来存储搜索信息。

I've configured my search as told in the docs and already can find results. 我已经按照文档中的说明配置了搜索,并且已经可以找到结果了。

The problem I have is a field which stores and email-address ("test@testdomain.com"). 我的问题是存储和电子邮件地址(“ test@testdomain.com”)的字段。 When I search for "testdomain" I will not get any results but when I search for "tesdomain.com" I'll get some results. 当我搜索“ testdomain”时,不会得到任何结果,但是当我搜索“ tesdomain.com”时,我会得到一些结果。 Now I want to get the results (which I get when "testdomain.com" is entered) when I enter "testdomain". 现在,当我输入“ testdomain”时,我想获得结果(输入“ testdomain.com”时得到的结果)。 Any ideas how this can be done? 任何想法如何做到这一点?

Did someone ever posted to the mailinglist of haystack? 有没有人张贴到干草堆的邮件列表中? For me it is not possible to post even if I'm a member of the google-group. 对我来说,即使我是google-group的成员,也无法发布。

regards Martin 问候马丁

Now I have the answer for the problem. 现在,我已经找到了问题的答案。 The standard search shipped with haystack does not support searching by substrings. haystack附带的标准搜索不支持按子字符串搜索。

I createt my own app (mysearch) for searching which will use haystacksearch 我创建了自己的应用程序(mysearch)进行搜索,它将使用haystacksearch

What you have to do is to create your own SearchForm (mysearch/forms.py) 您要做的就是创建自己的SearchForm(mysearch / forms.py)

from django import forms
from haystack.forms import ModelSearchForm
from haystack.query import SearchQuerySet

class AutocompleteSearchForm(ModelSearchForm):

  def search(self):
    if not self.is_valid():
      return self.no_query_found()

    if not self.cleaned_data.get('q'):
      return self.no_query_found()

    sqs = self.searchqueryset.filter(autocompletetext=self.cleaned_data.get('q'))

    sqs = sqs.models(*self.get_models())

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

    return sqs

Then you have to create your own url-route using your own SearchForm (mysearch/urls.py) 然后,您必须使用自己的SearchForm(mysearch / urls.py)创建自己的网址路由

from django.conf.urls.defaults import *
from haystack.forms import ModelSearchForm
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from forms import AutocompleteSearchForm

sqs = SearchQuerySet()

# Without threading...
urlpatterns = patterns('haystack.views',
  url(r'^$', SearchView(searchqueryset=sqs, form_class=AutocompleteSearchForm), name='haystack_search'),
)

in your projects urls.py use 在您的项目urls.py中使用

url(r"^search/", include("mysearch.urls", namespace="Search")),

instead of 代替

url(r'^search/', include('haystack.urls', namespace="Search")),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM