From 67cb316ba2ceb4459ca7fd06129c3b6e3b83c8fc Mon Sep 17 00:00:00 2001 From: Timotheus Kampik Date: Sun, 22 Jul 2018 11:01:28 +0200 Subject: [PATCH] move templating from `searchtools` to `documentation_options` --- .../basic/static/documentation_options.js_t | 16 +++- .../{searchtools.js_t => searchtools.js} | 78 +++++++++---------- 2 files changed, 50 insertions(+), 44 deletions(-) rename sphinx/themes/basic/static/{searchtools.js_t => searchtools.js} (91%) diff --git a/sphinx/themes/basic/static/documentation_options.js_t b/sphinx/themes/basic/static/documentation_options.js_t index 66d4bab88..bd32e356b 100644 --- a/sphinx/themes/basic/static/documentation_options.js_t +++ b/sphinx/themes/basic/static/documentation_options.js_t @@ -6,5 +6,19 @@ var DOCUMENTATION_OPTIONS = { FILE_SUFFIX: '{{ '' if no_search_suffix else file_suffix }}', HAS_SOURCE: {{ has_source|lower }}, SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}', - NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}} + NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}}, + SEARCH_LANGUAGE_STOP_WORDS: {{ search_language_stop_words }} }; + + +{% if search_language_stemming_code %} +/* Non-minified version JS is _stemmer.js if file is provided */ {% endif -%} +{{ search_language_stemming_code|safe }} + +{% if search_scorer_tool %} +{{ search_scorer_tool|safe }} +{% endif -%} + +{% if search_word_splitter_code %} +{{ search_word_splitter_code }} +{% endif -%} diff --git a/sphinx/themes/basic/static/searchtools.js_t b/sphinx/themes/basic/static/searchtools.js similarity index 91% rename from sphinx/themes/basic/static/searchtools.js_t rename to sphinx/themes/basic/static/searchtools.js index e707bb1ea..34d7db2e3 100644 --- a/sphinx/themes/basic/static/searchtools.js_t +++ b/sphinx/themes/basic/static/searchtools.js @@ -9,51 +9,43 @@ * */ -{% if search_language_stemming_code %} -/* Non-minified version JS is _stemmer.js if file is provided */ {% endif -%} -{{ search_language_stemming_code|safe }} +if (!Scorer) { + /** + * Simple result scoring code. + */ + var Scorer = { + // Implement the following function to further tweak the score for each result + // The function takes a result array [filename, title, anchor, descr, score] + // and returns the new score. + /* + score: function(result) { + return result[4]; + }, + */ -{% if search_scorer_tool %} -{{ search_scorer_tool|safe }} -{% else %} -/** - * Simple result scoring code. - */ -var Scorer = { - // Implement the following function to further tweak the score for each result - // The function takes a result array [filename, title, anchor, descr, score] - // and returns the new score. - /* - score: function(result) { - return result[4]; - }, - */ + // query matches the full name of an object + objNameMatch: 11, + // or matches in the last dotted part of the object name + objPartialMatch: 6, + // Additive scores depending on the priority of the object + objPrio: {0: 15, // used to be importantResults + 1: 5, // used to be objectResults + 2: -5}, // used to be unimportantResults + // Used when the priority is not in the mapping. + objPrioDefault: 0, - // query matches the full name of an object - objNameMatch: 11, - // or matches in the last dotted part of the object name - objPartialMatch: 6, - // Additive scores depending on the priority of the object - objPrio: {0: 15, // used to be importantResults - 1: 5, // used to be objectResults - 2: -5}, // used to be unimportantResults - // Used when the priority is not in the mapping. - objPrioDefault: 0, - - // query found in title - title: 15, - // query found in terms - term: 5 -}; -{% endif %} - -{% if search_word_splitter_code %} -{{ search_word_splitter_code }} -{% else %} -function splitQuery(query) { - return query.split(/\s+/); + // query found in title + title: 15, + // query found in terms + term: 5 + }; +} + +if (!splitQuery) { + function splitQuery(query) { + return query.split(/\s+/); + } } -{% endif %} /** * Search Module @@ -146,7 +138,7 @@ var Search = { */ query : function(query) { var i; - var stopwords = {{ search_language_stop_words }}; + var stopwords = DOCUMENTATION_OPTIONS.SEARCH_LANGUAGE_STOP_WORDS; // stem the searchterms and add them to the correct list var stemmer = new Stemmer();