Skip to content

Commit

Permalink
changed data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
robfelty committed Mar 15, 2024
1 parent eadbe30 commit 3046218
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions projects/packages/search/src/instant-search/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,21 @@ function generateApiQueryString( {
// starts with "regex:". For regex, we anchor the pattern to the start and
// end of the query. If the user really wants to match anywhere within the
// query, they can use for example ".*hello.*"
for ( const [ queryPattern, postIds ] of Object.entries( customResults ) ) {
if ( queryPattern.startsWith( 'regex:' ) ) {
const pattern = '^' + queryPattern.replace( 'regex:', '' ) + '$';
//
customResults.every( rule => {
let pattern = rule.pattern;
const postIds = rule.ids;
if ( pattern.startsWith( 'regex:' ) ) {
pattern = '^' + pattern.replace( 'regex:', '' ) + '$';
if ( query.match( pattern ) ) {
params.custom_results = postIds;
break;
return false;
}
} else if ( query === queryPattern ) {
} else if ( query === pattern ) {
params.custom_results = postIds;
break;
return false;
}
}
} );

if ( staticFilters && Object.keys( staticFilters ).length > 0 ) {
params = {
Expand Down

0 comments on commit 3046218

Please sign in to comment.