I'm trying to add a module wide search for my App and found haystack-search. I took whoosh to store the search information.
我正在尝试为我的应用程序添加模块范围的搜索,并找到了haystack-search。我带着嗖嗖声来存储搜索信息。
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"). When I search for "testdomain" I will not get any results but when I search for "tesdomain.com" I'll get some results. Now I want to get the results (which I get when "testdomain.com" is entered) when I enter "testdomain". Any ideas how this can be done?
我遇到的问题是存储和电子邮件地址(“test@testdomain.com”)的字段。当我搜索“testdomain”时,我不会得到任何结果但是当我搜索“tesdomain.com”时,我会得到一些结果。现在我想得到结果(当我输入“testdomain.com”时我得到的结果)当我输入“testdomain”时。有什么想法可以做到这一点?
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
1 个解决方案
#1
1
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)创建自己的url-route
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")),
#1
1
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)创建自己的url-route
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")),