Narrow search by specific attributes #6266
Answered
by
joshpalmeroc
joshpalmeroc
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
joshpalmeroc
Jul 3, 2024
Replies: 2 comments 1 reply
-
const { refine } = useSearchBox();
const { refine: configure } = useConfigure({});
function handleSearch(data) {
const { JobPostingTitle, Location } = data;
if (!JobPostingTitle && !Location) return;
const restrictions = [];
let query = '';
if (JobPostingTitle) {
restrictions.push('JobPostingTitle');
query += JobPostingTitle;
}
if (Location) {
restrictions.push('Location');
query += ` ${Location}`;
}
configure({ restrictSearchableAttributes: restrictions });
refine(query.trim());
} I was actually able to solve my problem by using "restrictSearchableAttributes" |
Beta Was this translation helpful? Give feedback.
1 reply
-
I figured out my problem again. useSearchbox returns the existing query const value = data[name]; // the form input value ("tech")
let newQuery = query.replace(value, '').trim(); // replacing the existing queries text with nothing
refine(newQuery); // refine again with useSearchbox |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
joshpalmeroc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I figured out my problem again.
useSearchbox returns the existing query
My form field has the value in state for that field