<field name="authors" type="text_general" stored="false" indexed="true" multiValued="true" termPositions="true" termVectors="true"/>
<field name="translators" type="text_general" stored="false" indexed="true" multiValued="true" termPositions="true" termVectors="true" />
<field name="title" type="text_pl" stored="false" indexed="true"/>
- <field name="title_orig" type="lowercase" stored="true" indexed="true"/>
+ <field name="title_orig" type="lowercase" stored="false" indexed="true"/>
<!-- <field name="published_date" type="tdate" stored="false" indexed="true"/>-->
<field name="published_date" type="string" stored="true" indexed="true"/>
+ <field name="metadata" type="lowercase" stored="false" indexed="true"/>
+
<field name="themes" type="lowercase" stored="true" indexed="true" termVectors="true" termPositions="true" multiValued="true" />
<field name="themes_pl" type="text_pl" stored="true" indexed="true" termVectors="true" termPositions="true" multiValued="true" />
<field name="header_index" type="int" stored="true" indexed="true"/>
{% if hit.snippet %}
{{hit.snippet|safe}}
{% else %}
- {{hit.fragment.text|truncatewords_html:15|safe}}
+ {{hit.fragment.text|truncatewords_html:15|safe}} {# bad, now impossible #}
{% endif %}
</a>
</div>
off = -start
snip = snip[:e + off] + mark[1] + snip[e + off:]
snip = snip[:s + off] + mark[0] + snip[s + off:]
+ snip = re.sub('%s[ \t\n]+%s' % (mark[1], mark[0]), " ", snip)
return snip
]
ignore_content_tags = [
- 'uwaga', 'extra',
+ 'uwaga', 'extra', 'nota_red',
'zastepnik_tekstu', 'sekcja_asterysk', 'separator_linia', 'zastepnik_wersu',
'didaskalia',
'naglowek_aktu', 'naglowek_sceny', 'naglowek_czesc',
if master is None:
return []
- def walker(node, ignore_tags=()):
- if node.tag not in ignore_tags:
+ def walker(node):
+ if node.tag not in self.ignore_content_tags:
yield node, None, None
if node.text is not None:
yield None, node.text, None
book.id, doc['header_index'], doc['header_span'], doc.get('fragment_anchor', ''))
return doc
- def give_me_utf8(s):
- if isinstance(s, unicode):
- return s.encode('utf-8')
- else:
- return s
-
fragments = {}
snippets = Snippets(book.id).open('w')
try:
content.append(text)
handle_text = [all_content]
- for start, text, end in walker(header, ignore_tags=self.ignore_content_tags):
+ for start, text, end in walker(header):
# handle footnotes
if start is not None and start.tag in self.footnote_tags:
footnote = []
text = snippets.get((int(position),
int(length)))
snip = self.index.highlight(text=text, field=field, q=query)
- snips[idx] = snip
- if snip:
- num -= 1
+ if snip not in snips:
+ snips[idx] = snip
+ if snip:
+ num -= 1
idx += 1
except IOError, e:
# We don't need hits which lead to sections but do not have
# snippets.
hits = filter(lambda (idx, h):
- 'fragment' in h or
result.snippets[idx] is not None,
enumerate(result.hits))
# print "[tmpl: from %d hits selected %d]" % (len(result.hits), len(hits))
continue
snip = result.snippets[idx]
# fix some formattting
- snip = re.subn(r"(^[ \t\n]+|[ \t\n]+$)", u"",
- re.subn(r"[ \t\n]*\n[ \t\n]*", u"\n", snip)[0])[0]
+ snip = re.sub(r"[ \t\n]*\n[ \t\n]*", u"\n", snip)
+ snip = re.sub(r"(^[ \t\n]+|[ \t\n]+$)", u"", snip)
snip = snip.replace("\n", "<br />").replace('---', '—')
hit['snippet'] = snip
return {
'request': context['request'],
'book': book,
- 'hits': hits and zip(*hits)[1] or []
+ 'hits': zip(*hits)[1] if hits else []
}
text_phrase = filter(ensure_exists, text_phrase)
everywhere = filter(ensure_exists, everywhere)
- results = author_results + translator_results + title_results + text_phrase + everywhere
# ensure books do exists & sort them
for res in (author_results, translator_results, title_results, text_phrase, everywhere):
res.sort(reverse=True)
# #frag = Fragment.objects.get(anchor=anchor)
# return HttpResponseRedirect(fragment_hits[0]['fragment'].get_absolute_url())
# return HttpResponseRedirect(results[0].book.get_absolute_url())
- if len(results) == 0:
+ if not (author_results or translator_results or title_results or text_phrase or everywhere):
form = PublishingSuggestForm(initial={"books": query + ", "})
return render_to_response(
'catalogue/search_no_hits.html',