search by name now excludes by ~

This commit is contained in:
Daniel 2020-06-24 18:22:28 -04:00
parent e14de59e88
commit 25a7eadf41
4 changed files with 49 additions and 27 deletions

File diff suppressed because one or more lines are too long

6
package-lock.json generated
View File

@ -3559,9 +3559,9 @@
"dev": true
},
"@types/react": {
"version": "16.9.38",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.38.tgz",
"integrity": "sha512-pHAeZbjjNRa/hxyNuLrvbxhhnKyKNiLC6I5fRF2Zr/t/S6zS41MiyzH4+c+1I9vVfvuRt1VS2Lodjr4ZWnxrdA==",
"version": "16.9.41",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.41.tgz",
"integrity": "sha512-6cFei7F7L4wwuM+IND/Q2cV1koQUvJ8iSV+Gwn0c3kvABZ691g7sp3hfEQHOUBJtccl1gPi+EyNjMIl9nGA0ug==",
"requires": {
"@types/prop-types": "*",
"csstype": "^2.2.0"

View File

@ -58,7 +58,7 @@
"@babel/runtime": "^7.10.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/react": "^16.9.38",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.5",
"babel-eslint": "^10.1.0",

View File

@ -44,28 +44,50 @@ export default function search_api(input) {
// Search by name
if (input.name.length > 0) {
let inputname = cleanInputRegex(input.name);
const negates = [];
let inputname = input.name.replace(/(?:~)([\w,()]+)/g, (_, p1) => { negates.push(p1); return ""; });
if (inputname.length > 0) {
inputname = cleanInputRegex(inputname);
attackResults = attackResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
battlegearResults = battlegearResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
creatureResults = creatureResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
locationResults = locationResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }}
]});
mugicResults = mugicResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
}
if (negates.length > 0) {
const ignoreText = (obj) => {
let truth = false;
negates.forEach((word) => {
truth |= (obj.gsx$name.toLowerCase().indexOf(word.toLowerCase().replace('_', ' ')) > -1);
});
return !truth;
}
attackResults = attackResults.where(ignoreText);
battlegearResults = battlegearResults.where(ignoreText);
creatureResults = creatureResults.where(ignoreText);
locationResults = locationResults.where(ignoreText);
mugicResults = mugicResults.where(ignoreText);
}
attackResults = attackResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
battlegearResults = battlegearResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
creatureResults = creatureResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
locationResults = locationResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }}
]});
mugicResults = mugicResults.find({ '$or': [
{ 'gsx$name': { '$regex': inputname }},
{ 'gsx$tags': { '$regex': inputname }},
]});
}
@ -111,7 +133,7 @@ export default function search_api(input) {
attackResults = attackResults.where(ignoreText);
battlegearResults = battlegearResults.where(ignoreText);
creatureResults = creatureResults.where(ignoreText, true);
creatureResults = creatureResults.where(obj => ignoreText(obj, true));
locationResults = locationResults.where(ignoreText);
mugicResults = mugicResults.where(ignoreText);
}