def get(self): if self.search_adapter: result = search.query(self.search_adapter, **multi_to_dict(request.args)) objects = result.get_objects() else: objects = list(self.model.objects) return marshal(objects, self.fields)
def test_empty_search_with_filter_and_match(self): '''Should match both the topic criteria and the query''' with self.autoindex(): # Match both the topic condition but the queried tag match = VisibleDatasetFactory.create_batch(2, tags=[ 'in', 'filtered' ]) # Match the topic condition but not the queried tag no_match = VisibleDatasetFactory.create_batch(2, tags=['in']) # Excluded because not matching one of the topic tag excluded = VisibleDatasetFactory.create_batch(2, tags=[ 'out', 'filtered' ]) topic = TopicFactory(tags=['in', 'no-match']) query = topic_search_for(topic, DatasetSearch, tag='filtered') result = search.query(query) found = [d.id for d in result] self.assertEqual(len(found), 2) for dataset in match: self.assertIn(dataset.id, found) for dataset in no_match + excluded: self.assertNotIn(dataset.id, found)
def get(self): """List all objects""" if self.search_adapter: objects = search.query(self.search_adapter, **multi_to_dict(request.args)) else: objects = list(self.model.objects) return marshal_page(objects, self.fields)
def get(self): '''List all objects''' if self.search_adapter: objects = search.query(self.search_adapter, **multi_to_dict(request.args)) else: objects = list(self.model.objects) return marshal_page(objects, self.fields)
def reuses(topic): kwargs = multi_to_dict(request.args) kwargs.pop('topic', None) topic_search = topic_search_for(topic, ReuseSearch, facets=True, **kwargs) return theme.render('topic/reuses.html', topic=topic, reuses=search.query(topic_search))
def get_queryset(self): adapter = search.adapter_for(self.search_adapter or self.model) parser = adapter.as_request_parser() params = not_none_dict(parser.parse_args()) params['facets'] = True adapter = self.search_adapter or self.model result = search.query(adapter, **params) return result
def get(self): '''List or search all datasets''' search_parser.parse_args() try: return search.query(Dataset, **multi_to_dict(request.args)) except NotImplementedError: abort(501, 'Search endpoint not enabled') except RuntimeError: abort(500, 'Internal search service error')
def test_empty_search_no_match(self): '''Should return no result if no data match the tags''' with self.autoindex(): VisibleDatasetFactory.create_batch(2, tags=['whatever']) topic = TopicFactory(tags=['no-match']) query = topic_search_for(topic, DatasetSearch) result = search.query(query) self.assertEqual(len(result), 0)
def datasets(topic): kwargs = multi_to_dict(request.args) kwargs.pop('topic', None) topic_search = topic_search_for(topic, DatasetSearch, facets=True, **kwargs) return theme.render('topic/datasets.html', topic=topic, datasets=search.query(topic_search))
def datasets(topic): kwargs = multi_to_dict(request.args) kwargs.pop('topic', None) topic_search = topic_search_for(topic, DatasetSearch, facets=True, **kwargs) return theme.render( 'topic/datasets.html', topic=topic, datasets=search.query(topic_search) )
def reuses(topic): kwargs = multi_to_dict(request.args) kwargs.pop('topic', None) topic_search = topic_search_for(topic, ReuseSearch, facets=True, **kwargs) return theme.render( 'topic/reuses.html', topic=topic, reuses=search.query(topic_search) )
def test_should_not_fail_on_missing_objects(self, autoindex): with autoindex: FakeFactory.create_batch(3) deleted_fake = FakeFactory() result = search.query(FakeSearch) deleted_fake.delete() assert len(result) == 4 # Missing object should be filtered out objects = result.objects assert len(objects) == 3 for o in objects: assert isinstance(o, Fake)
def test_should_not_fail_on_missing_objects(self): with self.autoindex(): FakeFactory.create_batch(3) deleted_fake = FakeFactory() result = search.query(FakeSearch) deleted_fake.delete() self.assertEqual(len(result), 4) # Missing object should be filtered out objects = result.objects self.assertEqual(len(objects), 3) for o in objects: self.assertIsInstance(o, Fake)
def test_empty_search_with_match(self): '''Should only return data with at least one tag''' with self.autoindex(): included = VisibleDatasetFactory.create_batch(2, tags=['in']) excluded = VisibleDatasetFactory.create_batch(2, tags=['out']) topic = TopicFactory(tags=['in', 'no-match']) query = topic_search_for(topic, DatasetSearch) result = search.query(query) found = [d.id for d in result] self.assertEqual(len(found), 2) for dataset in included: self.assertIn(dataset.id, found) for dataset in excluded: self.assertNotIn(dataset.id, found)
def get(self): return search.query(DatasetSearch, **multi_to_dict(request.args))
def get(self): search_parser.parse_args() return search.query(ReuseSearch, **multi_to_dict(request.args))
def get(self): '''List all users''' search_parser.parse_args() return search.query(UserSearch, **multi_to_dict(request.args))
def get_queryset(self): params = multi_to_dict(request.args) params['facets'] = True return search.query(self.search_adapter or self.model, **params)
def get(self): return search.query(ReuseSearch, **multi_to_dict(request.args))
def get(self): '''List or search all organizations''' search_parser.parse_args() return search.query(OrganizationSearch, **multi_to_dict(request.args))
def test_execute_search_result_with_model(self): '''Should return a SearchResult with the right model''' result = search.query(Fake) assert isinstance(result, search.SearchResult) assert result.query.adapter == FakeSearch
def get(self): '''List or search all datasets''' return search.query(DatasetSearch, **multi_to_dict(request.args))
def test_execute_search_result(self): '''SearchQuery execution should return a SearchResult with the right model''' result = search.query(FakeSearch) self.assertIsInstance(result, search.SearchResult) self.assertEqual(result.query.adapter, FakeSearch)
def get(self): """List or search all organizations""" return search.query(OrganizationSearch, **multi_to_dict(request.args))
def test_execute_search_result_with_model(self): '''SearchQuery execution from a model should return a SearchResult with the right model''' result = search.query(Fake) self.assertIsInstance(result, search.SearchResult) self.assertEqual(result.query.adapter, FakeSearch)
def get_queryset(self): return search.query(self.search_adapter, **multi_to_dict(request.args))
def test_execute_search_result_with_model(self): '''Should return a SearchResult with the right model''' self.init_search() result = search.query(Fake) self.assertIsInstance(result, search.SearchResult) self.assertEqual(result.query.adapter, FakeSearch)
def get(self): '''List or search all datasets''' search_parser.parse_args() return search.query(Dataset, **multi_to_dict(request.args))