Skip to content

Commit

Permalink
Merge pull request #3432 from vespa-engine/freva/encode
Browse files Browse the repository at this point in the history
Encode spaces as %20
  • Loading branch information
freva authored Oct 21, 2024
2 parents 1e07543 + 7674dfe commit 79f7045
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ const debounce = (func, timeout = 200) => {
};
};

const encode = (params) => {
return new URLSearchParams(params)
.toString()
.replaceAll('+', '%20'); // CloudFront requires that spaces are encoded as %20
};


const handleQuery = (query) => {
if (query.length > 0) {
const result = document.getElementById("result");

document.getElementById("hits").innerHTML = "";
result.innerHTML = `Searching for '${escapeHtml(query)}' ...`;
const searchParams = new URLSearchParams({term: query});
fetch("https://api.search.vespa.ai/search/?" + searchParams.toString())
fetch("https://api.search.vespa.ai/search/?" + encode({term: query}))
.then((res) => res.json())
.then((res) => { const children = (res.root.children)? res.root.children : [];
handleSuggestionResults(children.filter(child => child.fields.sddocname === "term"));
Expand All @@ -55,15 +60,15 @@ const handleLocationQuery = () => {
document.getElementById("searchinput").value = query;
result.innerHTML = `Searching for '${escapeHtml(query)}' ...`;

const searchParams = new URLSearchParams({
const searchParams = {
yql: 'select * from doc where {grammar: "weakAnd"}userInput(@userinput)',
hits: 25,
ranking: 'documentation',
locale: 'en-US',
userinput: query,
});
};

fetch("https://api.search.vespa.ai/search/?" + searchParams.toString())
fetch("https://api.search.vespa.ai/search/?" + encode(searchParams))
.then((res) => res.json())
.then((res) => handleResults(res.root.children, escapeHtml(query)))
}
Expand Down

0 comments on commit 79f7045

Please sign in to comment.