base_search_fuzzy: Migration to 11.0
parent
958d0eef45
commit
29b7aa886e
|
@ -1,107 +1 @@
|
||||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
This file is going to be generated by oca-gen-addon-readme.
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
|
||||||
:alt: License: AGPL-3
|
|
||||||
|
|
||||||
=========================
|
|
||||||
PostgreSQL Trigram Search
|
|
||||||
=========================
|
|
||||||
|
|
||||||
This addon provides the ability to create GIN or GiST indexes of char and text
|
|
||||||
fields and also to use the search operator `%` in search domains. Currently
|
|
||||||
this module doesn't change the backend search or anything else. It provides
|
|
||||||
only the possibilty to perfrom the fuzzy search for external addons.
|
|
||||||
|
|
||||||
|
|
||||||
Installation
|
|
||||||
============
|
|
||||||
|
|
||||||
#. The PostgreSQL extension ``pg_trgm`` should be available. In debian based
|
|
||||||
distribution you have to install the `postgresql-contrib` module.
|
|
||||||
#. Install the ``pg_trgm`` extension to your database or give your postgresql
|
|
||||||
user the ``SUPERUSER`` right (this allows the odoo module to install the
|
|
||||||
extension to the database).
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
=============
|
|
||||||
|
|
||||||
If the odoo module is installed:
|
|
||||||
|
|
||||||
#. You can define ``GIN`` and ``GiST`` indexes for `char` and `text` via
|
|
||||||
`Settings -> Database Structure -> Trigram Index`. The index name will
|
|
||||||
automatically created for new entries.
|
|
||||||
|
|
||||||
|
|
||||||
Usage
|
|
||||||
=====
|
|
||||||
|
|
||||||
#. You can create an index for the `name` field of `res.partner`.
|
|
||||||
#. In the search you can use:
|
|
||||||
|
|
||||||
``self.env['res.partner'].search([('name', '%', 'Jon Miller)])``
|
|
||||||
|
|
||||||
#. In this example the function will return positive result for `John Miller` or
|
|
||||||
`John Mill`.
|
|
||||||
|
|
||||||
#. You can tweak the number of strings to be returned by adjusting the set limit
|
|
||||||
(default: 0.3). NB: Currently you have to set the limit by executing the
|
|
||||||
following SQL statment:
|
|
||||||
|
|
||||||
``self.env.cr.execute("SELECT set_limit(0.2);")``
|
|
||||||
|
|
||||||
#. Another interesting feature is the use of ``similarity(column, 'text')``
|
|
||||||
function in the ``order`` parameter to order by similarity. This module just
|
|
||||||
contains a basic implementation which doesn't perform validations and has to
|
|
||||||
start with this function. For example you can define the function as
|
|
||||||
followed:
|
|
||||||
|
|
||||||
``similarity(%s.name, 'John Mil') DESC" % self.env['res.partner']._table``
|
|
||||||
|
|
||||||
For further questions read the Documentation of the
|
|
||||||
`pg_trgm <https://www.postgresql.org/docs/current/static/pgtrgm.html>`_ module.
|
|
||||||
|
|
||||||
Known issues / Roadmap
|
|
||||||
======================
|
|
||||||
|
|
||||||
* Modify the general search parts (e.g. in tree view or many2one fields)
|
|
||||||
* add better `order by` handling
|
|
||||||
|
|
||||||
|
|
||||||
Bug Tracker
|
|
||||||
===========
|
|
||||||
|
|
||||||
Bugs are tracked on `GitHub Issues
|
|
||||||
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
|
|
||||||
check there if your issue has already been reported. If you spotted it first,
|
|
||||||
help us smash it by providing detailed and welcomed feedback.
|
|
||||||
|
|
||||||
Credits
|
|
||||||
=======
|
|
||||||
|
|
||||||
Images
|
|
||||||
------
|
|
||||||
|
|
||||||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
------------
|
|
||||||
|
|
||||||
* Christoph Giesel <https://github.com/christophlsa>
|
|
||||||
* Jordi Ballester <jordi.ballester@eficent.com>
|
|
||||||
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
|
|
||||||
* Dave Lasley <dave@laslabs.com>
|
|
||||||
|
|
||||||
Maintainer
|
|
||||||
----------
|
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/logo.png
|
|
||||||
:alt: Odoo Community Association
|
|
||||||
:target: https://odoo-community.org
|
|
||||||
|
|
||||||
This module is maintained by the OCA.
|
|
||||||
|
|
||||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
|
||||||
mission is to support the collaborative development of Odoo features and
|
|
||||||
promote its widespread use.
|
|
||||||
|
|
||||||
To contribute to this module, please visit https://odoo-community.org.
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from . import models
|
from . import models
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
{
|
{
|
||||||
'name': "Fuzzy Search",
|
'name': "Fuzzy Search",
|
||||||
'summary': "Fuzzy search with the PostgreSQL trigram extension",
|
'summary': "Fuzzy search with the PostgreSQL trigram extension",
|
||||||
'category': 'Uncategorized',
|
'category': 'Uncategorized',
|
||||||
'version': '10.0.1.1.0',
|
'version': '11.0.1.0.0',
|
||||||
'website': 'https://odoo-community.org/',
|
'website': 'https://odoo-community.org/',
|
||||||
'author': 'bloopark systems GmbH & Co. KG, '
|
'author': 'bloopark systems GmbH & Co. KG, '
|
||||||
'Eficent, '
|
'Eficent, '
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
# Translation of Odoo Server.
|
|
||||||
# This file contains the translation of the following modules:
|
|
||||||
# * base_search_fuzzy
|
|
||||||
#
|
|
||||||
msgid ""
|
|
||||||
msgstr ""
|
|
||||||
"Project-Id-Version: Odoo Server 10.0alpha1\n"
|
|
||||||
"Report-Msgid-Bugs-To: \n"
|
|
||||||
"POT-Creation-Date: 2016-06-24 08:47+0000\n"
|
|
||||||
"PO-Revision-Date: 2016-06-24 08:47+0000\n"
|
|
||||||
"Last-Translator: <>\n"
|
|
||||||
"Language-Team: \n"
|
|
||||||
"MIME-Version: 1.0\n"
|
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
|
||||||
"Content-Transfer-Encoding: \n"
|
|
||||||
"Plural-Forms: \n"
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: help:trgm.index,index_type:0
|
|
||||||
msgid "Cite from PostgreSQL documentation: \"As a rule of thumb, a GIN index is faster to search than a GiST index, but slower to build or update; so GIN is better suited for static data and GiST for often-updated data.\""
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,create_uid:0
|
|
||||||
msgid "Created by"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,create_date:0
|
|
||||||
msgid "Created on"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,field_id:0
|
|
||||||
msgid "Field"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: selection:trgm.index,index_type:0
|
|
||||||
msgid "GIN"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: selection:trgm.index,index_type:0
|
|
||||||
msgid "GiST"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,id:0
|
|
||||||
msgid "ID"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,index_name:0
|
|
||||||
msgid "Index Name"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,index_type:0
|
|
||||||
msgid "Index Type"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,write_uid:0
|
|
||||||
msgid "Last Updated by"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: field:trgm.index,write_date:0
|
|
||||||
msgid "Last Updated on"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: model:ir.model,name:base_search_fuzzy.model_ir_model
|
|
||||||
msgid "Models"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: help:trgm.index,index_name:0
|
|
||||||
msgid "The index name is automatically generated like fieldname_indextype_idx. If the index already exists and the index is located in the same table then this index is resused. If the index is located in another table then a number is added at the end of the index name."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: model:ir.actions.act_window,name:base_search_fuzzy.trgm_index_action
|
|
||||||
#: model:ir.ui.menu,name:base_search_fuzzy.trgm_index_menu
|
|
||||||
#: view:trgm.index:base_search_fuzzy.trgm_index_view_form
|
|
||||||
#: view:trgm.index:base_search_fuzzy.trgm_index_view_tree
|
|
||||||
msgid "Trigram Index"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: help:trgm.index,field_id:0
|
|
||||||
msgid "You can either select a field of type \"text\" or \"char\"."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#. module: base_search_fuzzy
|
|
||||||
#: code:addons/base_search_fuzzy/models/trgm_index.py:123
|
|
||||||
#, python-format
|
|
||||||
msgid "The pg_trgm extension does not exists or cannot be installed."
|
|
||||||
msgstr ""
|
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from . import ir_model
|
from . import ir_model
|
||||||
from . import trgm_index
|
from . import trgm_index
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# Copyright 2017 LasLabs Inc.
|
# Copyright 2017 LasLabs Inc.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
import logging
|
import logging
|
||||||
|
@ -43,7 +42,7 @@ def patch_leaf_trgm(method):
|
||||||
if left in model._fields:
|
if left in model._fields:
|
||||||
params = str(right)
|
params = str(right)
|
||||||
|
|
||||||
if isinstance(params, basestring):
|
if isinstance(params, str):
|
||||||
params = [params]
|
params = [params]
|
||||||
return query, params
|
return query, params
|
||||||
elif operator == 'inselect':
|
elif operator == 'inselect':
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# Copyright 2017 LasLabs Inc.
|
# Copyright 2017 LasLabs Inc.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
import logging
|
import logging
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
If the odoo module is installed:
|
||||||
|
|
||||||
|
#. You can define ``GIN`` and ``GiST`` indexes for `char` and `text` via
|
||||||
|
`Settings -> Database Structure -> Trigram Index`. The index name will
|
||||||
|
automatically created for new entries.
|
|
@ -0,0 +1,5 @@
|
||||||
|
* Christoph Giesel <https://github.com/christophlsa>
|
||||||
|
* Jordi Ballester <jordi.ballester@eficent.com>
|
||||||
|
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
|
||||||
|
* Dave Lasley <dave@laslabs.com>
|
||||||
|
* Vicent Cubells <vicent.cubells@tecnativa.com>
|
|
@ -0,0 +1,4 @@
|
||||||
|
This addon provides the ability to create GIN or GiST indexes of char and text
|
||||||
|
fields and also to use the search operator `%` in search domains. Currently
|
||||||
|
this module doesn't change the backend search or anything else. It provides
|
||||||
|
only the possibilty to perfrom the fuzzy search for external addons.
|
|
@ -0,0 +1,5 @@
|
||||||
|
#. The PostgreSQL extension ``pg_trgm`` should be available. In debian based
|
||||||
|
distribution you have to install the `postgresql-contrib` module.
|
||||||
|
#. Install the ``pg_trgm`` extension to your database or give your postgresql
|
||||||
|
user the ``SUPERUSER`` right (this allows the odoo module to install the
|
||||||
|
extension to the database).
|
|
@ -0,0 +1,2 @@
|
||||||
|
* Modify the general search parts (e.g. in tree view or many2one fields)
|
||||||
|
* Add better `order by` handling
|
|
@ -0,0 +1,24 @@
|
||||||
|
#. You can create an index for the `name` field of `res.partner`.
|
||||||
|
#. In the search you can use:
|
||||||
|
|
||||||
|
``self.env['res.partner'].search([('name', '%', 'Jon Miller)])``
|
||||||
|
|
||||||
|
#. In this example the function will return positive result for `John Miller`
|
||||||
|
or `John Mill`.
|
||||||
|
|
||||||
|
#. You can tweak the number of strings to be returned by adjusting the set
|
||||||
|
limit (default: 0.3). NB: Currently you have to set the limit by executing
|
||||||
|
the following SQL statment:
|
||||||
|
|
||||||
|
``self.env.cr.execute("SELECT set_limit(0.2);")``
|
||||||
|
|
||||||
|
#. Another interesting feature is the use of ``similarity(column, 'text')``
|
||||||
|
function in the ``order`` parameter to order by similarity. This module just
|
||||||
|
contains a basic implementation which doesn't perform validations and has to
|
||||||
|
start with this function. For example you can define the function as
|
||||||
|
followed:
|
||||||
|
|
||||||
|
``similarity(%s.name, 'John Mil') DESC" % self.env['res.partner']._table``
|
||||||
|
|
||||||
|
For further questions read the Documentation of the
|
||||||
|
`pg_trgm <https://www.postgresql.org/docs/current/static/pgtrgm.html>`_ module.
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from . import test_query_generation
|
from . import test_query_generation
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016 Eficent Business and IT Consulting Services S.L.
|
||||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2016 Serpent Consulting Services Pvt. Ltd.
|
||||||
# © 2016 Serpent Consulting Services Pvt. Ltd.
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from odoo.osv import expression
|
from odoo.osv import expression
|
||||||
from odoo.tests.common import TransactionCase, at_install, post_install
|
from odoo.tests.common import TransactionCase, at_install, post_install
|
||||||
|
@ -37,8 +36,8 @@ class QueryGenerationCase(TransactionCase):
|
||||||
where_clause_params)
|
where_clause_params)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
complete_where,
|
complete_where,
|
||||||
'SELECT FROM "res_partner" WHERE '
|
b'SELECT FROM "res_partner" WHERE '
|
||||||
'("res_partner"."name" % \'test\')')
|
b'("res_partner"."name" % \'test\')')
|
||||||
|
|
||||||
def test_fuzzy_where_generation_translatable(self):
|
def test_fuzzy_where_generation_translatable(self):
|
||||||
"""Check the generation of the where clause for translatable fields."""
|
"""Check the generation of the where clause for translatable fields."""
|
||||||
|
@ -58,7 +57,7 @@ class QueryGenerationCase(TransactionCase):
|
||||||
where_clause_params)
|
where_clause_params)
|
||||||
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
"""SELECT id FROM temp_irt_current WHERE name % 'Goschaeftlic'""",
|
b"""SELECT id FROM temp_irt_current WHERE name % 'Goschaeftlic'""",
|
||||||
complete_where)
|
complete_where)
|
||||||
|
|
||||||
def test_fuzzy_order_generation(self):
|
def test_fuzzy_order_generation(self):
|
||||||
|
|
|
@ -1,41 +1,40 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<record model="ir.ui.view" id="trgm_index_view_form">
|
<record model="ir.ui.view" id="trgm_index_view_form">
|
||||||
<field name="name">trgm.index.view.form</field>
|
<field name="name">trgm.index.view.form</field>
|
||||||
<field name="model">trgm.index</field>
|
<field name="model">trgm.index</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Trigram Index">
|
<form string="Trigram Index">
|
||||||
<sheet>
|
<sheet>
|
||||||
<group col="4">
|
<group col="4">
|
||||||
<field name="field_id" domain="[('ttype', 'in', ['char', 'text'])]"/>
|
<field name="field_id" domain="[('ttype', 'in', ['char', 'text'])]"/>
|
||||||
<field name="index_name"/>
|
<field name="index_name"/>
|
||||||
<field name="index_type"/>
|
<field name="index_type"/>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="trgm_index_view_tree">
|
<record model="ir.ui.view" id="trgm_index_view_tree">
|
||||||
<field name="name">trgm.index.view.tree</field>
|
<field name="name">trgm.index.view.tree</field>
|
||||||
<field name="model">trgm.index</field>
|
<field name="model">trgm.index</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Trigram Index">
|
<tree string="Trigram Index">
|
||||||
<field name="field_id"/>
|
<field name="field_id"/>
|
||||||
<field name="index_name"/>
|
<field name="index_name"/>
|
||||||
<field name="index_type"/>
|
<field name="index_type"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.actions.act_window" id="trgm_index_action">
|
<record model="ir.actions.act_window" id="trgm_index_action">
|
||||||
<field name="name">Trigram Index</field>
|
<field name="name">Trigram Index</field>
|
||||||
<field name="res_model">trgm.index</field>
|
<field name="res_model">trgm.index</field>
|
||||||
<field name="view_type">form</field>
|
<field name="view_type">form</field>
|
||||||
<field name="view_mode">tree,form</field>
|
<field name="view_mode">tree,form</field>
|
||||||
<field name="type">ir.actions.act_window</field>
|
<field name="type">ir.actions.act_window</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem id="trgm_index_menu"
|
<menuitem id="trgm_index_menu"
|
||||||
|
@ -43,5 +42,4 @@
|
||||||
action="trgm_index_action"
|
action="trgm_index_action"
|
||||||
groups="base.group_no_one"/>
|
groups="base.group_no_one"/>
|
||||||
|
|
||||||
</data>
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue