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

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

ไวยากรณ์

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

คุณใช้ 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"
    | "WAITING"
    | "ESTABLISHED"
    | "REJECTED"
    ;
serviceType
    : "ACCOUNT_AGGREGATION"
    | "ACCOUNT_MANAGEMENT"
    ;

comparator
    : " = " | " != "
    ;