Skip to content

Commit 32d97aa

Browse files
committed
search for multiple terms
1 parent 98b851b commit 32d97aa

3 files changed

Lines changed: 33 additions & 26 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"react-search-input.js",
55
"react-search-input.css"
66
],
7-
"version": "0.2.4",
7+
"version": "0.2.5",
88
"homepage": "https://github.com/enki-com/react-search-input",
99
"description": "Simple react.js component for a search input, providing a filter function.",
1010
"keywords": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-search-input",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "Simple react.js component for a search input, providing a filter function.",
55
"main": "react-search-input.js",
66
"dependencies": {

react-search-input.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,42 @@
7878
term = term.toLowerCase();
7979
}
8080

81-
if (keys) {
82-
if( typeof keys === 'string' ) {
83-
keys = [keys];
84-
}
85-
for (var i = 0; i < keys.length; i++) {
86-
var values = _getValuesForKey(keys[i], item);
81+
var terms = term.split(' ');
82+
var foundCount = 0;
83+
terms.forEach(function(term) {
84+
if (keys) {
85+
if (typeof keys === 'string') {
86+
keys = [keys];
87+
}
8788
var found = false;
88-
values.forEach(function(value) {
89-
try {
90-
if (value && value.search(term) !== -1) {
91-
found = true;
92-
}
93-
} catch(e) {
89+
for (var i = 0; i < keys.length; i++) {
90+
var values = _getValuesForKey(keys[i], item);
91+
values.forEach(function(value) {
92+
try {
93+
if (value && value.search(term) !== -1) {
94+
found = true;
95+
}
96+
} catch(e) {}
97+
});
98+
if (found) {
99+
break;
94100
}
95-
});
101+
}
102+
96103
if (found) {
97-
return true;
104+
foundCount++;
98105
}
106+
} else {
107+
try {
108+
var stringValue = item.toLowerCase();
109+
if (stringValue.search(term) !== -1) {
110+
foundCount++;
111+
}
112+
} catch(e) {}
99113
}
100-
return false;
101-
} else {
102-
try {
103-
var stringValue = item.toLowerCase();
104-
return (stringValue.search(term) !== -1);
105-
} catch(e) {
106-
return false;
107-
}
108-
}
109-
}.bind(this);
114+
});
115+
return foundCount === terms.length;;
116+
};
110117
}
111118
}
112119
});

0 commit comments

Comments
 (0)