Skip to content
Closed
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
6 changes: 6 additions & 0 deletions setup/typesense_ir_exports/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
2 changes: 2 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ unidecode

# tests
vcrpy-unittest

odoo-addon-connector_search_engine @ git+https://github.com/OCA/search-engine.git@refs/pull/207/head#subdirectory=setup/connector_search_engine
223 changes: 223 additions & 0 deletions typesense_ir_exports/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
==============================
Typesense Serializer Ir Export
==============================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-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%2Fsearch--engine-lightgray.png?logo=github
:target: https://github.com/OCA/search-engine/tree/16.0/typesense_ir_exports
:alt: OCA/search-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-typesense_ir_exports
: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/search-engine&target_branch=16.0
:alt: Try me on Runboat

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

Use Exporter (ir.exports) as serializer for connector_typesense

Each ir.exports records is converted into JSON and JSON data get indexed
into the Search Engine.

Data can be String, Integer, Float, Lists, and Relations in the form of
Object.

Thnaks to the dynamic Schema configuration we can add new fields or
remove without breaking the Schema.

Binary data like images are sent as string, but better if we use
external filestore to use images related external urls.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

You need to have typesense search engine running and successfully
connected to odoo.

Make sure to have ``connector_search_engine`` and
``connector_typesense`` modules installed.

SE Index Config
---------------

Transition to: Search Engine > Configuration > Index configurations

Make sure to have this search index configuration in a new record:

::

- Name: give it a unigue name
- Body Str:

.. code:: json

{
"name": "ts_products_collection",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": ".*",
"type": "auto",
"optional": true
}
],
"enable_nested_fields": true
}

SE Backend
----------

Transition to: Search Engine > Configuration > Backends

Create a backend record, and create an index line with values:

::

- Model: select the model you want to index
- Serializer Type: Exporter
- Exporter: select or create a new exporter template by clicking on "Open Exporter" button
- Config: select or create the config se index record mentioned above

You can create, update and delete exporter templates through a button in
the tree view once you click on the exporter or the button under the
``exporter_id`` field in the se.index form view.

Media
-----

|Backend Configuration|

|Exporter Dialog Button in Tree View|

|Exporter Dialog|

.. |Backend Configuration| image:: https://raw.githubusercontent.com/OCA/search-engine/16.0/typesense_ir_exports/static/img/backend.png
.. |Exporter Dialog Button in Tree View| image:: https://raw.githubusercontent.com/OCA/search-engine/16.0/typesense_ir_exports/static/img/exporter_dialog_button.png
.. |Exporter Dialog| image:: https://raw.githubusercontent.com/OCA/search-engine/16.0/typesense_ir_exports/static/img/exporter_dialog.png

Usage
=====

Simple Quick User Friendly Usage
--------------------------------

The key of the module is the user friendly usage of ir.exports to
serialize data and resolve it for JSON.

Behind the scene everything is managed to jsonify:

::

- images bytes into string
- images thumbnail into urls external or internal (any of them in sequence)
- many2one relation into string
- many2one inner fileds into object of key value pairs
- many2many into list of inner strings or objects
- intergers are indexed as integers
- floats are indexed as floats
- id is ESSENIALLY indexed as string and not as integer (typesene only)

If relational field has inner relational field and that also has inner
relational field or data, no worries everything is managed smoothly.

Selecting fields and relations and inner relations is friendly handled
by the exporter dialog.

You can remove or add fields as you wish, as indexing is updated, and if
necessary recreated.

(recreating a collection only if a data type changes from string into
object or vice versa, like having many2one relation and then having the
same relation with inner fields of it)

Media
-----

|se index form view with exporter button|

|exporter dialog complicated tree|

|serialized json data from exporter related record|

.. |se index form view with exporter button| image:: https://raw.githubusercontent.com/OCA/search-engine/16.0/typesense_ir_exports/static/img/se_index_form_with_exporter_button.png
.. |exporter dialog complicated tree| image:: https://raw.githubusercontent.com/OCA/search-engine/16.0/typesense_ir_exports/static/img/dialog_tree_content.png
.. |serialized json data from exporter related record| image:: https://raw.githubusercontent.com/OCA/search-engine/16.0/typesense_ir_exports/static/img/serialized_data_from_exporter.png

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/search-engine/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/search-engine/issues/new?body=module:%20typesense_ir_exports%0Aversion:%2016.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
-------

* Kencove

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

- Mohamed Alkobrosli malkobrosly@kencove.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-Kencove| image:: https://github.com/Kencove.png?size=40px
:target: https://github.com/Kencove
:alt: Kencove

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

