def search(request): ix = getdatastoreindex("search", schema=SEARCHSCHEMA) if request.GET.has_key("query"): ix = getdatastoreindex("search", schema=SEARCHSCHEMA) parser = MultifieldParser(["title", "description", "keywords", "page"], schema = ix.schema) query = parser.parse(request.GET['query']) title = "Search Results - %s" % request.GET['query'] results = ix.searcher().search(query) results.model = Page return object_list(request, results, paginate_by=100, extra_context={'object_list': results, 'title': title, 'query': request.GET['query']}) else: return HttpResponseRedirect(reverse("search.index"))
def get(self): self.response.out.write('<html><body>') self.response.out.write(""" <form action="/search" method="get"> <div><input name="query" type="text" value=""><input type="submit" value="Search"></div> </form> </body> </html>""") ix = getdatastoreindex("hello", schema=SEARCHSCHEMA) parser = QueryParser("content", schema=ix.schema) q = parser.parse(self.request.get('query')) results = ix.searcher().search(q) for result in results: self.response.out.write('<blockquote>%s</blockquote>' % cgi.escape(result['content'])) # Write the submission form and the footer of the page self.response.out.write(""" <form action="/sign" method="post"> <div><textarea name="content" rows="3" cols="60"></textarea></div> <div><input type="submit" value="Sign Guestbook"></div> </form> </body> </html>""")
def post(self): user = self.getAuthentificatedUser() if not user: return try: id = int(self.request.get('post_id')) post = Post().get(db.Key.from_path('Post', id)) if post.author != user: self.redirect('/') return body = db.Text(strip_ml_tags(self.request.get('body'))) postmarkup = create(use_pygments=False) post.body = postmarkup(body) # replace('\n','<br />') if post.body != '': post.put() # re-index it! ix = getdatastoreindex("post_"+str(post.key().id()), schema=SEARCHSCHEMA) writer = ix.writer() writer.add_document(body=u"%s" % post.body) writer.commit() except: pass if self.request.get('page'): self.redirect('/view?id=' + str(self.request.get('id')) + '&page=' + self.request.get('page')) else: self.redirect('/view?id=' + str(self.request.get('id')))
def get(self): #ix = getdatastoreindex("hello", schema=SEARCHSCHEMA) ix = getdatastoreindex("hello", schema=SEARCHSCHEMA) courses=models.Course().all() for course in courses: writer = ix.writer() writer.add_document(title=course.name, content=course.description, path=course.course_id) writer.commit()
def post(self): user = self.getAuthentificatedUser() if not user: return try: id = int(self.request.get('id')) topic = Topic().get(db.Key.from_path('Topic', id)) preview = self.request.get('preview', None) if preview is not None: forum = self.getForumInstance() postmarkup = create(use_pygments=False) body = strip_ml_tags(self.request.get('body')) body2 = postmarkup(body) template_values = { 'url' : users.CreateLogoutURL(self.request.uri), 'user' : user, 'forum' : forum, 'topic' : topic, 'body' : body, 'body2' : body2, 'page' : 100 } path = os.path.join(os.path.dirname(__file__), os.path.join('templates', 'previewPost.htm')) self.response.out.write(template.render(path, template_values)) return except: self.redirect('/') return post = Post() #parent=topic.key() post.topic = topic if users.get_current_user(): post.author = users.get_current_user() body = db.Text(strip_ml_tags(self.request.get('body'))) postmarkup = create(use_pygments=False) post.body = postmarkup(body) # replace('\n','<br />') if post.body != '': post.put() # index it! ix = getdatastoreindex("post_"+str(post.key().id()), schema=SEARCHSCHEMA) writer = ix.writer() writer.add_document(body=u"%s" % post.body) writer.commit() # end index mailAdditionalText = """ ... testing e-mail notification. Sorry if you get this message accidently.""" post.sendMailToAll(user.email(), mailAdditionalText) ##### #message = mail.EmailMessage(sender=user.email(), subject="New message in small-forum") #message.to = "log1 (sms) <*****@*****.**>" #message.body = post.body #message.send() ##### # To Do if self.request.get('page'): self.redirect('/view?id=' + str(self.request.get('id')) + '&page=' + self.request.get('page')) else: self.redirect('/view?id=' + str(self.request.get('id')))
def search_query(str): """""" log.debug("Search request is processing.") index = getdatastoreindex("articles", schema=DOCUMENTS_SCHEMA) parser = QueryParser("content", schema=index.schema) query = parser.parse(str) results = index.searcher().search(query) # log results log.debug("search results are %s" % results)
def update_search(sender, instance, **kwargs): ix = getdatastoreindex("search", schema=SEARCHSCHEMA) writer = ix.writer() writer.update_document( url=u"%s" % instance.url, title=instance.title, description=instance.description, keywords=instance.keywords, page=instance.page, ) writer.commit()
def searchTextInTopic(self, entity, whatTextSearchFor): postKeys = [] for post in entity.posts: ix = getdatastoreindex("post_"+str(post.key().id()), schema=SEARCHSCHEMA) parser = QueryParser("body", schema = ix.schema) q = parser.parse(whatTextSearchFor) results = ix.searcher().search(q) for result in results: if result['body'] != '': postKeys.append(post) break return postKeys
def get(self): ix = getdatastoreindex("hello", schema=SEARCHSCHEMA) parser = QueryParser("content", schema = ix.schema) q = parser.parse(self.request.get('query')) results = ix.searcher().search(q) r=[] for result in results: rr={"name":result['title'], "id":result['path']} r.append(rr) template_values = {"results":r} path = os.path.join(os.path.dirname(__file__), 'search.html') self.response.out.write(template.render(path, template_values))
def exec_add_docs_to_index(): """It's temporary decision and have to be moved to task scheduler""" # check unindexed documents queue query = DocumentsQueue.all() # NOTE: here is used fetch without params because it's suspected that # there always will be just few documents in the queue docs_to_index = query.fetch() if None != docs_to_index: # get index writer and index required documents index = getdatastoreindex("articles", schema=DOCUMENTS_SCHEMA) writer = index.writer() for doc in docs_to_index: # retrieve content of appropriate documents and write index it writer.add_document( title=doc.document.get_title(), id=doc.document.get_id(), content=doc.document.get_content() ) writer.commit()
def post(self): ix = getdatastoreindex("hello", schema=SEARCHSCHEMA) writer = ix.writer() writer.add_document(content=u"%s" % self.request.get('content')) writer.commit() self.redirect('/')
def delete_search(sender, instance, **kwargs): ix = getdatastoreindex("search", schema=SEARCHSCHEMA) ix.delete_by_term("url", u"%s" % instance.url) ix.commit()