From: Charles Connell Date: Thu, 2 Jan 2014 21:16:58 +0000 (-0500) Subject: Index tags correctly X-Git-Tag: release-20150131~327 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=11bd953e2f67c310e0e81576ff6ce6b063cb4a04;p=oweals%2Fkarmaworld.git Index tags correctly --- diff --git a/karmaworld/apps/notes/search.py b/karmaworld/apps/notes/search.py index 039a273..db36aa7 100644 --- a/karmaworld/apps/notes/search.py +++ b/karmaworld/apps/notes/search.py @@ -6,6 +6,10 @@ import time import indextank.client as itc import karmaworld.secret.indexden as secret +import logging + +logger = logging.getLogger(__name__) + api_client = itc.ApiClient(secret.PRIVATE_URL) if not api_client.get_index(secret.INDEX).exists(): api_client.create_index(secret.INDEX, {'public_search': False}) @@ -18,13 +22,11 @@ while not index.has_started(): def note_to_dict(note): d = { 'name': note.name, + 'text': note.text } - if note.text: - d['text'] = note.text - if note.tags.exists(): - d['tags'] = [str(tag) for tag in note.tags.all()] + d['tags'] = ' '.join([str(tag) for tag in note.tags.all()]) if note.course: d['course_id'] = note.course.id @@ -32,7 +34,10 @@ def note_to_dict(note): return d def add_document(note): - index.add_document(note.id, note_to_dict(note)) + if note.text: + index.add_document(note.id, note_to_dict(note)) + else: + logger.warn("Note {n} has no text, will not add to IndexDen".format(n=note)) def remove_document(note): index.delete_document(note.id)