From 11bd953e2f67c310e0e81576ff6ce6b063cb4a04 Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Thu, 2 Jan 2014 16:16:58 -0500 Subject: [PATCH] Index tags correctly --- karmaworld/apps/notes/search.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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) -- 2.25.1