简体   繁体   English

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

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

I have an two tables:- 我有两个桌子:

Countries Customers [have a number of column- ike name, address, city, zipcode, email, etc] Customer table have an column country [Pointer of Countries]. 国家客户[具有许多列名称,地址,城市,邮政编码,电子邮件等]客户表具有列国家[国家指针]。

Now what I want: I have a search form and if some put "aus" in a search box and click on "Search" button I want to display all matching records, I want to apply search on "Name, email, address, city, and the Country name [pointer]" 现在我想要的是:我有一个搜索表单,如果有人在搜索框中输入“ aus”,然后单击“搜索”按钮,我想显示所有匹配的记录,我想对“名称,电子邮件,地址,城市”应用搜索,以及国家/地区名称[pointer]“

So if someone has name Austin or Country name "Australia" will be the output of search, currently, I'm using "contains" on the name, email and it is working fine. 因此,如果某人的名字为Austin或国家/地区名称“ Australia”将作为搜索结果,那么目前,我在名称,电子邮件上使用“ contains”,并且工作正常。

I tried to apply search on country but not successes, could someone please help to apply this. 我尝试对国家/地区进行搜索,但未成功搜索,有人可以帮助应用此搜索。

Here is my current code that is working [Without Country search], I am using cloud functions. 这是我当前正在使用的代码[无国家/地区搜索],我正在使用云功能。

`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
  );

.............` Thanks .............`谢谢

Try something like this: 尝试这样的事情:

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
);

Instead of searching for each of customers' fields, you can use full text search: https://docs.parseplatform.org/js/guide/#full-text-search 您可以使用全文本搜索来代替搜索每个客户的字段: https : //docs.parseplatform.org/js/guide/#full-text-search

A solution would be to compute a fullTextSearch field on cloud beforeSave of your objects. 一种解决方案是在对象beforeSave之前在云上计算fullTextSearch字段。 The best way is to store this string in lowercase and without diacritics. 最好的方法是将此字符串存储为小写且不带变音符号。 It will give better results if you do the same when searching (so that André will match andre or AnDrÉ ). 如果您在搜索时执行相同的操作,则会得到更好的结果(以便André匹配andreAnDrÉ )。

Here is the helper I used to do so: 这是我曾经这样做的助手:

  /**
   * 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 is simply a call to Diacritics package . DiacriticRemove只是对Diacritics软件包的调用。

In your beforeSave (in cloud code), you just have to call: beforeSave (在云代码中)中,您只需调用:

  myCustomer("myFullTextField", generateFulltextSearch(["name", "email", "address", "country", "anyotherField"], myCustomer))

Then, when you're searching: 然后,当您进行搜索时:

var customer = new Parse.Query("customer");
// Don't forget to lowercase and remove diacritics from your searched string.
customer.contains('myFullTextField','aus');

And voilà :) 还有voilà:)

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

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