summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2025-12-18 15:43:02 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2025-12-18 15:43:02 +0700
commitfbb30fff2489546e4c21ab55d504b6b861e70deb (patch)
tree2025a6c756c5b249e2be2630d2ae6b1ab485e96a
parent7399a88e6bab3993c2162d469878c0cf4c7da458 (diff)
<Miqdad> fix solr sync
-rw-r--r--indoteknik_custom/models/keywords.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/indoteknik_custom/models/keywords.py b/indoteknik_custom/models/keywords.py
index 69ecdd46..225710ab 100644
--- a/indoteknik_custom/models/keywords.py
+++ b/indoteknik_custom/models/keywords.py
@@ -76,6 +76,7 @@ class Keywords(models.Model):
keyword = f"%{record.keywords.strip()}%"
+ # AND (pt.unpublished IS FALSE OR pt.unpublished IS NULL)
sql = """
SELECT DISTINCT pp.id
FROM product_product pp
@@ -83,11 +84,11 @@ class Keywords(models.Model):
JOIN product_public_category_product_template_rel rel
ON rel.product_template_id = pt.id
WHERE
- COALESCE(pt.product_rating, 0) >= 3
- AND (pt.unpublished IS FALSE OR pt.unpublished IS NULL)
+ pt.product_rating >= 3
+ AND pp.active IS TRUE
AND (
pt.name ILIKE %s
- OR COALESCE(pt.website_description, '') ILIKE %s
+ OR pt.website_description ILIKE %s
)
"""
@@ -122,27 +123,34 @@ class Keywords(models.Model):
len(product_ids),
record.keywords
)
+
def sync_solr(self):
- # solr_model = self.env['apache.solr']
+ active_ids = self.env.context.get('active_ids', [])
+ if not active_ids:
+ _logger.warning("No active_ids found, nothing to sync")
+ return True
+
+ keywords = self.browse(active_ids)
+
documents = []
- data = {}
- for keyword in self.search([]):
+ for keyword in keywords:
searchkey = (keyword.keywords or '').strip().lower().replace(' ', '-')
try:
doc = {
'id': keyword.id,
'category_id_i': keyword.category_id.id,
'keywords_s': searchkey,
- # 'searchkey_t': searchkey,
'url_s': keyword.url,
- 'product_ids_is': [p.product_tmpl_id.id for p in keyword.product_ids]
+ 'product_ids_is': [p.product_tmpl_id.id for p in keyword.product_ids],
}
documents.append(doc)
- data = doc
except Exception as e:
_logger.error('failed %s', e)
- _logger.error('doc data: %s', data)
- solr.add(documents)
+ _logger.error('doc data: %s', doc)
+
+ if documents:
+ solr.add(documents)
+
return True
@api.model