我有两个表: -
国家客户[有多个列名称,地址,城市,邮政编码,电子邮件等]客户表有一个专栏国家[国家指针]。
现在我想要的是:我有一个搜索表格,如果有人将" AUS"放在搜索框中,然后单击我想显示所有匹配记录的"搜索"按钮,我想在"名称,电子邮件,电子邮件,电子邮件,电子邮件"上应用搜索地址,城市和国家名称[指针]"
因此,如果某人的名称为Austin或Country名称"澳大利亚"将是搜索的输出,目前,我正在使用"包含"的名称,电子邮件,并且运行正常。
我试图在国家/地区应用搜索,但没有成功,请有人可以帮助使用此搜索。
这是我当前正在工作的代码[无国家搜索],我正在使用云功能。
`var customerName = new Parse.Query("customer");
var customerEmail = new Parse.Query("customer");
var customerAddress = new Parse.Query("customer");
customerName.contains('name','aus');
customerEmail.contains('email','aus');
customerAddress.contains('address','aus');
var serviceQuery = new Parse.Query.or(
customerName,
customerEmail,
customerAddress
// country
);
......................谢谢
尝试这样的东西:
var customerName = new Parse.Query('customer');
var customerEmail = new Parse.Query('customer');
var customerAddress = new Parse.Query('customer');
customerName.contains('name','aus');
customerEmail.contains('email','aus');
customerAddress.contains('address','aus');
var countryQuery = new Parse.Query('country');
countryQuery.contains('name','aus');
var customerCountry = new Parse.Query('customer');
customerCountry.matchesQuery('country', countryQuery);
var serviceQuery = new Parse.Query.or(
customerName,
customerEmail,
customerAddress,
customerCountry
);
您可以使用全文搜索而不是搜索每个客户的字段:https://docs.parseplatform.org/js/guide/#full-text-search
解决方案是在对象的云beforeSave
上计算fullTextSearch
字段。最好的方法是将此字符串存储在小写的情况下,而无需变音符号。如果您在搜索时执行相同的操作,它将提供更好的结果(André
将匹配andre
或AnDrÉ
(。
这是我曾经这样做的助手:
/**
* Generates fulltextsearch for any Parse.Object. It's the concatenation of the value
* of all fields in propertiesToAdd, separated by a whitespace and lowercased.
* Often used in beforeSave :)
* @param propertiesToAdd the list of the object properties names that we want to handle in fulltextsearch
* @param newObject the new version of the object
*/
static generateFulltextSearch(propertiesToAdd, newObject): string {
let result = '';
propertiesToAdd.forEach(property => {
let value = newObject.get(property);
if (value) {
result += DiacriticRemove(value) + ' ';
}
});
return result.trim().toLocaleLowerCase();
}
DiacriticRemove
只是对变音术包的呼吁。
在您的beforeSave
(在云代码中(中,您只需要致电:
myCustomer("myFullTextField", generateFulltextSearch(["name", "email", "address", "country", "anyotherField"], myCustomer))
然后,当您搜索时:
var customer = new Parse.Query("customer");
// Don't forget to lowercase and remove diacritics from your searched string.
customer.contains('myFullTextField','aus');
和voilà:(