mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-04-25 15:58:11 -05:00
add support for titled comma
This commit is contained in:
parent
bf11e5ade8
commit
2e33398792
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,14 @@
|
||||||
import loki from 'lokijs';
|
import loki from 'lokijs';
|
||||||
import API from '../../SpreadsheetData';
|
import API from '../../SpreadsheetData';
|
||||||
|
|
||||||
|
function cleanInputRegex(input) {
|
||||||
|
input = input
|
||||||
|
.replace(/\\/g, '')
|
||||||
|
.replace(/\(|\)/g, (match) => {return ("\\"+match)})
|
||||||
|
.replace(/\‘|\’/g, "'");
|
||||||
|
return new RegExp(input.trim(), 'i');
|
||||||
|
}
|
||||||
|
|
||||||
export default function search_api(input) {
|
export default function search_api(input) {
|
||||||
|
|
||||||
// Sort data descending alphabetically
|
// Sort data descending alphabetically
|
||||||
|
|
@ -34,27 +42,27 @@ export default function search_api(input) {
|
||||||
|
|
||||||
// Search by name
|
// Search by name
|
||||||
if (input.name.length > 0) {
|
if (input.name.length > 0) {
|
||||||
// clean name
|
let inputname = cleanInputRegex(input.name);
|
||||||
let inputname = input.name.replace(/\\/g, '').replace(/\(|\)/g, (match) => {return ("\\"+match)});
|
|
||||||
attackResults = attackResults.find({'$or': [
|
attackResults = attackResults.find({'$or': [
|
||||||
{'gsx$name': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$name': {'$regex': inputname}},
|
||||||
{'gsx$tags': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$tags': {'$regex': inputname}},
|
||||||
]});
|
]});
|
||||||
battlegearResults = battlegearResults.find({'$or': [
|
battlegearResults = battlegearResults.find({'$or': [
|
||||||
{'gsx$name': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$name': {'$regex': inputname}},
|
||||||
{'gsx$tags': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$tags': {'$regex': inputname}},
|
||||||
]});
|
]});
|
||||||
creatureResults = creatureResults.find({'$or': [
|
creatureResults = creatureResults.find({'$or': [
|
||||||
{'gsx$name': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$name': {'$regex': inputname}},
|
||||||
{'gsx$tags': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$tags': {'$regex': inputname}},
|
||||||
]});
|
]});
|
||||||
locationResults = locationResults.find({'$or': [
|
locationResults = locationResults.find({'$or': [
|
||||||
{'gsx$name': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$name': {'$regex': inputname}},
|
||||||
{'gsx$tags': {'$regex': new RegExp(inputname, 'i')}}
|
{'gsx$tags': {'$regex': inputname}}
|
||||||
]});
|
]});
|
||||||
mugicResults = mugicResults.find({'$or': [
|
mugicResults = mugicResults.find({'$or': [
|
||||||
{'gsx$name': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$name': {'$regex': inputname}},
|
||||||
{'gsx$tags': {'$regex': new RegExp(inputname, 'i')}},
|
{'gsx$tags': {'$regex': inputname}},
|
||||||
]});
|
]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,12 +71,11 @@ export default function search_api(input) {
|
||||||
if (input.text.length > 0) {
|
if (input.text.length > 0) {
|
||||||
// split text by comma
|
// split text by comma
|
||||||
let textList = input.text.split(",").filter(Boolean).map((item) => {
|
let textList = input.text.split(",").filter(Boolean).map((item) => {
|
||||||
return ({'$regex': new RegExp(item.trim(), 'i')});
|
return ({'$regex': cleanInputRegex(item)});
|
||||||
});
|
});
|
||||||
// clean text
|
// clean text
|
||||||
let inputtext = new RegExp(input.text.replace(/\\/g, '').replace(/\(|\)/g, (match) => {return ("\\"+match)}), "i");
|
let inputtext = cleanInputRegex(input.text);
|
||||||
|
|
||||||
console.log(inputtext);
|
|
||||||
let parm = (() => {
|
let parm = (() => {
|
||||||
let list = [
|
let list = [
|
||||||
{'gsx$tags': {"$or": textList}},
|
{'gsx$tags': {"$or": textList}},
|
||||||
|
|
@ -78,7 +85,6 @@ export default function search_api(input) {
|
||||||
list.push({'gsx$flavortext': {"$or": textList}});
|
list.push({'gsx$flavortext': {"$or": textList}});
|
||||||
list.push({'gsx$artist': {"$or": textList}});
|
list.push({'gsx$artist': {"$or": textList}});
|
||||||
}
|
}
|
||||||
console.log(list);
|
|
||||||
return list;
|
return list;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
@ -94,7 +100,7 @@ export default function search_api(input) {
|
||||||
// Subtypes / Initiative
|
// Subtypes / Initiative
|
||||||
if (input.subtypes.length > 0) {
|
if (input.subtypes.length > 0) {
|
||||||
let subtypesList = input.subtypes.split(",").filter(Boolean).map((item) => {
|
let subtypesList = input.subtypes.split(",").filter(Boolean).map((item) => {
|
||||||
return ({'$regex': new RegExp(item.trim(), 'i')});
|
return ({'$regex': cleanInputRegex(item)});
|
||||||
});
|
});
|
||||||
|
|
||||||
creatureResults = creatureResults.find({'gsx$types': {'$or': subtypesList}});
|
creatureResults = creatureResults.find({'gsx$types': {'$or': subtypesList}});
|
||||||
|
|
@ -321,27 +327,27 @@ export default function search_api(input) {
|
||||||
|
|
||||||
if (types || input.types.attack) {
|
if (types || input.types.attack) {
|
||||||
let temp = attackResults.data();
|
let temp = attackResults.data();
|
||||||
temp.forEach(function(v){ delete v.$loki });
|
temp.forEach((v) => { delete v.$loki });
|
||||||
filter.insert(temp);
|
filter.insert(temp);
|
||||||
}
|
}
|
||||||
if (types || input.types.battlegear) {
|
if (types || input.types.battlegear) {
|
||||||
let temp = battlegearResults.data();
|
let temp = battlegearResults.data();
|
||||||
temp.forEach(function(v){ delete v.$loki });
|
temp.forEach((v) => { delete v.$loki });
|
||||||
filter.insert(temp);
|
filter.insert(temp);
|
||||||
}
|
}
|
||||||
if (types || input.types.creature) {
|
if (types || input.types.creature) {
|
||||||
let temp = creatureResults.data()
|
let temp = creatureResults.data()
|
||||||
temp.forEach(function(v){ delete v.$loki });
|
temp.forEach((v) => { delete v.$loki });
|
||||||
filter.insert(temp);
|
filter.insert(temp);
|
||||||
}
|
}
|
||||||
if (types || input.types.location) {
|
if (types || input.types.location) {
|
||||||
let temp = locationResults.data()
|
let temp = locationResults.data()
|
||||||
temp.forEach(function(v){ delete v.$loki });
|
temp.forEach((v) => { delete v.$loki });
|
||||||
filter.insert(temp);
|
filter.insert(temp);
|
||||||
}
|
}
|
||||||
if (types || input.types.mugic) {
|
if (types || input.types.mugic) {
|
||||||
let temp = mugicResults.data()
|
let temp = mugicResults.data()
|
||||||
temp.forEach(function(v){ delete v.$loki });
|
temp.forEach((v) => { delete v.$loki });
|
||||||
filter.insert(temp);
|
filter.insert(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user