allow search hits in body text that are in title of other doc #2891 (#2971)

* allow search hits in body text that are in title of other doc #2891

* shorten lines/add line breaks #2891

* remove out-commented LoC, simplify check #2891
This commit is contained in:
Timotheus Kampik
2016-10-10 17:42:41 +02:00
committed by Takeshi KOMIYA
parent 71a36d5b33
commit de7c93756c
4 changed files with 29 additions and 2 deletions

View File

@@ -397,7 +397,8 @@ class IndexBuilder(object):
# again, stemmer must not remove words from search index
if not _filter(stemmed_word) and _filter(word):
stemmed_word = word
if stemmed_word not in self._title_mapping and _filter(stemmed_word):
already_indexed = docname in self._title_mapping.get(stemmed_word, [])
if _filter(stemmed_word) and not already_indexed:
self._mapping.setdefault(stemmed_word, set()).add(docname)
def context_for_searchtool(self):

View File

@@ -11,4 +11,10 @@ Stemmer
=======
zfs
findthisstemmedkey
findthisstemmedkey
textinheading
.. toctree::
tocitem

View File

@@ -0,0 +1,10 @@
heading 1
=========
lorem ipsum
textinheading
=============
lorem ipsum

View File

@@ -105,3 +105,13 @@ def test_stemmer_does_not_remove_short_words(app, status, warning):
def test_stemmer(app, status, warning):
searchindex = (app.outdir / 'searchindex.js').text()
assert 'findthisstemmedkei' in searchindex
@with_app(testroot='search')
def test_term_in_heading_and_section(app, status, warning):
searchindex = (app.outdir / 'searchindex.js').text()
# if search term is in the title of one doc and in the text of another
# both documents should be a hit in the search index as a title,
# respectively text hit
assert 'textinhead:1' in searchindex
assert 'textinhead:0' in searchindex