From 321a0ea6a0d20e68c872e179cf83a1b1da96331e Mon Sep 17 00:00:00 2001 From: Andy Armstrong Date: Wed, 9 Sep 2015 14:16:05 -0400 Subject: [PATCH] Fix searching with Chinese characters TNL-3228 --- lms/djangoapps/teams/search_indexes.py | 6 +++--- lms/djangoapps/teams/tests/test_views.py | 12 +++++++++++- lms/djangoapps/teams/views.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lms/djangoapps/teams/search_indexes.py b/lms/djangoapps/teams/search_indexes.py index cc743401b6..9299f31d1b 100644 --- a/lms/djangoapps/teams/search_indexes.py +++ b/lms/djangoapps/teams/search_indexes.py @@ -48,9 +48,9 @@ class CourseTeamIndexer(object): """ # Always use the English version of any localizable strings (see TNL-3239) with translation.override('en'): - return "{name}\n{description}\n{country}\n{language}".format( - name=self.course_team.name.encode('utf-8'), - description=self.course_team.description.encode('utf-8'), + return u"{name}\n{description}\n{country}\n{language}".format( + name=self.course_team.name, + description=self.course_team.description, country=self.course_team.country.name.format(), language=self._language_name() ) diff --git a/lms/djangoapps/teams/tests/test_views.py b/lms/djangoapps/teams/tests/test_views.py index 85a980e630..8c0e0cd3e1 100644 --- a/lms/djangoapps/teams/tests/test_views.py +++ b/lms/djangoapps/teams/tests/test_views.py @@ -224,6 +224,14 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): course_id=self.test_course_2.id, topic_id='topic_7' ) + self.chinese_team = CourseTeamFactory.create( + name=u'著文企臺個', + description=u'共樣地面較,件展冷不護者這與民教過住意,國制銀產物助音是勢一友', + country='CN', + language='zh_HANS', + course_id=self.test_course_2.id, + topic_id='topic_7' + ) self.test_team_name_id_map = {team.name: team for team in ( self.solar_team, @@ -232,6 +240,7 @@ class TeamAPITestCase(APITestCase, SharedModuleStoreTestCase): self.another_team, self.public_profile_team, self.search_team, + self.chinese_team, )} for user, course in [('staff', self.test_course_1), ('course_staff', self.test_course_1)]: @@ -438,7 +447,7 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase): self.verify_names( {'course_id': self.test_course_2.id}, 200, - ['Another Team', 'Public Profile Team', 'Search'], + ['Another Team', 'Public Profile Team', 'Search', u'著文企臺個'], user='staff' ) @@ -517,6 +526,7 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase): ('Island', ['Search']), ('not-a-query', []), ('team', ['Another Team', 'Public Profile Team']), + (u'著文企臺個', [u'著文企臺個']), ) @ddt.unpack def test_text_search(self, text_search, expected_team_names): diff --git a/lms/djangoapps/teams/views.py b/lms/djangoapps/teams/views.py index 9a88a2526c..cdf20060a9 100644 --- a/lms/djangoapps/teams/views.py +++ b/lms/djangoapps/teams/views.py @@ -333,7 +333,7 @@ class TeamsListView(ExpandableFieldViewMixin, GenericAPIView): result_filter.update({'course_id': course_id_string}) search_results = search_engine.search( - query_string=text_search.encode('utf-8'), + query_string=text_search, field_dictionary=result_filter, size=MAXIMUM_SEARCH_SIZE, )