源自: 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_commandrun_module(manage_file, None, '__main__', True)File "C:\Programs\Miniconda3\envs\djg3211env\lib\runpy.py", line 210, in run_modulereturn _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_codeexec(code, run_globals)File "D:\WebProjects/aisitev\manage.py", line 22, in <module>main()File "D:\WebProjects/aisitev\manage.py", line 18, in mainexecute_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_lineutility.execute()File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 413, in executeself.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_argvself.execute(*args, **cmd_options)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 398, in executeoutput = self.handle(*args, **options)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\rebuild_index.py", line 65, in handlecall_command("update_index", **update_options)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\__init__.py", line 181, in call_commandreturn command.execute(*args, **defaults)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\django\core\management\base.py", line 398, in executeoutput = self.handle(*args, **options)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 297, in handleself.update_backend(label, using)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 342, in update_backendmax_pk = do_update(File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\management\commands\update_index.py", line 119, in do_updatebackend.update(index, current_qs, commit=commit)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 215, in updateprepped_data = self._prepare_object(index, obj)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\backends\elasticsearch_backend.py", line 196, in _prepare_objectreturn index.full_prepare(obj)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\indexes.py", line 235, in full_prepareself.prepared_data = self.prepare(obj)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\indexes.py", line 226, in prepareself.prepared_data[field.index_fieldname] = field.prepare(obj)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 236, in preparereturn self.convert(super().prepare(obj))File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 105, in preparevalues = self.resolve_attributes_lookup(current_objects, attrs)File "C:\Programs\Miniconda3\envs\djg3211env\lib\site-packages\haystack\fields.py", line 157, in resolve_attributes_lookupvalues.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_CODEif currentLngCode == lngCode: kwdkey = "text" kwargs[kwdkey] = kwdelse:kwdkey = "text_%s" % currentLngCodekwargs[kwdkey] = kwdif 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 Answer

ActiveOldestScore

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

  • 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. 

    – Rafe Hatfield

    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") 

    – Rafe Hatfield

    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)

    – Rafe Hatfield

    May 17 '13 at 17:52

Show 1 more comment

django-haystack 对 多对多字段( ManyToManyField )进行索引相关推荐

  1. Django之ORM(多对多)

    一.ManyToManyField 1.class RelatedManager "关联管理器"是在一对多或者多对多的关联上下文中使用的管理器. 它存在于下面两种情况: 外键关系的 ...

  2. django 模型类的常见字段约束,以及filter 过滤和查询

    null 不设置时默认设置为False.设置为True时,数据库表字段中将存入NULL的记录. null和blank组合使用,null=True,blank=True,表示该字段可以为空 blank ...

  3. django中Models常用的字段及属性介绍

    模型类 介绍 每个模型类都可以被映射为数据库中的一个数据表,类类属性被映射为数据字段,除此之外,数据库表的主键.外键.约束等也通过类属性完成定义 模型类属性 属性 描述 AutoField AutoF ...

  4. Django模型系统的常用字段和字段参数

    常用字段 AutoField:int自增列,必须填入参数 primary_key=True.当model中如果没有自增列,则自动会创建一个列名为id的列. IntegerField:一个整数类型,范围 ...

  5. Diango博客--22.Django Haystack 全文检索与关键词高亮

    文章目录 1. Django Haystack 简介 2. 安装 django-haystack和elasticsearch 2 3. 构建容器来运行 elasticsearch 服务 4. 配置 H ...

  6. django haystack一次使用总结

    记一次django_haystack的坑 使用的是 whoosh 和jieba : pip install whoosh pip install jieba 首先在django,导入我们的haysta ...

  7. Django开发个人博客网站——19、通过Django Haystack实现搜索功能(上)

    该博客最开始采用的模板是并不包括搜索功能的,在主页只有主页.归档和分类三个部分.最后博主自己添加了搜索框,不过其实不太想让大家使用这个功能,因此将搜索框隐藏了,只有再点击搜索时,才会显现出来.但是这个 ...

  8. django+haystack+elasticsearch优化查询效率

    django+haystack+elasticsearch优化查询效率 背景 安装环境 配置 1.在settings中的配置 2.在子应用下创建索引文件 3.指定索引模板文件 4.使用命令创建索引 索 ...

  9. Django+haystack+jieba进行全文检索

    最近,在做一个全文检索的功能,找了两个方案: mysql的全文检索索引 优点:配置起来简单,改mysql配置即可 缺点:无法在django使用模型生成,查询语句也无法使用orm,只能用原生sql 基于 ...

  10. Django的model中日期字段设置默认值的问题

    之前写过这样一个model: class MonthlyFeeMember(models.Model):worker = models.ForeignKey(Student, verbose_name ...

最新文章

  1. -Linux基础知识2 -文件系统的操作 压缩,解压缩
  2. jquery引入标红叉
  3. ANN:DNN结构演进History—RNN
  4. python3.x : 安装opencv
  5. [转]Nant daily build实践
  6. Python数据结构实战—栈(Stack)
  7. Luogu P1967 货车运输 倍增+最大生成树
  8. python写彩票程序30选7_python实现彩票系统
  9. Kotlin的一点学习资源
  10. android pt分区,[玩机技巧之Android篇]系统分区之System、Data、cache 来自 淡影寒...
  11. 多易教育KAFKA实战(3)-java消费者客户端API示例代码
  12. 使用getsockopt函数判断TCP/IP异常
  13. Unity中的资源管理-几种常见的序列化方式
  14. 点阵字库显示系列之二:GB2312点阵字库显示
  15. 如何快速提升新站点的外链数量
  16. MySQL数据库程序设计(二)
  17. html设置播放器位置,【关于Flash网页播放器的定位与浮动的HTML代码】
  18. CQUPT Sre 2022 winter assessment pwn static_debug
  19. django 允许post请求
  20. 聊天记录 --- 如何维护标准版本以及N个拓展版本

热门文章

  1. 检查Telerik UI以使用UWP作为PVS-Studio的入门方法
  2. linux pvdisplay PE,linux中的pvmove,pvremove,pvs,pvscan
  3. CM13.0代码下载
  4. 菜鸟日记(yzy) 微信公众号网页的开发基础(微信接口调用)
  5. 帝恩思:网站被劫持跳转怎么办?
  6. linux上安装NVIDIA显卡驱动以及深度学习需要的cudn、cudnn、pytorch
  7. python处理can协议文件_用Python处理CAN数据库
  8. idea 提示Expecting newline or semicolon解决办法
  9. matlab主成分分析代码
  10. Typo in static class property declarationeslint