diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-12 16:33:24 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-10-12 16:33:24 +0200 |
commit | 2f61567837dab3e2e7354d8b81e844596046cb2a (patch) | |
tree | 66df3422b057c773b3088d2746323389bedad517 | |
parent | 6776fd5a5d88667d58085441facb7fa0c98b76da (diff) | |
download | Ishtar-2f61567837dab3e2e7354d8b81e844596046cb2a.tar.bz2 Ishtar-2f61567837dab3e2e7354d8b81e844596046cb2a.zip |
Search vectors manage integration of parent vectors (refs #2912)
-rw-r--r-- | archaeological_context_records/tests.py | 14 | ||||
-rw-r--r-- | ishtar_common/models.py | 10 |
2 files changed, 24 insertions, 0 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py index 89b15fbbf..029246235 100644 --- a/archaeological_context_records/tests.py +++ b/archaeological_context_records/tests.py @@ -273,6 +273,20 @@ class ContextRecordTest(ContextRecordInit, TestCase): cr.operation ) + def test_search_vector_update(self): + cr = self.create_context_record(force=True)[0] + cr = models.ContextRecord.objects.get(pk=cr.pk) + cr.label = "Label label" + cr.location = "I am heeere" + cr.save() + for key in ('label', 'heeer'): + self.assertIn(key, cr.search_vector) + cr.operation.code_patriarche = "PATRIARCHE" + cr.operation.save() + cr = models.ContextRecord.objects.get(pk=cr.pk) + self.assertIn(settings.ISHTAR_OPE_PREFIX.lower() + "patriarch", + cr.search_vector) + def test_upstream_cache_update(self): cr = self.create_context_record()[0] cr_pk = cr.pk diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 915415416..ac5c29a0f 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -924,6 +924,7 @@ class FullSearch(models.Model): BASE_SEARCH_VECTORS = [] INT_SEARCH_VECTORS = [] M2M_SEARCH_VECTORS = [] + PARENT_SEARCH_VECTORS = [] class Meta: abstract = True @@ -968,6 +969,15 @@ class FullSearch(models.Model): search_vectors.append( "'{}':1".format(q.all()[0][INT_SEARCH_VECTOR])) + # copy parent vector fields + for PARENT_SEARCH_VECTOR in self.PARENT_SEARCH_VECTORS: + parent = getattr(self, PARENT_SEARCH_VECTOR) + if hasattr(parent, 'all'): # m2m + for p in parent.all(): + search_vectors.append(p.search_vector) + else: + search_vectors.append(parent.search_vector) + # query "simple" fields q = base_q.annotate( search=SearchVector( |