diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-01-19 15:51:21 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-01-19 15:51:21 +0100 | 
| commit | 266836701081d674db486ebf70d8a3960493a9fc (patch) | |
| tree | 60043b09fb91643e302e6ecb69d30a1dbb3ce60b /ishtar_common | |
| parent | 1da5669b4e24621d43a1e6c9c7a519e180a9e302 (diff) | |
| download | Ishtar-266836701081d674db486ebf70d8a3960493a9fc.tar.bz2 Ishtar-266836701081d674db486ebf70d8a3960493a9fc.zip  | |
Improve search vector indexation
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/forms_common.py | 1 | ||||
| -rw-r--r-- | ishtar_common/management/commands/update_search_vectors.py | 7 | ||||
| -rw-r--r-- | ishtar_common/models.py | 19 | 
3 files changed, 17 insertions, 10 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 403f9fe5f..2b30c56f6 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -920,6 +920,7 @@ class SourceForm(CustomForm, ManageOldType):  class SourceSelect(TableSelect): +    search_vector = forms.CharField(label=_(u"Full text search"))      authors = forms.IntegerField(          widget=widgets.JQueryAutoComplete(              "/" + settings.URL_PATH + 'autocomplete-author', diff --git a/ishtar_common/management/commands/update_search_vectors.py b/ishtar_common/management/commands/update_search_vectors.py index c73a6e88e..d301a3afc 100644 --- a/ishtar_common/management/commands/update_search_vectors.py +++ b/ishtar_common/management/commands/update_search_vectors.py @@ -14,11 +14,14 @@ class Command(BaseCommand):      def handle(self, *args, **options):          for model in django.apps.apps.get_models():              if hasattr(model, "update_search_vector") and \ -                    getattr(model, "BASE_SEARCH_VECTORS", None): +                    (getattr(model, "BASE_SEARCH_VECTORS", None) or +                     getattr(model, "INT_SEARCH_VECTORS", None) or +                     getattr(model, "M2M_SEARCH_VECTORS", None) or +                     getattr(model, "PARENT_SEARCH_VECTORS", None)):                  self.stdout.write("\n* update {}".format(model))                  total = model.objects.count()                  for idx, item in enumerate(model.objects.all()): -                    sys.stdout.write("\r{}/{} ".format(idx, total)) +                    sys.stdout.write("\r{}/{} ".format(idx + 1, total))                      sys.stdout.flush()                      item.update_search_vector()          self.stdout.write("\n") diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 66b15be34..86191c0ef 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1030,7 +1030,9 @@ class FullSearch(models.Model):          :param save: True if you want to save the object immediately          :return: True if modified          """ -        if not self.BASE_SEARCH_VECTORS and not self.M2M_SEARCH_VECTORS: +        if not self.BASE_SEARCH_VECTORS and not self.M2M_SEARCH_VECTORS \ +                and not self.INT_SEARCH_VECTORS \ +                and not self.PARENT_SEARCH_VECTORS:              logger.warning("No search_vectors defined for {}".format(                  self.__class__))              return @@ -1073,13 +1075,14 @@ class FullSearch(models.Model):              else:                  search_vectors.append(parent.search_vector) -        # query "simple" fields -        q = base_q.annotate( -            search=SearchVector( -                *self.BASE_SEARCH_VECTORS, -                config=settings.ISHTAR_SEARCH_LANGUAGE -            )).values('search') -        search_vectors.append(q.all()[0]['search']) +        if self.BASE_SEARCH_VECTORS: +            # query "simple" fields +            q = base_q.annotate( +                search=SearchVector( +                    *self.BASE_SEARCH_VECTORS, +                    config=settings.ISHTAR_SEARCH_LANGUAGE +                )).values('search') +            search_vectors.append(q.all()[0]['search'])          self.search_vector = merge_tsvectors(search_vectors)          changed = old_search != self.search_vector          if save and changed:  | 
