diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-10-23 11:35:46 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-10-23 11:35:46 +0700 |
| commit | 3852cfd075fb3bebf189234db6fd9c52acf6d667 (patch) | |
| tree | bbee3b57b8e22f2cb4df5047055b09e89ab01f21 | |
| parent | 70a6cf87d721e9e6c78d27a9e9ef4168ad96fac7 (diff) | |
sync to solr web find page
| -rw-r--r-- | indoteknik_custom/models/find_page.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/indoteknik_custom/models/find_page.py b/indoteknik_custom/models/find_page.py index 697fd275..467e30d1 100644 --- a/indoteknik_custom/models/find_page.py +++ b/indoteknik_custom/models/find_page.py @@ -1,8 +1,11 @@ from odoo import fields, models, api, tools, _ import logging import re +import pysolr _logger = logging.getLogger(__name__) +_cat_brand_solr = pysolr.Solr('http://10.148.0.5:8983/solr/url_category_brand/', always_commit=True, timeout=30) +# _cat_brand_solr_dev = pysolr.Solr('http://127.0.0.1:8983/solr/url_category_brand/', always_commit=True, timeout=30) class BrandProductCategory(models.Model): @@ -35,6 +38,26 @@ class FindPage(models.Model): category_id = fields.Many2one('product.public.category', string='Category', help='Bisa semua level Category') url = fields.Char(string='Url') + def _sync_to_solr(self, limit=10000): + urls = self.env['web.find.page'].search([]) + documents = [] + catch = {} + for url in urls: + try: + document = { + 'id': url.id, + 'category_id_i': url.category_id.id, + 'brand_id_i': url.brand_id.id, + 'url_s': url.url + } + documents.append(document) + catch = document + except Exception as e: + _logger.error('Failed to add document to Solr URL Category Brand: %s', e) + _logger.error('Document Data: %s', catch) + _cat_brand_solr.add(documents) + return True + def _get_category_hierarchy(self, category): categories = [] current_category = category |
