簡體   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