def test_specificity_of_organisation_search(self): queryset = Fixtures.es_organisation_connection() exact_query = "Scottish Optometrist Society" inexact_query = "Scottish Optometrist Society Glasgow" undesired_query = "Scottish Ontology Society" result_exact_query = filter_organisations_by_query(queryset, exact_query).execute() result_inexact_query = filter_organisations_by_query(queryset, inexact_query).execute() result_undesired_query = filter_organisations_by_query(queryset, undesired_query).execute() while len(result_inexact_query) == 0: inexact_query = inexact_query[:-1] result_inexact_query = filter_organisations_by_query(queryset, inexact_query).execute() self.assertEqual(result_exact_query[0].name, self.org2.name) self.assertEqual(result_inexact_query[0].name, self.org2.name)
def test_organisation_filter_organisations_by_query(self): queryset = Fixtures.es_organisation_connection() self.org.name = "banana weird" self.org.save() result = filter_organisations_by_query(queryset, "banana") result = order_organistations_by_created_on(result).execute() self.assertEqual(result[0].name, self.org.name)
def filter_queryset(self, queryset): query = self.request.GET.get('q') claimed_status = self.request.GET.get('is_claimed') if claimed_status: queryset = filter_by_claimed_status(queryset, claimed_status) if query: if self.request.user.is_authenticated() and ( self.request.user.is_staff): queryset = filter_organisations_by_query(queryset, query) else: queryset = filter_organisations_by_query_published( queryset, query) return queryset
def test_organisation_filter_organisations_by_query_published(self): queryset = Fixtures.es_organisation_connection() published_org = Organisation.objects.create(name="Banana Published") unpublished_org = Organisation.objects.create(name="Banana Unpublished") unpublished_org.published = False unpublished_org.save() result_all = filter_organisations_by_query(queryset, "Banana") result_all = order_organistations_by_created_on(result_all).execute() result_published = filter_organisations_by_query_published(queryset, "Banana") result_published = order_organistations_by_created_on(result_published).execute() self.assertEqual(unpublished_org.published, False) self.assertEqual(result_all[0].name, unpublished_org.name) self.assertEqual(result_published[0].name, published_org.name)
def get_queryset(self, *args, **kwargs): connections.create_connection( hosts=[settings.ELASTICSEARCH_URL], timeout=20, http_auth=(settings.ELASTICSEARCH_USERNAME, settings.ELASTICSEARCH_PASSWORD)) queryset = Search(index='organisation_search', doc_type='organisation') query = self.request.GET.get('q') if query: if self.request.user.is_authenticated() and ( self.request.user.is_editor or self.request.user.is_staff): queryset = filter_organisations_by_query(queryset, query) else: queryset = filter_organisations_by_query_published( queryset, query) return queryset