Skip to content

Commit

Permalink
search: dump searchindex.js with minimal JSON separators
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Oct 22, 2024
1 parent 8042eb6 commit 6616c77
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion sphinx/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ class _JavaScriptIndex:
SUFFIX = ')'

def dumps(self, data: Any) -> str:
return self.PREFIX + json.dumps(data, sort_keys=True) + self.SUFFIX
return (
self.PREFIX
+ json.dumps(data, separators=(',', ':'), sort_keys=True)
+ self.SUFFIX
)

def loads(self, s: str) -> Any:
data = s[len(self.PREFIX) : -len(self.SUFFIX)]
Expand Down
2 changes: 1 addition & 1 deletion tests/js/fixtures/cpp/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/multiterm/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/partial/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/js/fixtures/titles/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def test_term_in_heading_and_section(app):
# 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": 2' in searchindex
assert '"textinhead": 0' in searchindex
assert '"textinhead":2' in searchindex
assert '"textinhead":0' in searchindex


@pytest.mark.sphinx('html', testroot='search')
Expand Down

0 comments on commit 6616c77

Please sign in to comment.