Beispiel #1
0
    def search(self, start=0, size=20, doc_types='resource', indices='order_index', sort=None, **kwargs):
        # set filter
        filters = []
        for k,v in kwargs.items():
            if k and k!='complete_time':
                filters.append(TermFilter(k, v))
            elif k and v!='' and k=='complete_time':
                ct = kwargs['complete_time']
                if len(ct) == 2:
                    filters.append(RangeFilter(ESRange('complete_time', from_value=ct[0], to_value=ct[1])))
                else:
                    filters.append(RangeFilter(ESRange('complete_time', from_value=ct[0])))
        
        _filter = None
        if filters:
            _filter = ANDFilter(filters)

        bq = MatchAllQuery()
        # filtered
        q = FilteredQuery(bq, _filter)

        # sort
        if sort:
            sf = SortFactory()
            for s in sort:
                sf.add(s)
            s = Search(q, sort=sf)
        else:
            s = Search(q)

        # result
        return self.conn.search(s, indices=indices, doc_types=doc_types, start=start, size=size)
Beispiel #2
0
 def test_sort_factory_reset(self):
     sort_factory = SortFactory()
     sort_factory.add(SortOrder('foo'))
     self.assertEqual(len(sort_factory.sort_orders), 1)
     sort_factory.reset()
     self.assertEqual(len(sort_factory.sort_orders), 0)
Beispiel #3
0
 def test_sort_factory_with_sort_order(self):
     sort_factory = SortFactory()
     sort_factory.add(SortOrder('foo'))
     self.assertEqual(sort_factory.serialize(), [{'foo': {}}])
Beispiel #4
0
 def test_sort_factory_reset(self):
     sort_factory = SortFactory()
     sort_factory.add(SortOrder('foo'))
     self.assertEqual(len(sort_factory.sort_orders), 1)
     sort_factory.reset()
     self.assertEqual(len(sort_factory.sort_orders), 0)
Beispiel #5
0
 def test_sort_factory_with_sort_order(self):
     sort_factory = SortFactory()
     sort_factory.add(SortOrder('foo'))
     self.assertEqual(sort_factory.serialize(), [{'foo': {}}])