ไวยากรณ์ตัวกรอง

หน้านี้อธิบายไวยากรณ์ที่คุณต้องใช้เพื่อกรอง บัญชี

ไวยากรณ์

ค่าทั้งหมดที่ไม่ใช่จำนวนเต็มต้องอยู่ในเครื่องหมายคำพูดคู่ (") หากต้องการดูว่าฟิลด์ใดรับค่าใดบ้าง โปรดดูเอกสารประกอบอ้างอิงสำหรับฟิลด์นั้น

คุณใช้ AND เพื่อกรองหลายฟิลด์ในการค้นหาเดียวกันได้ นอกจากนี้ คุณยัง ใช้ AND เพื่อรวมตัวกรอง relationship(...) และ service(...) หลายรายการได้ด้วย ต่อไปนี้คือตัวอย่างที่รวมตัวกรอง relationship(...) และ service(...) หลายรายการ

(relationship(service(type = "ACCOUNT_MANAGEMENT") AND service(handshakeState = "PENDING"))) OR (accountName = "store" AND relationship(...))

ตัวอย่างนี้จะแสดงบัญชีต่อไปนี้

  • บัญชีทั้งหมดที่มีความสัมพันธ์ในการจัดการบัญชีกับบัญชีอื่น และ ความสัมพันธ์เพิ่มเติมที่รอการยอมรับ

  • บัญชีทั้งหมดที่มีชื่อที่แสดง "store" ซึ่งมีความสัมพันธ์กับบัญชีอื่นๆ

คุณใช้ AND เพื่อกรองค่าหลายค่าในช่องเดียวกันไม่ได้ เช่น คุณใช้ accountName = "*A*" AND accountName = "*B*" ไม่ได้

คุณใช้ OR เพื่อกรอง 2 ฟิลด์ในการค้นหาเดียวกันได้ ใส่วงเล็บคร่อมเกณฑ์ตัวกรอง แต่ละด้านของโอเปอเรเตอร์ OR เช่น (accountName = "storeA") OR (accountName = "storeB")

คุณใช้ OR เพื่อรวม 2 ฟิลด์ได้เท่านั้น เช่น คุณจะใช้ (accountName = "storeA") OR (accountName = "storeB") OR (accountName = "storeC") ไม่ได้

ไม่อนุญาตให้ใช้วงเล็บนอกเหนือจากโอเปอเรเตอร์ AND และ OR รวมถึงในการเรียกใช้ฟังก์ชัน เช่น relationship(...) และ service(...)

สำหรับฟิลด์สตริง เช่น accountName และ accountIdAlias คุณสามารถกรองค่าที่มีคำหรือลำดับอักขระที่ต้องการได้โดยการใส่ลำดับในเครื่องหมายดอกจัน (*) เช่น accountName = "*foo*" จะแสดงผลบัญชีทั้งหมดที่มี accountName ซึ่งมี foo เช่น "storeFoo"

คุณสามารถกรองค่าที่ไม่มีลำดับที่ต้องการได้โดยใช้ != และ * เช่น accountName != "*foo*" จะแสดงบัญชีทั้งหมดที่มี accountName ซึ่งไม่มี foo

ระบบจะไม่สนใจการเว้นวรรคเกินความจำเป็น เช่น foo AND bar เหมือนกับ foo AND bar

ตัวอย่างการกรองบัญชีโดยใช้วิธี account.list มีดังนี้

"* บัญชีย่อย MCA ทั้งหมดที่มีคำว่า "Store"

accountName = "*store*" AND relationship(service(type = "ACCOUNT_AGGREGATION"))
  • บัญชีทั้งหมดที่ผู้ให้บริการ 123456 จัดการ
relationship(service(type = "ACCOUNT_MANAGEMENT") AND providerId = 123456)
  • บัญชีทั้งหมดที่ส่งคำเชิญไปยังผู้ให้บริการ 123456 หรือต้อง ยอมรับคำเชิญจากผู้ให้บริการรายนี้
relationship(service(handshakeState = "PENDING" AND type ="ACCOUNT_MANAGEMENT")
AND providerId = 123456)

หากต้องการกรองบัญชีที่ผู้ใช้ซึ่งส่งคำขอเข้าถึงได้ ให้ใช้วิธีgoogle.shopping.merchant.accounts.v1.ListAccountsRequest ดังที่แสดงในตัวอย่างต่อไปนี้

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient.ListAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.ListAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to filter the accounts the user making the request has access to. */
public class FilterAccountsSample {

  public static void filterAccounts(Config config) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    AccountsServiceSettings accountsServiceSettings =
        AccountsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (AccountsServiceClient accountsServiceClient =
        AccountsServiceClient.create(accountsServiceSettings)) {

      // Filter for accounts with display names containing "store" and a provider with the ID "123":
      String filter = "accountName = \"*store*\" AND relationship(providerId = 123)";

      // Filter for all subaccounts of account "123":
      // String filter2 = "relationship(providerId = 123 AND service(type =
      // \"ACCOUNT_AGGREGATION\"))";

      // String filter3 = "relationship(service(handshakeState = \"APPROVED\" AND type =
      // \"ACCOUNT_MANAGEMENT\") AND providerId = 123)";

      ListAccountsRequest request = ListAccountsRequest.newBuilder().setFilter(filter).build();

      System.out.println("Sending list accounts request with filter:");
      ListAccountsPagedResponse response = accountsServiceClient.listAccounts(request);

      int count = 0;

      // Iterates over all rows in all pages and prints the sub-account
      // in each row.
      // `response.iterateAll()` automatically uses the `nextPageToken` and recalls the
      // request to fetch all pages of data.
      for (Account account : response.iterateAll()) {
        System.out.println(account);
        count++;
      }
      System.out.print("The following count of elements were returned: ");
      System.out.println(count);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    filterAccounts(config);
  }
}

ข้อมูลจำเพาะ

ฟิลเตอร์เป็นไปตามข้อกำหนดของฟิลเตอร์ AIP ซึ่งเป็นส่วนย่อย และไวยากรณ์ EBNF อย่างเป็นทางการ

filter
    : accountFilterDisj
    | accountFilterConj

accountFilterDisj
    : "(" accountFilterConj " OR " accountFilterConj ")"
    ;
accountFilterConj
    : accountFilter {" AND " accountFilter}
    ;

accountFilter
    : accountNameFilter | capabilityFilter | relationshipFn
    ;

accountNameFilter
    : "accountName" comparator value
    ;

capabilityFilter
    : "capabilities:" capabilityValue
    | "-capabilities:" capabilityValue
    | "NOT capabilities:" capabilityValue
    ;
capabilityValue
    : "CAN_UPLOAD_PRODUCTS"
    ;

relationshipFn
    : "relationship(" relationshipConj ")"
    ;
relationshipConj
    : relationshipFilter {" AND " relationshipFilter}
    ;
relationshipFilter
    : "providerId = " numValue
    | "accountIdAlias" comparator value
    | serviceFn
    ;

serviceFn
    : "service(" serviceConj ")"
    ;
serviceConj
    : serviceFilter {" AND " serviceFilter}
    ;
serviceFilter
    : "externalAccountId" comparator value
    | "handshakeState = " handshakeState
    | "type = " serviceType
    ;

handshakeState
    : "PENDING"
    | "APPROVED"
    | "REJECTED"
    ;
serviceType
    : "ACCOUNT_AGGREGATION"
    | "ACCOUNT_MANAGEMENT"
    ;

comparator
    : " = " | " != "
    ;