源自: Django Haystack and Taggit - Stack Overflow
我的错误栈如下:
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm\plugins\python\helpers\pycharm\django_manage.py", line 52, in <module>
run_command()
File "D:\Program Files\JetBrains\PyCharm\plugins\python\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\WebProjects/aisitev\manage.py", line 22, in <module>
main()
File "D:\WebProjects/aisitev\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\rebuild_index.py", line 65, in handle
call_command("update_index", **update_options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 181, in call_command
return command.execute(*args, **defaults)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 297, in handle
self.update_backend(label, using)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 342, in update_backend
max_pk = do_update(
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 119, in do_update
backend.update(index, current_qs, commit=commit)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 215, in update
prepped_data = self._prepare_object(index, obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 196, in _prepare_object
return index.full_prepare(obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\indexes.py", line 235, in full_prepare
self.prepared_data = self.prepare(obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\indexes.py", line 226, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 236, in prepare
return self.convert(super().prepare(obj))
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 105, in prepare
values = self.resolve_attributes_lookup(current_objects, attrs)
File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 157, in resolve_attributes_lookup
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'
Is there anybody using Django taggit with haystack? How can we make tags field indexable by haystack?
I have tried:
class EventIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField( model_attr='descr_en', document=True, use_template=True)
text_tr = indexes.CharField(model_attr='descr_tr')
tags = indexes.MultiValueField()
def prepare_text(self, obj):
return '%s %s' % (obj.title_en, obj.descr_en)
def prepare_text_tr(self, obj):
return '%s %s' % (obj.title_tr, obj.descr_tr)
def prepare_tags(self, obj):
return [tag.name for tag in obj.tags.all()]
def get_model(self):
return Event
And i am using a custom searchqueryset for multilingual search :
class MlSearchQuerySet(SearchQuerySet):
def filter(self, **kwargs):
"""Narrows the search based on certain attributes and the default operator."""
if 'content' in kwargs:
kwd = kwargs.pop('content')
currentLngCode = str(get_language())
lngCode = settings.LANGUAGE_CODE
if currentLngCode == lngCode:
kwdkey = "text"
kwargs[kwdkey] = kwd
else:
kwdkey = "text_%s" % currentLngCode
kwargs[kwdkey] = kwd
if getattr(settings, 'HAYSTACK_DEFAULT_OPERATOR', DEFAULT_OPERATOR) == 'OR':
return self.filter_or(**kwargs)
else:
return self.filter_and(**kwargs)
Follow
asked May 17 '13 at 16:19
1,1011313 silver badges3737 bronze badges
1 Answer
8
To get the tags into the search index we added them to our content template file eg
{{ object.title }}
{{ object.body }}
{% for tag in object.tags.all %} {{ tag.name }} {% endfor %}
{{ object.user.get_full_name }}
We also include it as a MultiValueField
tags = indexes.MultiValueField()
def prepare_tags(self, obj):
return [tag.name for tag in obj.tags.all()]
Haven't had success trying to make boost work in either case, but the search definitely indexes them correctly.
Follow
answered May 17 '13 at 17:03
59511 gold badge55 silver badges1010 bronze badges
- I have updated my question in order to represent my real code structure better. Because i am not getting any tags related search results with the ways you suggest...
– ratata
May 17 '13 at 17:23 - can you include your text template? if your tags are in there they should get indexed, they will be treated the same as any other content in your template. May 17 '13 at 17:28
- in 'event_text.txt' i have : {{ object.title }} {{ object.descr }} {% for tag in object.tags.all %} {{ tag.name }} {% endfor %}
– ratata
May 17 '13 at 17:30 - hmm seems ok to me - sorry to ask what may be a silly question, but just to make sure; you are reindexing after each change, correct? (ie run "python manage.py rebuild_index") May 17 '13 at 17:38
-
1
ah you probably also need to add tags to your prepare_text method - not confident on that but seems like its missing (still new to haystack, you're past my basic knowledge now) May 17 '13 at 17:52