源自: 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 FilesJetBrainsPyCharmpluginspythonhelperspycharmdjango_manage.py", line 52, inrun_command() File "D:Program FilesJetBrainsPyCharmpluginspythonhelperspycharmdjango_manage.py", line 46, in run_command run_module(manage_file, None, '__main__', True) File "C:ProgramsMiniconda3envsdjg3211envlibrunpy.py", line 210, in run_module return _run_module_code(code, init_globals, run_name, mod_spec) File "C:ProgramsMiniconda3envsdjg3211envlibrunpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:ProgramsMiniconda3envsdjg3211envlibrunpy.py", line 87, in _run_code exec(code, run_globals) File "D:WebProjects/aisitevmanage.py", line 22, in main() File "D:WebProjects/aisitevmanage.py", line 18, in main execute_from_command_line(sys.argv) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packagesdjangocoremanagement__init__.py", line 419, in execute_from_command_line utility.execute() File "C:ProgramsMiniconda3envsdjg3211envlibsite-packagesdjangocoremanagement__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packagesdjangocoremanagementbase.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packagesdjangocoremanagementbase.py", line 398, in execute output = self.handle(*args, **options) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackmanagementcommandsrebuild_index.py", line 65, in handle call_command("update_index", **update_options) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packagesdjangocoremanagement__init__.py", line 181, in call_command return command.execute(*args, **defaults) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packagesdjangocoremanagementbase.py", line 398, in execute output = self.handle(*args, **options) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackmanagementcommandsupdate_index.py", line 297, in handle self.update_backend(label, using) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackmanagementcommandsupdate_index.py", line 342, in update_backend max_pk = do_update( File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackmanagementcommandsupdate_index.py", line 119, in do_update backend.update(index, current_qs, commit=commit) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackbackendselasticsearch_backend.py", line 215, in update prepped_data = self._prepare_object(index, obj) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackbackendselasticsearch_backend.py", line 196, in _prepare_object return index.full_prepare(obj) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackindexes.py", line 235, in full_prepare self.prepared_data = self.prepare(obj) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackindexes.py", line 226, in prepare self.prepared_data[field.index_fieldname] = field.prepare(obj) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackfields.py", line 236, in prepare return self.convert(super().prepare(obj)) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackfields.py", line 105, in prepare values = self.resolve_attributes_lookup(current_objects, attrs) File "C:ProgramsMiniconda3envsdjg3211envlibsite-packageshaystackfields.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)
djangodjango-haystack
Share
Follow
edited May 17 '13 at 17:19
asked May 17 '13 at 16:19
ratata
1,1011313 silver badges3737 bronze badges
Add a comment
1 AnswerActiveOldestScore
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.
Share
Follow
answered May 17 '13 at 17:03
Rafe Hatfield
59511 gold badge55 silver badges1010 bronze badges
– ratata
May 17 '13 at 17:23– Rafe Hatfield
May 17 '13 at 17:28– ratata
May 17 '13 at 17:30– Rafe Hatfield
May 17 '13 at 17:381
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)– Rafe Hatfield
May 17 '13 at 17:52Show 1 more comment
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)