def get(self):
        print "Run BuildCompletionIndexHandler"
        keywords = []
        known_keywords = set()
        completionindex = CompletionIndex.query().get()
        if not completionindex:
            # No completionindex existing
            completionindex=CompletionIndex(keywords=[])
        streams = stream.query().order(-stream.num_of_view, -stream.num_of_pics)
        for temp_stream in streams:
            for temp_word in extract_stream_keywords(temp_stream):
                if temp_word in known_keywords:
                    continue
                keywords.append(temp_word)
                known_keywords.add(temp_word)

        completionindex.keywords = keywords
        completionindex.put()
Пример #2
0
 def get(self):
     print str(self.request.get("keywords"))
     no_backslash_string = str(self.request.get("keywords")).replace("\\"," ")
     keywords = filter(None, re.split(r'[ ,;\t\n\r\s]', no_backslash_string.lower() ) )
     result = []
     completion_words = []
     completion_index = CompletionIndex.query().get()
     if completion_index:
         completion_words = completion_index.keywords
     print completion_words
     for word in completion_words:  # copy
         if any(key in word.lower() for key in keywords):
             result.append(word)
             if len(result) == constants.AUTO_COMPLETE_LENGTH:
                 break
     if result:
         result.sort()
     print ("AutoCompleteHandler: keywords is " + " ".join(keywords))
     self.response.write(json.dumps(result, sort_keys=True))