X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/281a6f613c78ffd1fa81951db829a5551fd2e42d..153bc4288d5941dafcaca24fe1f4859419d744e0:/apps/search/index.py?ds=sidebyside diff --git a/apps/search/index.py b/apps/search/index.py index da54fe7f0..26da06220 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -18,6 +18,7 @@ import sunburnt import custom import operator +log = logging.getLogger('search') class SolrIndex(object): def __init__(self, mode=None): @@ -145,6 +146,7 @@ class Index(SolrIndex): Removes all tags from index, then index them again. Indexed fields include: id, name (with and without polish stems), category """ + log.debug("Indexing tags") remove_only = kw.get('remove_only', False) # first, remove tags from index. if tags: @@ -201,7 +203,6 @@ class Index(SolrIndex): "is_pdcounter": False, "uid": "tag%d" % tag.id } - print "ADD 1 %s" % doc self.index.add(doc) def create_book_doc(self, book): @@ -241,7 +242,7 @@ class Index(SolrIndex): self.remove_book(book, remove_snippets=False) book_doc = self.create_book_doc(book) - meta_fields = self.extract_metadata(book, book_info, dc_only=['source_name', 'authors', 'title']) + meta_fields = self.extract_metadata(book, book_info, dc_only=['source_name', 'authors', 'translators', 'title']) # let's not index it - it's only used for extracting publish date if 'source_name' in meta_fields: del meta_fields['source_name'] @@ -250,7 +251,6 @@ class Index(SolrIndex): book_doc[n] = f book_doc['uid'] = "book%s" % book_doc['book_id'] - print "ADD 2 %s" % book_doc self.index.add(book_doc) del book_doc book_fields = { @@ -258,6 +258,7 @@ class Index(SolrIndex): 'authors': meta_fields['authors'], 'published_date': meta_fields['published_date'] } + if 'translators' in meta_fields: book_fields['translators'] = meta_fields['translators'] @@ -462,7 +463,6 @@ class Index(SolrIndex): doc = add_part(snippets, header_index=position, header_type=header.tag, text=u''.join(footnote), is_footnote=True) - print "ADD 3 %s" % doc self.index.add(doc) #print "@ footnote text: %s" % footnote footnote = [] @@ -498,7 +498,6 @@ class Index(SolrIndex): text=fix_format(frag['text']), themes=frag['themes']) #print '@ FRAG %s' % frag['content'] - print "ADD 4 %s" % doc self.index.add(doc) # Collect content. @@ -513,7 +512,6 @@ class Index(SolrIndex): header_type=header.tag, text=fix_format(content)) #print '@ CONTENT: %s' % fix_format(content) - print "ADD 5 %s" % doc self.index.add(doc) finally: @@ -653,7 +651,6 @@ class SearchResult(object): except catalogue.models.Fragment.DoesNotExist: # stale index continue - print f # Figure out if we were searching for a token matching some word in theme name. themes = frag.tags.filter(category='theme') themes_hit = set() @@ -797,6 +794,7 @@ class Search(SolrIndex): modal - applies to boolean query fuzzy - should the query by fuzzy. """ + if query is None: query = '' q = self.index.Q() q = reduce(modal, map(lambda s: self.index.Q(**{field: s}), query.split(r" ")), q) @@ -958,7 +956,6 @@ class Search(SolrIndex): continue text = snippets.get((int(position), int(length))) - print "== %s -- %s ==" % (query, text) snip = self.index.highlight(text=text, field=field, q=query) snips[idx] = snip if snip: @@ -975,6 +972,7 @@ class Search(SolrIndex): snips = map(lambda s: s and s.replace("/\n", "\n"), snips) searchresult.snippets = snips + return snips def hint_tags(self, query, pdcounter=True, prefix=True):