django-haystack

Haystack says “Model could not be found for SearchResult”

余生长醉 提交于 2019-12-18 14:52:45
问题 After updating my Django from 1.7 to 1.9, search engine, which is based on Haystack and Solr, stopped working. This is what I get: ./manage.py shell Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from haystack.query import SearchQuerySet >>> sqs = SearchQuerySet().all() >>>sqs[0].pk u'1' >>> sqs[0].text u'\u06a9\u0627\u0645\u0631\u0627\u0646 \u0647\u0645\u062a\u200c\u067e\u0648

Django-Haystack with Solr contains search

孤街醉人 提交于 2019-12-18 12:34:08
问题 I am using haystack within a project using solr as the backend. I want to be able to perform a contains search, similar to the Django .filter(something__contains="...") The __startswith option does not suit our needs as it, as the name suggests, looks for words that start with the string. I tried to use something like *keyword* but Solr does not allow the * to be used as the first character Thanks. 回答1: To get "contains" functionallity you can use: <tokenizer class="solr

Search for multiple words elasticsearch haystack

余生长醉 提交于 2019-12-14 03:44:35
问题 I used to django, haystack and elasticsearch. My search_index.py: from haystack import indexes from models import Advertisement class AdvertisementIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) make = indexes.CharField() section = indexes.CharField() subcategory = indexes.CharField() content = indexes.CharField(model_attr='content') images = indexes.CharField(model_attr='images') def get_model(self): return Advertisement def index

Elasticsearch: do exact searches where the query contains special characters like '#'

一个人想着一个人 提交于 2019-12-13 20:37:53
问题 Get the results of only those documents which contain '#test' and ignore the documents that contain just 'test' in elasticsearch 回答1: People may gripe at you about this question, so I'll note that it was in response to my comment on this post. You're probably going to want to read up on analysis in Elasticsearch, as well as match queries versus term queries. Anyway, the convention here is to use a .raw sub-field on a string field. That way, if you want to do searches involving analysis, you

Haystack with Whoosh- Search Results Not Redirecting

时间秒杀一切 提交于 2019-12-13 18:04:00
问题 I successfully installed whoosh and made it work with Haystack. Things are working fine but I'm facing one problem which is; after searching for a keyword and it print out the results, when I click on the result(title), It won't redirect me to the page of the keyword I clicked on, it's just static. I tried adding a get_absolute_url method. Yet it's not working. What I'm I missing? Models class Meek(models.Model): user=models.ForeignKey(User) title=models.CharField(max_length=250, unique=True)

Django Haystack index on multiple fields from same model

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:28:51
问题 I am trying to embed elasticsearch in my Django app using django-haystack . I am trying to implement a user search. My user model is this: class MyUser(AbstractBaseUser): username = models.CharField(max_length=255, unique=True) name = models.CharField(max_length=63, blank=True) email = models.EmailField(blank=True, unique=True) status = models.CharField(max_length=255, blank=True, null=True) is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=True) joined =

Django Haystack Search by Django Model PK

北城余情 提交于 2019-12-13 04:33:39
问题 Is there an easy hook for looking up Haystack results by Django model PK? Something like (this doesn't work) SearchQuerySet().filter(pk=12) The alternative is that I would add an explicit field to the SearchIndex for the model pk, but that seems wasteful, since the queryset results from Haystack contain the underlying django model pk 回答1: Following worked for me: SearchQuerySet().models(Product).filter(django_id='10229') 回答2: In Haystack you might have a lot of different Apps and Models, thus

How can I use a HayStack form that contains a ChoiceField within a Context Processor(Django 1.3)?

限于喜欢 提交于 2019-12-13 04:25:36
问题 I have a pretty simple Haystack form that looks just like this: class BasicSearchForm(SearchForm): category_choices = Category.objects.all() category_tuples = tuple([(c.id, c.name) for c in category_choices]) category = forms.ChoiceField(choices=category_tuples, required=False) def search(self): sqs = super(BasicSearchForm, self).search() if self.cleaned_data['category']: if self.cleaned_data['category'] != "*": sqs = sqs.filter(category__id=self.cleaned_data['category']) return sqs I then

“No results found” on Django Haystack ElasticSearch

China☆狼群 提交于 2019-12-12 17:01:52
问题 Failed to query Elasticsearch using '*:*': TransportError(400,u'parsing_exception', u'no [query] registered for [filtered]') Traceback (most recent call last): File "C:\Python27\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 524, in search _source=True) File "C:\Python27\lib\site-packages\elasticsearch\client\utils.py", line 71, in _wrapped return func(*args, params=params, **kwargs) File "C:\Python27\lib\site-packages\elasticsearch\client\__init__.py", line 569, in

Django-haystack with xapian engine: can't execute update_index if model has ManyToManyField

 ̄綄美尐妖づ 提交于 2019-12-12 10:49:23
问题 After upgrading django to 1.7 I can't execute management command update_index. Traceback (most recent call last): File "/opt/pycharm-3.4.1/helpers/pydev/pydevd.py", line 1733, in <module> debugger.run(setup['file'], None, None) File "/opt/pycharm-3.4.1/helpers/pydev/pydevd.py", line 1226, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/home/tochium/projects/povary/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/tochium/projects