Exemple #1
0
    def resolve_service_search(self, **kwargs):
        search_text = kwargs.get('search_text').lower()
        start = kwargs.get('start')
        size = kwargs.get('size')

        searched = SearchQuery.search(search_text)
        return searched[start:start + size]
Exemple #2
0
    def resolve_more(self, **kwargs):
        # FIXME: rethink matching on partial words
        # cause currently we match e.g. Portrait with Po

        start = kwargs.get('start')
        size = kwargs.get('size')

        return SearchQuery.search(self.all_tags_str,
                                  exclude_args={'pk':
                                                self.pk})[start:start + size]
Exemple #3
0
    def resolve_similar(self, info):
        # FIXME for the moment this is as good as it gets
        # ordering after a search and keeping the relevance requires a custom scoring function
        # nothing special, but I don't know yet how to implement this in wagtail
        #
        # and in addition calling len(.) materializes the results which we don't like
        # because we want to keep the first 6 anyway
        #

        # FIXME since we do not have such data at the moment lets, ignore it
        # similar = get_image_model().objects.exclude(pk=self.pk).filter(rating__gt=1).search(self.all_tags_str)[:6]
        # if len(similar) < 6:
        #     similar = get_image_model().objects.exclude(pk=self.pk).search(self.all_tags_str)[:6]
        # return similar

        # results = get_image_model().objects.exclude(pk=self.pk) \
        #               .search(self.styles_str, fields=['styles_str'], operator='and') \
        #               .search(self.parts_str + self.minor_tags_str, operator='or')[:6]
        #
        # return results
        results = get_image_model().objects.exclude(pk=self.pk)
        if self.styles_tags:
            results = results.filter(
                styles_tags__contains=self.styles_tags).values_list(
                    'pk', flat=True)[:200]

        # This should work, but doesn't
        # results = get_image_model().objects.exclude(pk=self.pk).filter(styles_tags__contains=['Fineline']).search(self.all_tags_str)[:6]

        # unfortunately this is necessary because wagtail search
        # though a great search interface cannot handle ArrayFields
        # it can handle single values, but then the sql query to actually
        # get the data from the db gets screwed...
        #
        return SearchQuery.search(self.all_tags_str,
                                  filter_args={'pk__in': results})[:6]
Exemple #4
0
    def handle(self, *args, **options):
        for event in UserSearchTerm.objects.all():
            search_term = event.fields.get('searchTerm')
            nbr_results = SearchQuery.search(search_term).count()

            print('{}: {} -> {}'.format(search_term, event.nbr_results, nbr_results))
 def enhance_search(event):
     event.nbr_results = SearchQuery.search(
         event.fields.get('searchTerm')).count()
     event.has_results = event.nbr_results > 0