Skip to content

Commit

Permalink
Merge pull request #7801 from unoplatform/dev/altre/docfx-search
Browse files Browse the repository at this point in the history
feat(docs): Search with partial words
  • Loading branch information
jeromelaban authored Jan 13, 2022
2 parents 82367b0 + 064597a commit b295720
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions doc/templates/uno/service/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,32 @@ function enableSearch() {
indexReady.promise().done(function () {

$("body").on("query-ready", function () {
worker.postMessage({q: query});
postSearchQuery(worker, query);
});

if (query && (query.length >= 3)) {
worker.postMessage({q: query});
}
postSearchQuery(worker, query);

}).then(r => r.resolve());
}

// Highlight the searching keywords
/**
* This function posts the message to the worker if the string has at least
* three characters.
*
* @param worker The search worker used by DocFx (lunr)
* @param searchQuery The string to post to the worker.
*/
function postSearchQuery(worker, searchQuery) {
if (searchQuery && (searchQuery.length >= 3)) {
worker.postMessage({q: `${searchQuery}*`});
} else {
worker.postMessage({q: ''});
}
}

/**
* Highlight the searching keywords
*/
function highlightKeywords() {
const q = url('?q');
if (q != null) {
Expand All @@ -182,9 +197,9 @@ function enableSearch() {
return e.key !== 'Enter';
});

searchQuery.on("keyup", function () {
searchQuery.on("keyup", function (e) {
$('#search-results').show();
query = $(this).val();
query = `${e.target.value}`;
$("body").trigger("query-ready");
$('#search-results>.search-list').text('Search Results for "' + query + '"');
}).off("keydown");
Expand Down
Loading

0 comments on commit b295720

Please sign in to comment.