def test_sort_order_serialization_with_nested_path(self): sort_order = SortOrder('foo', mode='avg', nested_path='bar') self.assertEqual(sort_order.serialize(), {'foo': { 'nested_path': 'bar', 'mode': 'avg' }})
def test_sorting_by_foo(self): search = Search(MatchAllQuery()) search.sort.add(SortOrder('foo', order='desc')) resultset = self.conn.search(search, indices=self.index_name, doc_types=[self.document_type]) ids = [doc['_id'] for doc in resultset.hits] self.assertEqual(ids, ['3', '2', '1'])
def search_add_sort(query, sort_field, sort_type): search = Search(query) sort_order = SortOrder(sort_field, sort_type) search.sort.add(sort_order) return search
def test_sort_order_serialization_with_nested_path(self): sort_order = SortOrder('foo', mode='avg', nested_path='bar') self.assertEqual( sort_order.serialize(), {'foo': {'nested_path': 'bar', 'mode': 'avg'}} )
def test_sort_order_serialization_with_missing(self): sort_order = SortOrder('foo', missing='_last') self.assertEqual(sort_order.serialize(), {'foo': {'missing': '_last'}})
def test_sort_order_serialization_with_order(self): sort_order = SortOrder('foo', 'asc') self.assertEqual(sort_order.serialize(), {'foo': {'order': 'asc'}})
def test_sort_order_serialization(self): sort_order = SortOrder('foo') self.assertEqual(sort_order.serialize(), {'foo': {}})
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)
def test_sort_factory_with_sort_order(self): sort_factory = SortFactory() sort_factory.add(SortOrder('foo')) self.assertEqual(sort_factory.serialize(), [{'foo': {}}])