Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sphinx/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def stem(word):
# 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):
Expand Down
8 changes: 7 additions & 1 deletion tests/roots/test-search/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ Stemmer
=======

zfs
findthisstemmedkey
findthisstemmedkey

textinheading

.. toctree::

tocitem
10 changes: 10 additions & 0 deletions tests/roots/test-search/tocitem.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
heading 1
=========

lorem ipsum


textinheading
=============

lorem ipsum
10 changes: 10 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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