Преглед на файлове

Example search engine: Match all words, in any order (#26971)

* match all words, in any order

* docs: match all words, in any order
sunag преди 1 година
родител
ревизия
f14779fcfc
променени са 2 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 3 1
      docs/index.html
  2. 3 1
      examples/index.html

+ 3 - 1
docs/index.html

@@ -359,7 +359,9 @@
 
 
 		function escapeRegExp( string ) {
 		function escapeRegExp( string ) {
 
 
-			return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+			string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+
+			return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')'; // match all words, in any order
 
 
 		}
 		}
 
 

+ 3 - 1
examples/index.html

@@ -253,7 +253,9 @@
 
 
 		function escapeRegExp( string ) {
 		function escapeRegExp( string ) {
 
 
-			return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+			string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
+
+			return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')'; // match all words, in any order
 
 
 		}
 		}