Beispiel #1
0
 def getTitleWords(self, game):
     stemmer = CustomStemmer()
     title_words_list = re.compile('[\w]+').findall(game.title)
     title_words = []
     for element in title_words_list:
             t_word = stemmer.stem(element)
             if t_word:
                 title_words.append(t_word)
     return title_words
Beispiel #2
0
 def get_queryset(self):
     selected_genre = self.request.GET.get('genre')
     selected_platform = self.request.GET.get('platform')
     search_string = self.request.GET.get('search')
     
     try:
         genreobj = Genre.objects.get(id=selected_genre)
     except:
         genreobj = None
     
     try:
         platformobj = Platform.objects.get(id=selected_platform)
     except:
         platformobj = None
     
     if not search_string:
         if genreobj and platformobj:
             games = genreobj.game_set.filter(platform=platformobj).order_by('title')
         elif genreobj:
             games = genreobj.game_set.all().order_by('title')
         elif platformobj:
             games = platformobj.game_set.all().order_by('title')
         else:
             games = Game.objects.all().order_by('title')
     else:
         games = []
         title_games = []
         other_games = []
         words = []
         words_list = re.compile('[\w]+').findall(search_string)
         
         ''' Stem the word '''
         stemmer = CustomStemmer()
         for element in words_list:
             word = stemmer.stem(element)
             if word:
                 words.append(word)
                 
         for word in words:
             try:
                 keywordobj = GameKeyword.objects.get(word=word)
                 
                 if genreobj and platformobj:
                     selected_title_games = keywordobj.title_games.filter(platform=platformobj).filter(genres__id=selected_genre)
                     selected_other_games = keywordobj.other_games.filter(platform=platformobj).filter(genres__id=selected_genre)
                 elif genreobj:
                     selected_title_games = keywordobj.title_games.filter(genres__id=selected_genre)
                     selected_other_games = keywordobj.other_games.filter(genres__id=selected_genre)
                 elif platformobj:
                     selected_title_games = keywordobj.title_games.filter(platform=platformobj)
                     selected_other_games = keywordobj.other_games.filter(platform=platformobj)
                 else:
                     selected_title_games = keywordobj.title_games.all()
                     selected_other_games = keywordobj.other_games.all()
                 
                 if selected_title_games:
                     if title_games:
                         set_selected_title_games = set(selected_title_games)
                         common_title_games = [x for x in title_games if x in set_selected_title_games]
                         set_common_title_games = set(common_title_games)
                         other_uncommon_in_title_games = [x for x in title_games if x not in set_common_title_games]
                         other_uncommon_in_selected_title_games = [x for x in selected_title_games if x not in set_common_title_games]
                         title_games = common_title_games + other_uncommon_in_title_games + other_uncommon_in_selected_title_games
                         #title_games = title_games & set(selected_title_games)
                     else:
                         title_games = set(selected_title_games)
                         
                 if selected_other_games:
                     if other_games:
                         '''
                         set_selected_other_games = set(selected_other_games)
                         common_other_games = [x for x in other_games if x in set_selected_other_games]
                         set_common_other_games = set(common_other_games)
                         other_uncommon_in_other_games = [x for x in other_games if x not in set_common_other_games]
                         other_uncommon_in_selected_other_games = [x for x in selected_other_games if x not in set_common_other_games]
                         other_games = common_other_games + other_uncommon_in_other_games + other_uncommon_in_selected_other_games
                         '''
                         other_games = other_games & set(selected_other_games)
                     else:
                         other_games = set(selected_other_games)
             except:
                 pass
         
         games = list(title_games) + list(other_games)
     return games