summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-06-18 15:50:30 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-06-18 15:50:30 +0700
commit2fec90b4a9040cde79774f61e4e19fff30f2a916 (patch)
treee553ba99c8d282b115b60b058e0abc3a3e3d3197
parent6b1745b06fef67a3310b176e71d73d840935398a (diff)
add some field in recommendation solr
-rw-r--r--indoteknik_custom/models/solr/apache_solr.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py
index 397db53b..7fc9dd5f 100644
--- a/indoteknik_custom/models/solr/apache_solr.py
+++ b/indoteknik_custom/models/solr/apache_solr.py
@@ -294,23 +294,23 @@ class ApacheSolr(models.Model):
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 = []
+ counter = 0
for variant in variants:
- # document = solr_model.get_doc('recommendation', variant.id)
+ template_time = time.time()
+ counter += 1
document = {}
document.update({
- 'id': variant.id,
- 'display_name_s': variant.display_name,
- 'name_s': variant.name,
+ 'id': variant.id or 0,
+ 'display_name_s': variant.display_name or '',
+ 'name_s': variant.name or '',
'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,
+ 'product_rating_f': variant.product_tmpl_id.virtual_rating or 0,
+ 'template_id_i': variant.product_tmpl_id.id or 0,
+ 'active_s': str(variant.active) or 'false',
+ 'type_s': variant.product_tmpl_id.type or ''
})
- # self.solr().add(docs=[document], softCommit=True)
- # documents.append(document)
variant.solr_flag = 1
_recommendation_solr.add(document)
- # _recommendation_solr.add(documents)
+ _logger.info('[SYNC_VARIANTS_TO_SOLR] {}/{} {:.6f}'.format(counter, limit, time.time() - template_time))
+ _logger.info('[SYNC_VARIANTS_TO_SOLR] Success add to solr variants %s' % variant.id)