|maintainer-Kencove|

This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/16.0/typesense_ir_exports>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions typesense_ir_exports/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import tools
29 changes: 29 additions & 0 deletions typesense_ir_exports/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Kencove (https://kencove.com).
# @author Mohamed Alkobrosli <malkobrosly@kencove.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Typesense Serializer Ir Export",
"summary": "Use Exporter (ir.exports) as serializer for index",
"version": "16.0.1.0.0",
"category": "Uncategorized",
"website": "https://github.com/OCA/search-engine",
"author": "Kencove, Odoo Community Association (OCA)",
"maintainers": ["Kencove"],
"license": "AGPL-3",
"development_status": "Alpha",
"depends": [
"connector_search_engine_serializer_ir_export",
],
"data": [
"data/se_index_config_data.xml",
"views/se_index_view.xml",
],
"installable": True,
"assets": {
"web.assets_backend": [
"typesense_ir_exports/static/src/action_ir_export.xml",
"typesense_ir_exports/static/src/action_ir_export.esm.js",
],
},
}
28 changes: 28 additions & 0 deletions typesense_ir_exports/data/se_index_config_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo noupdate="1">
<record id="se_index_config_product" model="se.index.config">
<field name="name">TS Product Dynamic Fields Config</field>
<field name="body">{}</field>
<field name="body_str">
{
"name": "ts_products_collection",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": ".*",
"type": "auto",
"optional": true
}
],
"enable_nested_fields": true
}
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions typesense_ir_exports/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import se_index
23 changes: 23 additions & 0 deletions typesense_ir_exports/models/se_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Kencove (https://kencove.com).
# @author Mohamed Alkobrosli <malkobrosly@kencove.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models

from ..tools.resolver import IrExportsResolver
from ..tools.serializer import JsonifySerializer


class SeIndex(models.Model):
_inherit = "se.index"

def _get_serializer(self):
if (
self.serializer_type == "ir_exports"
and self.backend_id.backend_type == "typesense"
):
parser = self.exporter_id.get_json_parser()
resolved_parser = IrExportsResolver(parser).resolved_parser
return JsonifySerializer(parser=resolved_parser, index=self)

Check warning on line 21 in typesense_ir_exports/models/se_index.py

View check run for this annotation

Codecov / codecov/patch

typesense_ir_exports/models/se_index.py#L19-L21

Added lines #L19 - L21 were not covered by tests
else:
return super()._get_serializer()

Check warning on line 23 in typesense_ir_exports/models/se_index.py

View check run for this annotation

Codecov / codecov/patch

typesense_ir_exports/models/se_index.py#L23

Added line #L23 was not covered by tests
57 changes: 57 additions & 0 deletions typesense_ir_exports/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
You need to have typesense search engine running and successfully connected to odoo.

Make sure to have `connector_search_engine` and `connector_typesense` modules installed.

## SE Index Config

Transition to: Search Engine > Configuration > Index configurations

Make sure to have this search index configuration in a new record:

- Name: give it a unigue name
- Body Str:

```json
{
"name": "ts_products_collection",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": ".*",
"type": "auto",
"optional": true
}
],
"enable_nested_fields": true
}
```

## SE Backend

Transition to: Search Engine > Configuration > Backends

Create a backend record, and create an index line with values:

- Model: select the model you want to index
- Serializer Type: Exporter
- Exporter: select or create a new exporter template by clicking on "Open Exporter" button
- Config: select or create the config se index record mentioned above

You can create, update and delete exporter templates through a button in the tree view
once you click on the exporter or the button under the `exporter_id` field in the
se.index form view.

## Media

![Backend Configuration](../static/img/backend.png)

![Exporter Dialog Button in Tree View](../static/img/exporter_dialog_button.png)

![Exporter Dialog](../static/img/exporter_dialog.png)
1 change: 1 addition & 0 deletions typesense_ir_exports/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Mohamed Alkobrosli <malkobrosly@kencove.com>
9 changes: 9 additions & 0 deletions typesense_ir_exports/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Use Exporter (ir.exports) as serializer for connector_typesense

Each ir.exports records is converted into JSON and JSON data get indexed into the Search Engine.

Data can be String, Integer, Float, Lists, and Relations in the form of Object.

Thnaks to the dynamic Schema configuration we can add new fields or remove without breaking the Schema.

Binary data like images are sent as string, but better if we use external filestore to use images related external urls.
Loading
Loading