-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New addon: Fuzzy Search with PostgreSQL pg_trgm extension #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| def patch_generate_order_by(method): | ||
| def decorate_generate_order_by(self, order_spec, query): | ||
| if order_spec and order_spec.startswith('similarity('): | ||
| from pprint import pprint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove pprint lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think I committed to fast ^^
|
The initial approach looks good. |
|
|
Is it ready for review? |
|
for me yes :) |
base_search_fuzzy/README.rst
Outdated
|
|
||
| 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 something else. It provides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/something/anything
|
Thanks for the contribution! |
|
Please, Could you review our beta checks https://travis-ci.org/OCA/server-tools/jobs/139978373#L424-L430? ************* Module base_search_fuzzy.models.trgm_index
base_search_fuzzy/models/trgm_index.py:122: [C8107(translation-required), TrgmIndex.create_index] String parameter of raise "UserError" requires translation. Use _('The pg_trgm extension does not exists or cannot be installed.')Ignore ************* Module base_search_fuzzy.models.ir_model
base_search_fuzzy/models/ir_model.py:24: [W0402(deprecated-module), ] Uses of a deprecated module 'openerp.osv'
************* Module base_search_fuzzy.tests.test_query_generation
base_search_fuzzy/tests/test_query_generation.py:3: [W0402(deprecated-module), ] Uses of a deprecated module 'openerp.osv' |
|
@moylop260 FYI two of those are the dreaded false positive for imports from openerp.osv again. OCA/maintainer-quality-tools#306. What is the recommended solution for that? |
|
@StefanRijnhart |
|
👍 |
|
Thanks for the comments. I updated all. :) |
…nd allowing the sql parameter %.
…t tests, added translations, added access permissions, moved the monkey patching to method _register_hook of ir.model and fixed _auto_init, added README, cleaned up some aprts
…on, Added one more test
…avoid decorating the function many times whcih leads to recursion errors
|
I added a fix to check if the functions which I overwrite are already decorated by the new decorator. We had problems that these functions got this decorator much times (in particular in the cron worker) and a maximum recursion depth error was thrown. I also rebased the branch. |
|
travis red build should be fixed by #507 |
base_search_fuzzy/README.rst
Outdated
| #. 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 ``SUEPRUSER`` right (this allows the odoo module to install the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/SUEPRUSER/SUPERUSER/
|
one small typo, but 👍 |
|
TravisCI is red 🚧 |
Fix typo
|
After rerunning the checks (and merging the Readme fix) all are green. |
Syncing from upstream OCA/server-tools (9.0)
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. This is a first basic implementation which should be extended later.Requirements
First you need to have the
pg_trgmextension available. In debian based distribution you have to install the postgresql-contrib module. Then you have to either install thepg_trgmextension to your database or you have to give your postgresql user the superadmin right (then the extension will be installed by this module).Explanation
If you installed the odoo module you can define in Settings -> Database Structure -> Trigam Index the indexes. There the index name will automatically created.
For example you can create an index for the
namefield ofres.partner. Then in a search you can useself.env['res.partner'].search([('name', '%', 'Jon Miller)]). In this Example it can find existing names likeJohn MillerorJohn Mill.Which strings can be found depends on the limit which is set (default: 0.3). Currently you have to set the limit by executing SQL:
self.env.cr.execute("SELECT set_limit(0.2);").Also you can use the
similarity(column, 'text')function in theorderparameter to order by the similarity. This is just a basic implementation which doesn't contains validations and has to start with this function. For example you can define this like"similarity(%s.name, 'John Mil') DESC" % self.env['res.partner']._table.For further questions read the Documentation of the pg_trgm module.
Tasks/Goals
For this PR:
Later: