繁体   English   中英

在指针列上应用搜索时遇到问题-解析开源-Cloud Function

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

我有两个桌子:

国家客户[具有许多列名称,地址,城市,邮政编码,电子邮件等]客户表具有列国家[国家指针]。

现在我想要的是:我有一个搜索表单,如果有人在搜索框中输入“ aus”,然后单击“搜索”按钮,我想显示所有匹配的记录,我想对“名称,电子邮件,地址,城市”应用搜索,以及国家/地区名称[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软件包的调用。

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à:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM