11/**
22 * External dependencies
33 */
4- import { deburr , find , words } from 'lodash' ;
4+ import { noCase } from 'change-case' ;
5+ import removeAccents from 'remove-accents' ;
6+ import { find } from 'lodash' ;
57
68// Default search helpers.
79const defaultGetName = ( item ) => item . name || '' ;
@@ -21,7 +23,7 @@ const defaultGetCollection = () => null;
2123function normalizeSearchInput ( input = '' ) {
2224 // Disregard diacritics.
2325 // Input: "média"
24- input = deburr ( input ) ;
26+ input = removeAccents ( input ) ;
2527
2628 // Accommodate leading slash, matching autocomplete expectations.
2729 // Input: "/media"
@@ -34,6 +36,17 @@ function normalizeSearchInput( input = '' ) {
3436 return input ;
3537}
3638
39+ /**
40+ * Extracts words from an input string.
41+ *
42+ * @param {string } input The input string.
43+ *
44+ * @return {Array } Words, extracted from the input string.
45+ */
46+ function extractWords ( input = '' ) {
47+ return noCase ( input ) . split ( ' ' ) . filter ( Boolean ) ;
48+ }
49+
3750/**
3851 * Converts the search term into a list of normalized terms.
3952 *
@@ -42,8 +55,7 @@ function normalizeSearchInput( input = '' ) {
4255 * @return {string[] } The normalized list of search terms.
4356 */
4457export const getNormalizedSearchTerms = ( input = '' ) => {
45- // Extract words.
46- return words ( normalizeSearchInput ( input ) ) ;
58+ return extractWords ( normalizeSearchInput ( input ) ) ;
4759} ;
4860
4961const removeMatchingTerms = ( unmatchedTerms , unprocessedTerms ) => {
@@ -150,7 +162,7 @@ export function getItemSearchRank( item, searchTerm, config = {} ) {
150162 category ,
151163 collection ,
152164 ] . join ( ' ' ) ;
153- const normalizedSearchTerms = words ( normalizedSearchInput ) ;
165+ const normalizedSearchTerms = extractWords ( normalizedSearchInput ) ;
154166 const unmatchedTerms = removeMatchingTerms (
155167 normalizedSearchTerms ,
156168 terms
0 commit comments