Skip to content

Commit

Permalink
rustdoc-search: remove the now-redundant validateResult
Browse files Browse the repository at this point in the history
This function dates back to 9a45c9d and
seems to have been made obsolete when `addIntoResult` grew the ability to
check the levenshtein distance matching with commit
ba824ec.
  • Loading branch information
notriddle committed Dec 13, 2023
1 parent c3def26 commit fd1d256
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1329,25 +1329,6 @@ function initSearch(rawSearchIndex) {
return 0;
});

let nameSplit = null;
if (parsedQuery.elems.length === 1) {
const hasPath = typeof parsedQuery.elems[0].path === "undefined";
nameSplit = hasPath ? null : parsedQuery.elems[0].path;
}

for (const result of result_list) {
// this validation does not make sense when searching by types
if (result.dontValidate) {
continue;
}
const name = result.item.name.toLowerCase(),
path = result.item.path.toLowerCase(),
parent = result.item.parent;

if (!isType && !validateResult(name, path, nameSplit, parent)) {
result.id = -1;
}
}
return transformResults(result_list);
}

Expand Down Expand Up @@ -2284,44 +2265,6 @@ function initSearch(rawSearchIndex) {
return ret;
}

/**
* Validate performs the following boolean logic. For example:
* "File::open" will give IF A PARENT EXISTS => ("file" && "open")
* exists in (name || path || parent) OR => ("file" && "open") exists in
* (name || path )
*
* This could be written functionally, but I wanted to minimise
* functions on stack.
*
* @param {string} name - The name of the result
* @param {string} path - The path of the result
* @param {string} keys - The keys to be used (["file", "open"])
* @param {Object} parent - The parent of the result
*
* @return {boolean} - Whether the result is valid or not
*/
function validateResult(name, path, keys, parent, maxEditDistance) {
if (!keys || !keys.length) {
return true;
}
for (const key of keys) {
// each check is for validation so we negate the conditions and invalidate
if (!(
// check for an exact name match
name.indexOf(key) > -1 ||
// then an exact path match
path.indexOf(key) > -1 ||
// next if there is a parent, check for exact parent match
(parent !== undefined && parent.name !== undefined &&
parent.name.toLowerCase().indexOf(key) > -1) ||
// lastly check to see if the name was an editDistance match
editDistance(name, key, maxEditDistance) <= maxEditDistance)) {
return false;
}
}
return true;
}

function nextTab(direction) {
const next = (searchState.currentTab + direction + 3) % searchState.focusedByTab.length;
searchState.focusedByTab[searchState.currentTab] = document.activeElement;
Expand Down

0 comments on commit fd1d256

Please sign in to comment.