在指针列上应用搜索时遇到问题 - Parse Opensource - Cloud Function

Facing an issue when applying a search on pointer column - Parse Opensource - Cloud Function

我有两个 tables:-

国家 客户 [有许多列 - 例如姓名、地址、城市、邮政编码、电子邮件等] 客户 table 有一个列国家 [国家指针]。

现在我想要的是:我有一个搜索表单,如果有人在搜索框中输入 "aus" 并单击 "Search" 按钮 我想显示所有匹配的记录,我想应用搜索在 "Name, email, address, city, and the Country name [pointer]"

因此,如果某人的名字为 Austin 或国家/地区,"Australia" 将是搜索的输出,目前,我在姓名、电子邮件上使用 "contains",并且工作正常。

我尝试在国家/地区应用搜索但没有成功,请有人帮忙应用这个。

这是我当前可用的代码[没有国家/地区搜索],我正在使用云功能。

`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é 将匹配 andreAnDrÉ)。

这是我曾经这样做的助手:

  /**
   * 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 只是对 Diacritics package.

的调用

在您的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');

瞧瞧 :)