From: Marcin Koziej Date: Fri, 24 Aug 2012 12:04:09 +0000 (+0200) Subject: theme hits work! X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/ca7bffa0f660afefb98d37ac002b9652e1c858e5?hp=-c theme hits work! --- ca7bffa0f660afefb98d37ac002b9652e1c858e5 diff --git a/apps/search/custom.py b/apps/search/custom.py index fcc3bace2..33ce47d32 100644 --- a/apps/search/custom.py +++ b/apps/search/custom.py @@ -8,8 +8,6 @@ import copy class TermVectorOptions(search.Options): - option_name = "tv" - def __init__(self, schema, original=None): self.schema = schema if original is None: @@ -30,7 +28,8 @@ class TermVectorOptions(search.Options): def options(self): opts = {} - opts['tv'] = 'true' + if self.positions or self.fields: + opts['tv'] = 'true' if self.positions: opts['tv.positions'] = 'true' if self.fields: @@ -72,12 +71,12 @@ def __term_vector(self, positions=False, fields=None): newself.term_vectorer.update(positions, fields) return newself setattr(search.SolrSearch, 'term_vector', __term_vector) -__original__init_common_modules = search.SolrSearch._init_common_modules def __patched__init_common_modules(self): __original__init_common_modules(self) self.term_vectorer = TermVectorOptions(self.schema) +__original__init_common_modules = search.SolrSearch._init_common_modules setattr(search.SolrSearch, '_init_common_modules', __patched__init_common_modules) @@ -118,7 +117,6 @@ class CustomSolrInterface(sunburnt.SolrInterface): end = int(wrd.xpath("int[@name='end']")[0].text) matches.add((start, end)) - print matches if matches: return self.substring(kwargs['text'], matches, margins=kwargs.get('margins', 30), @@ -127,8 +125,8 @@ class CustomSolrInterface(sunburnt.SolrInterface): return None def analyze(self, **kwargs): - doc = self._analyze(self, **kwargs) - terms = doc.xpath("/lst[@name='index']/arr[last()]/lst/str[1]") + doc = self._analyze(**kwargs) + terms = doc.xpath("//lst[@name='index']/arr[last()]/lst/str[1]") terms = map(lambda n: unicode(n.text), terms) return terms @@ -154,3 +152,4 @@ class CustomSolrInterface(sunburnt.SolrInterface): snip = snip[:s + off] + mark[0] + snip[s + off:] # maybe break on word boundaries return snip + diff --git a/apps/search/index.py b/apps/search/index.py index 32cf5f922..4962cae99 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -202,7 +202,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): """ @@ -518,12 +517,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 +551,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 +561,7 @@ class SearchResult(object): def __unicode__(self): return u"