X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/8b808f24709efb16f6b6eff6abb05b41341573c7..153bc4288d5941dafcaca24fe1f4859419d744e0:/apps/search/index.py?ds=sidebyside diff --git a/apps/search/index.py b/apps/search/index.py index 32cf5f922..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): @@ -111,7 +112,7 @@ class Index(SolrIndex): Class indexing books. """ def __init__(self): - super(Index, self).__init__() + super(Index, self).__init__(mode='rw') def delete_query(self, *queries): """ @@ -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: @@ -202,7 +204,6 @@ class Index(SolrIndex): "uid": "tag%d" % tag.id } self.index.add(doc) - print "%s %s" % (doc['tag_name'], doc['tag_category']) 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'] @@ -257,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'] @@ -461,7 +463,6 @@ class Index(SolrIndex): doc = add_part(snippets, header_index=position, header_type=header.tag, text=u''.join(footnote), is_footnote=True) - self.index.add(doc) #print "@ footnote text: %s" % footnote footnote = [] @@ -518,12 +519,13 @@ class Index(SolrIndex): class SearchResult(object): - def __init__(self, doc, how_found=None, query=None): + def __init__(self, doc, how_found=None, query=None, query_terms=None): # self.search = search self.boost = 1.0 self._hits = [] self._processed_hits = None # processed hits self.snippets = [] + self.query_terms = query_terms if 'score' in doc: self._score = doc['score'] @@ -551,7 +553,9 @@ class SearchResult(object): hit = (sec + (header_span,), fragment, self._score, { 'how_found': how_found, 'snippets_pos': snippets_pos, - 'snippets_revision': snippets_rev + 'snippets_revision': snippets_rev, + 'themes': doc.get('themes', []), + 'themes_pl': doc.get('themes_pl', []) }) self._hits.append(hit) @@ -559,7 +563,7 @@ class SearchResult(object): def __unicode__(self): return u"