summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-06-18 13:46:34 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-06-18 13:46:34 +0700
commit6b1745b06fef67a3310b176e71d73d840935398a (patch)
treebbfc02a8d74a81dc4af42f96d90fa816314c18c3
parent18404c79a875afc31831ddd1ae2a419536216eb2 (diff)
add recommendation on solr
-rw-r--r--indoteknik_custom/models/solr/apache_solr.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py
index 5acfded8..397db53b 100644
--- a/indoteknik_custom/models/solr/apache_solr.py
+++ b/indoteknik_custom/models/solr/apache_solr.py
@@ -9,6 +9,7 @@ from odoo.tools.config import config
_logger = logging.getLogger(__name__)
_solr = pysolr.Solr('http://10.148.0.5:8983/solr/product/', always_commit=True, timeout=30)
_variants_solr = pysolr.Solr('http://10.148.0.5:8983/solr/variants/', always_commit=True, timeout=30)
+_recommendation_solr = pysolr.Solr('http://10.148.0.5:8983/solr/recommendation/', always_commit=True, timeout=30)
# _solr = pysolr.Solr('http://34.101.189.218:8983/solr/product/', always_commit=True, timeout=30) # for development only
@@ -291,3 +292,25 @@ class ApacheSolr(models.Model):
_logger.info("[SYNC_VARIANTS_TO_SOLR] Finish task add to solr. Time taken: {:.6f} seconds".format(end_time - start_time))
return False
+
+ def _solr_sync_recommendation(self, limit=100):
+ solr_model = self.env['apache.solr']
+ variants = self.env['product.product'].search([('solr_flag', '=', 2)], limit=limit)
+ # documents = []
+ for variant in variants:
+ # document = solr_model.get_doc('recommendation', variant.id)
+ document = {}
+ document.update({
+ 'id': variant.id,
+ 'display_name_s': variant.display_name,
+ 'name_s': variant.name,
+ 'default_code_s': variant.default_code or '',
+ 'product_rating_f': variant.product_tmpl_id.virtual_rating,
+ 'template_id_i': variant.product_tmpl_id.id,
+ 'active_s': variant.active,
+ })
+ # self.solr().add(docs=[document], softCommit=True)
+ # documents.append(document)
+ variant.solr_flag = 1
+ _recommendation_solr.add(document)
+ # _recommendation_solr.add(documents)