def search(request): term = request.REQUEST.get('term') if not term: raise Http404() si = SearchIndex() result = si.search(term) return HttpResponse(json.dumps(result))
def ask(self, title, content, lat, lng): centroid = (lng, lat) search = SearchIndex() tags = search.parse(title) self.update_tags(tags=tags) question = Question.create(title=title, area_slug=self.area_slug, centroid=centroid, author_name=self.username, content=content, tags=tags) self.publish(question)
def create_tag(cls, name_zh, *args, **kwargs): name_zh = to_unicode(name_zh) name_en = unidecode(name_zh) slug = slugify(name_en) tag = cls(slug=slug, name_en=name_en, name_zh=name_zh, *args, **kwargs) try: tag.save() except Exception as err: logging.info("Save Tag Err name_zh %s: err %s" %(name_zh, err)) return None tag.to_info() si = SearchIndex() si.add_tag(tag) return tag
def all_to_search_index(cls): tags = cls.objects() si = SearchIndex() for tag in tags: si.add_tag(tag)