X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ca7bffa0f660afefb98d37ac002b9652e1c858e5..f3acfae26c01f08232af6f4b48e9a2ea54a0c2da:/apps/search/index.py diff --git a/apps/search/index.py b/apps/search/index.py index 4962cae99..556bbfe5c 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): """ @@ -240,7 +241,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'] @@ -256,6 +257,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'] @@ -460,7 +462,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 = [] @@ -649,7 +650,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() @@ -722,7 +722,7 @@ class Search(SolrIndex): Search facilities. """ def __init__(self, default_field="text"): - super(Search, self).__init__() + super(Search, self).__init__(mode='r') # def get_tokens(self, searched, field='text', cached=None): # """returns tokens analyzed by a proper (for a field) analyzer @@ -793,6 +793,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) @@ -954,7 +955,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: @@ -971,6 +971,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):