Fuzzy search with the PostgreSQL trigram extension
Project description
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 possibility to perform the fuzzy search for external addons.
Table of contents
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 statement:
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 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. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.
Do not contact contributors directly about support or help with technical issues.
Credits
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>
-
Vicent Cubells
Ernesto Tejeda
Maintainers
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.
This module is part of the OCA/server-tools project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file odoo12_addon_base_search_fuzzy-12.0.1.0.0.99.dev3-py3-none-any.whl
.
File metadata
- Download URL: odoo12_addon_base_search_fuzzy-12.0.1.0.0.99.dev3-py3-none-any.whl
- Upload date:
- Size: 128.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/30.4.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b66b22f5b7633c60a69c3a0596eadde004c256ef91bb711b7503bfbb15308a9 |
|
MD5 | 6e1b4d6500da61fe62c8ca3a41bfd54b |
|
BLAKE2b-256 | b5a84fe1f70d2170b0de385a0a38c446000ff8f7a44f97b97c9ad1eca2f5586f |