Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
makepot: "true"
services:
postgres:
image: postgres:9.6
image: postgres:12
env:
POSTGRES_USER: odoo
POSTGRES_PASSWORD: odoo
Expand Down
189 changes: 189 additions & 0 deletions full_text_search/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

================
Full Text Search
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5374048b8bc825d4893d68c0f697227e4f6f76c1b21971351a5b223910a6cc46
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/14.0/full_text_search
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-full_text_search
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module provides a simple way to use full-text search functionality
in Odoo models.

It is fully based on `PostgreSQL full-text
search <https://www.postgresql.org/docs/current/textsearch.html>`__, and
adds a new ``Searchable`` field that represents the TSVector column in
the database that will store the weighted full-text vector. It also adds
the ``full_text`` matching operator : ``@@`` to odoo domains.

To add this functionality to a model, simply add a ``Searchable`` field
to the model with the fields you want to search on weighted by their
importance: ``A``, ``B``, ``C``, ``D`` with ``A`` being the most
important.

.. code:: python

from odoo import fields, models

class YourModel(models.Model):
_name = 'your.model'

full_text = fields.Searchable(
"Full Text",
fields={
"name": "A",
"description": "B",
"notes": "C",
},
dictionary="english",
)

And add the ``full_text`` field to the model's search view (first
position is recommended):

.. code:: xml

<odoo>
<record id="view_your_model_search" model="ir.ui.view">
<field name="model">your.model</field>
<field name="inherit_id" ref="base.view_your_model_search" />
<field name="arch" type="xml">
<field name="name" position="before">
<field name="full_text" operator="@@" />
</field>
</field>
</record>
</odoo>

You can also use the ``full_text`` operator in your own code to search
for records:

.. code:: python

records = self.env['your.model'].search([('full_text', '@@', 'search query')])

The search query uses the PostgreSQL websearch syntax with additional
prefix matching:

- unquoted text will be ANDed (``&``)
- quoted text will be searched for with followed by operator (``<->``)
- text around the OR keyword will be ORed (``|``)
- a dash ``-`` will be treated as a negation operator (``!``)
- every term will be treated as a prefix match (``:*``)

The results will be sorted by relevance if no other sort order is
specified.

By default, the ``full_text`` field is computed at database level using
a generated field (PostgreSQL 12+).

For more fine grained control, you can also use a compute to generate
the ``full_text`` field value yourself.

The usage is as follows:

.. code:: python

from odoo import fields, models

class YourModel(models.Model):
_name = 'your.model'

full_text = fields.Searchable(
"Full Text",
fields={
"name": "A",
"description": "B",
"notes": "C",
},
dictionary="english",
compute="_compute_full_text",
store=True,
)

@api.depends('name', 'description', 'notes')
def _compute_full_text(self):
for record in self:
record.full_text = {
"name": record.name,
"description": record.description,
"notes": " ".join(record.relation_ids.mapped('name')),
}

**Table of contents**

.. contents::
:local:

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20full_text_search%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Akretion

Contributors
------------

- Florian Mounier florian.mounier@akretion.com

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-paradoxxxzero| image:: https://github.com/paradoxxxzero.png?size=40px
:target: https://github.com/paradoxxxzero
:alt: paradoxxxzero

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-paradoxxxzero|

This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/14.0/full_text_search>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions full_text_search/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .hooks import post_load
from . import fields
from . import models
18 changes: 18 additions & 0 deletions full_text_search/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2026 Akretion (http://www.akretion.com).
# @author Florian Mounier <florian.mounier@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Full Text Search",
"summary": "Adds full text search capabilities to Odoo",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"category": "Tools",
"website": "https://github.com/OCA/server-tools",
"author": "Akretion, Odoo Community Association (OCA)",
"depends": ["web"],
"data": ["views/assets.xml"],
"maintainers": ["paradoxxxzero"],
"installable": True,
"post_load": "post_load",
}
Loading
Loading