diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-16 15:05:43 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-16 15:05:43 +0200 |
commit | 58cbaea8a20d17418d1613ea3b277242c932d2ac (patch) | |
tree | 48a3b167a477189f5cbcaf170158df416f24ca61 /ishtar_common/models.py | |
parent | fe78f0db71ac7a9528925492c8521496dc6c36ed (diff) | |
download | Ishtar-58cbaea8a20d17418d1613ea3b277242c932d2ac.tar.bz2 Ishtar-58cbaea8a20d17418d1613ea3b277242c932d2ac.zip |
Manage properties in search vectors - add short code for operation (refs #4027)
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index bd800181f..38e58955b 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1089,6 +1089,7 @@ class FullSearch(models.Model): search_vector = SearchVectorField(_("Search vector"), blank=True, null=True, help_text=_("Auto filled at save")) BASE_SEARCH_VECTORS = [] + PROPERTY_SEARCH_VECTORS = [] INT_SEARCH_VECTORS = [] M2M_SEARCH_VECTORS = [] PARENT_SEARCH_VECTORS = [] @@ -1122,6 +1123,7 @@ class FullSearch(models.Model): return if not self.BASE_SEARCH_VECTORS and not self.M2M_SEARCH_VECTORS \ and not self.INT_SEARCH_VECTORS \ + and not self.PROPERTY_SEARCH_VECTORS \ and not self.PARENT_SEARCH_VECTORS: logger.warning("No search_vectors defined for {}".format( self.__class__)) @@ -1191,6 +1193,19 @@ class FullSearch(models.Model): ) ) + if self.PROPERTY_SEARCH_VECTORS: + for attr in self.PROPERTY_SEARCH_VECTORS: + data = getattr(self, attr) + if callable(data): + data = data() + if not data: + continue + data = unicode(data) + with connection.cursor() as cursor: + cursor.execute("SELECT to_tsvector(%s)", [data]) + row = cursor.fetchone() + search_vectors.append(row[0]) + if hasattr(self, 'data') and self.data: content_type = ContentType.objects.get_for_model(self) for json_field in JsonDataField.objects.filter( |