Navigation

    Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

    Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

    开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

    如果您登录系统碰到问题,请在微信公众号留言:

    Full text search FTS 全文检索模块移植到Odoo 8.0绿色版经验及后续需求

    Odoo 开发与实施交流
    2
    3
    4532
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fisher last edited by

      有感于新odoo的论坛,文档管理,邮件等含大量文本内容的搜索标准功能中只能用SQL中的Like加通配符% ,也就是说只能模糊查询特定字符串,而不能真正像搜索引擎那样用时搜索多个关键字。幸好7.0版本中有个全文检索的模块。下载下来经过一番折腾,终于在绿色版的8.0上装上了,也基本能用了,现分享一些心得,也提出一些改善需求
      要改2个文件,3 个地方
      1 fts_base下的_openerp_.ini
      里的update_xml 改为data, 变这样 'data': ["fts_proxy.xml", 'wizard/fts_config.xml'],

      2.fts_base.py
      2.1 因为pool里没有DB属性了,第40行 去掉.DB, 变成这样        cr = self.pool.cursor()
      2.2 因为使用to_tsquery时如果输入多个关键字其中有空格的话,系统会报错,查询字符串不会法, 改为 plainto_tsquery就可以了(fts_proxy里也要改)

      除了fts_base,我还安装了fts_document,fts_mail,装上后要重启系统,就会在setting configure 下多一个full text 的配置菜单,点那个对应的生成索引按钮,等一会儿后在对应的ir_attachment,mail_message表里面会增加一个存放索引字串的栏位,一个对应的索引和触发器,就可以去message旁边那个full text search顶层菜单上搜索已启用全文搜索功能的内容了(正如FTS文档所说,可以将实现跨模块统一全文检索,类似ERP内的google)。

      昨晚折腾了很久,终于初步将此全文检索功能扩展到论坛模块,也就是直接在论坛模块就可实现全文搜索问题,答案及评论。
      主要的思路及做法如下
      1.继承fts_base,在forum_post表上增加全文检索栏位
      class Fts_Forum(fts_base):
          _model = 'forum.post'
          _indexed_column = 'content'
          _title_column = 'name'
      2.继承forum post,扩展search函数,获取搜索文本,参考fts base直接使用全文检索的SQL语句取得ID清单,
      特别的地方有两个,
          1.是默认情况下因为传到search函数中的filter已经有parent_id = blank的内容(此类记录表示是回复answer),需要去掉这种条件,不然就搜不到答案里的内容,
          2.论坛的评论comment并不保存在forum_post表里,而是保存在mail_message里的,所以在search函数中如果要同时搜索评论,还要去mail_message表中全文检索一下,再合并。
      代码即文档,见附件


      目前的问题
      1. 索引不支持中文,在windows 7上还不知道怎么安装zhparser
      2. fts base的全文检索出来的清单不支持双击跳转到显示对应的resource,如文档,邮件或论坛
      3. 还需要增加对问题标题及邮件主题的全文检索
      4. 其实可以考虑做成通用的全文检索,增加ORM定义时一个全文检索栏位属性,最终实现在定义search view时可以使用全文检索栏位,ORM可以自动转换为对应的全文检索SQL语句,用这样的方式使全文检索变成ORM的一部分。

      注,本人非专职程序员,大家多提意见,多交流。

      1 Reply Last reply Reply Quote 0
      • 2
        222411 last edited by

        在 8.0正式版安装 这三个addons 后 后台的 菜单上的搜索没问题,
        前台website的 forums 模块上的论坛一搜索出现 500错误


        Error 

        Error message:
        'NoneType' object has no attribute '_columns'

        ⁠



        Traceback 


        Traceback (most recent call last):
          File "/home/lv/g101/source/addons/website/models/ir_http.py", line 204, in _handle_exception
            response = super(ir_http, self)._handle_exception(exception)
          File "/home/lv/g101/source/openerp/addons/base/ir/ir_http.py", line 100, in _handle_exception
            return request._handle_exception(exception)
          File "/home/lv/g101/source/openerp/http.py", line 596, in _handle_exception
            return super(HttpRequest, self)._handle_exception(exception)
          File "/home/lv/g101/source/openerp/addons/base/ir/ir_http.py", line 126, in _dispatch
            result = request.dispatch()
          File "/home/lv/g101/source/openerp/http.py", line 614, in dispatch
            r = self._call_function(**self.params)
          File "/home/lv/g101/source/openerp/http.py", line 283, in _call_function
            return checked_call(self.db, *args, **kwargs)
          File "/home/lv/g101/source/openerp/service/model.py", line 113, in wrapper
            return f(dbname, *args, **kwargs)
          File "/home/lv/g101/source/openerp/http.py", line 280, in checked_call
            return self.endpoint(*a, **kw)
          File "/home/lv/g101/source/openerp/http.py", line 733, in call
            return self.method(*args, **kw)
          File "/home/lv/g101/source/openerp/http.py", line 376, in response_wrap
            response = f(*args, **kw)
          File "/home/lv/g101/source/addons/website_forum/controllers/main.py", line 106, in questions
            question_count = Post.search(cr, uid, domain, count=True, context=context)
          File "/home/lv/g101/source/openerp/api.py", line 237, in wrapper
            return old_api(self, *args, **kwargs)
          File "/home/lv/g101/source/openerp/addons/fts_forum/fts_forum.py", line 154, in search
            filters = self._get_filter_expression(cr, uid, args, context).to_sql()
          File "/home/lv/g101/source/openerp/api.py", line 237, in wrapper
            return old_api(self, *args, **kwargs)
          File "/home/lv/g101/source/openerp/addons/fts_forum/fts_forum.py", line 118, in _get_filter_expression
            args = get_applicable_args(expression.normalize_domain(args), 0)[0]
          File "/home/lv/g101/source/openerp/addons/fts_forum/fts_forum.py", line 106, in get_applicable_args
            op1 = get_applicable_args(args, index + 1)
          File "/home/lv/g101/source/openerp/addons/fts_forum/fts_forum.py", line 106, in get_applicable_args
            op1 = get_applicable_args(args, index + 1)
          File "/home/lv/g101/source/openerp/addons/fts_forum/fts_forum.py", line 106, in get_applicable_args
            op1 = get_applicable_args(args, index + 1)
          File "/home/lv/g101/source/openerp/addons/fts_forum/fts_forum.py", line 92, in get_applicable_args
            args[index][0] in orm_model._columns or
        AttributeError: 'NoneType' object has no attribute '_columns'


        想写个产品tfs搜索...

        1 Reply Last reply Reply Quote 0
        • First post
          Last post