コード例 #1
0
    def test_clone_keywords(self):
        q = SearchQuery("dummy", document_class=FakeDocument).keywords("bar")
        q1 = q.filter(foo="baz")

        self.assertEqual(u"bar", unicode(q.query))

        self.assertEqual(u'bar AND (foo:"baz")', unicode(q1.query))
コード例 #2
0
ファイル: test_query.py プロジェクト: Cgruppo/search
    def test_clone_keywords(self):
        q = SearchQuery("dummy", document_class=FakeDocument).keywords("bar")
        q1 = q.filter(foo="baz")

        self.assertEqual(
            u"bar",
            unicode(q.query)
        )

        self.assertEqual(
            u'bar AND (foo:"baz")',
            unicode(q1.query)
        )
コード例 #3
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]
コード例 #4
0
    def test_clone_filters(self):
        q = SearchQuery(
            "dummy",
            document_class=FakeDocument).filter((Q(foo="bar") | Q(foo="baz"))
                                                & ~Q(foo="neg"))

        q1 = q.filter(~Q(foo="neg2"))

        self.assertEqual(u'(((foo:"bar") OR (foo:"baz")) AND NOT (foo:"neg"))',
                         unicode(q.query))

        self.assertEqual(
            u'('
            '(((foo:"bar") OR (foo:"baz")) AND NOT (foo:"neg")) '
            'AND NOT (foo:"neg2")'
            ')', unicode(q1.query))
コード例 #5
0
ファイル: nodes.py プロジェクト: orbit7ch/creativeday
    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]
コード例 #6
0
ファイル: test_query.py プロジェクト: Cgruppo/search
    def test_clone_filters(self):
        q = SearchQuery("dummy", document_class=FakeDocument).filter(
            (Q(foo="bar") | Q(foo="baz")) & ~Q(foo="neg")
        )

        q1 = q.filter(~Q(foo="neg2"))

        self.assertEqual(
            u'(((foo:"bar") OR (foo:"baz")) AND NOT (foo:"neg"))',
            unicode(q.query)
        )

        self.assertEqual(
            u'('
            '(((foo:"bar") OR (foo:"baz")) AND NOT (foo:"neg")) '
            'AND NOT (foo:"neg2")'
            ')',
            unicode(q1.query)
        )
コード例 #7
0
ファイル: nodes.py プロジェクト: orbit7ch/creativeday
    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]
コード例 #8
0
ファイル: test_queries.py プロジェクト: orbit7ch/creativeday
    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))
コード例 #9
0
ファイル: report_events.py プロジェクト: orbit7ch/creativeday
 def enhance_search(event):
     event.nbr_results = SearchQuery.search(
         event.fields.get('searchTerm')).count()
     event.has_results = event.nbr_results > 0
コード例 #10
0
 def resolve_suggest(self, **kwargs):
     return SearchQuery.suggestions(kwargs.get('search_text'))