ทําให้เครื่องมือเชื่อมต่อใช้งานได้

หน้านี้ของบทแนะนำ Cloud Search จะแสดงวิธีตั้งค่าแหล่งข้อมูลและเครื่องมือเชื่อมต่อเนื้อหาสำหรับการจัดทำดัชนีข้อมูล หากต้องการเริ่มต้นจากจุดเริ่มต้นของบทแนะนำนี้ โปรดดู บทแนะนำเริ่มต้นใช้งาน Cloud Search

สร้างเครื่องมือเชื่อมต่อ

เปลี่ยนไดเรกทอรีที่ใช้งานอยู่เป็นไดเรกทอรี cloud-search-samples/end-to-end/connector แล้วเรียกใช้คำสั่งนี้

mvn package -DskipTests

คำสั่งจะดาวน์โหลดการขึ้นต่อกันที่จำเป็นสำหรับการสร้างเครื่องมือเชื่อมต่อเนื้อหาและคอมไพล์โค้ด

สร้างข้อมูลเข้าสู่ระบบของบัญชีบริการ

เครื่องมือเชื่อมต่อต้องใช้ข้อมูลเข้าสู่ระบบของบัญชีบริการเพื่อเรียกใช้ Cloud Search API วิธีสร้างข้อมูลเข้าสู่ระบบ

  1. กลับไปที่ คอนโซล Google Cloud
  2. คลิกข้อมูลเข้าสู่ระบบ ในการนำทางด้านซ้าย หน้า "ข้อมูลเข้าสู่ระบบ" จะปรากฏขึ้น
  3. คลิกรายการแบบเลื่อนลง + สร้างข้อมูลเข้าสู่ระบบ แล้วเลือก บัญชีบริการ หน้า "สร้างบัญชีบริการ" จะปรากฏขึ้น
  4. ป้อน "tutorial" ในช่องชื่อบัญชีบริการ
  5. จดค่ารหัสบัญชีบริการ (อยู่ทางขวาของชื่อบัญชีบริการ) เราจะใช้ค่านี้ในภายหลัง
  6. คลิกสร้าง กล่องโต้ตอบ "สิทธิ์ของบัญชีบริการ (ไม่บังคับ)" จะปรากฏขึ้น
  7. คลิกดำเนินการต่อ กล่องโต้ตอบ "ให้สิทธิ์เข้าถึงบัญชีบริการนี้แก่ผู้ใช้ (ไม่บังคับ)" จะปรากฏขึ้น
  8. คลิกเสร็จสิ้น หน้าจอ "ข้อมูลเข้าสู่ระบบ" จะปรากฏขึ้น
  9. คลิกอีเมลของบัญชีบริการในส่วนบัญชีบริการ หน้า "รายละเอียดบัญชีบริการ" จะปรากฏขึ้น
  10. คลิกรายการแบบเลื่อนลง เพิ่มคีย์ ในส่วนคีย์ แล้วเลือกสร้างคีย์ใหม่ กล่องโต้ตอบ "สร้างคีย์ส่วนตัว" จะปรากฏขึ้น
  11. คลิกสร้าง
  12. (ไม่บังคับ) หากกล่องโต้ตอบ "คุณต้องการอนุญาตการดาวน์โหลดใน console.cloud.google.com ไหม" ปรากฏขึ้น ให้คลิกอนุญาต
  13. ระบบจะบันทึกไฟล์คีย์ส่วนตัวลงในคอมพิวเตอร์ โปรดจดบันทึกตำแหน่งของไฟล์ที่ดาวน์โหลด เราจะใช้ไฟล์นี้เพื่อกำหนดค่าเครื่องมือเชื่อมต่อเนื้อหาเพื่อให้เครื่องมือเชื่อมต่อสามารถตรวจสอบสิทธิ์ตัวเองเมื่อเรียกใช้ Google Cloud Search API

เริ่มต้นการรองรับบุคคลที่สาม

เริ่มต้นการรองรับบุคคลที่สามสำหรับ Google Cloud Search ก่อนที่จะเรียกใช้ Cloud Search API อื่นๆ

วิธีเริ่มต้นการรองรับบุคคลที่สาม

  1. สร้างข้อมูลเข้าสู่ระบบของเว็บแอปพลิเคชันในโปรเจ็กต์แพลตฟอร์ม Cloud Search ดู สร้างข้อมูลเข้าสู่ระบบ คุณต้องใช้รหัสไคลเอ็นต์และรหัสลับไคลเอ็นต์
  2. รับโทเค็นเพื่อการเข้าถึงโดยใช้ OAuth 2.0 Playgroundโดยทำดังนี้
    1. คลิกการกำหนดค่า OAuth 2.0 (ไอคอนการตั้งค่า) แล้วเลือกใช้ข้อมูลเข้าสู่ระบบ OAuth ของคุณเอง
    2. ป้อนรหัสไคลเอ็นต์และรหัสลับไคลเอ็นต์
    3. ป้อน https://www.googleapis.com/auth/cloud_search.settings ในช่องขอบเขต แล้วคลิกให้สิทธิ์ API
    4. คลิกเปลี่ยนรหัสการให้สิทธิ์ของโทเค็น
  3. เรียกใช้คำสั่ง curl นี้ โดยแทนที่ [YOUR_ACCESS_TOKEN] ด้วยโทเค็นของคุณ

    curl --request POST \
    'https://cloudsearch.googleapis.com/v1:initializeCustomer' \
      --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
      --header 'Accept: application/json' \
      --header 'Content-Type: application/json' \
      --data '{}' \
      --compressed
    

    หากทำสำเร็จ เนื้อหาการตอบกลับจะมี operation หากไม่สำเร็จ โปรดติดต่อทีมสนับสนุนของ Cloud Search

  4. ใช้ operations.get เพื่อยืนยันการเริ่มต้น

    curl 'https://cloudsearch.googleapis.com/v1/operations/<var>operation_name</var>?key=[YOUR_API_KEY]' \
    --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
    --header 'Accept: application/json' \
    --compressed
    

    การเริ่มต้นจะเสร็จสมบูรณ์เมื่อ done เป็น true

สร้างแหล่งข้อมูล

จากนั้นสร้างแหล่งข้อมูลในคอนโซลผู้ดูแลระบบ แหล่งข้อมูลจะระบุเนมสเปซสำหรับการจัดทำดัชนีเนื้อหาโดยใช้เครื่องมือเชื่อมต่อ

  1. เปิดคอนโซลผู้ดูแลระบบของ Google
  2. คลิกไอคอนแอป หน้า "การดูแลระบบแอป" จะปรากฏขึ้น
  3. คลิก Google Workspace หน้า "การดูแลระบบแอป Google Workspace" จะปรากฏขึ้น
  4. เลื่อนลงแล้วคลิก Cloud Search หน้า "การตั้งค่าสำหรับ Google Workspace" จะปรากฏขึ้น
  5. คลิกแหล่งข้อมูลของบุคคลที่สาม หน้า "แหล่งข้อมูล" จะปรากฏขึ้น
  6. คลิก + สีเหลืองวงกลม กล่องโต้ตอบ "เพิ่มแหล่งข้อมูลใหม่" จะปรากฏขึ้น
  7. พิมพ์ "tutorial" ในช่องชื่อที่แสดง
  8. ป้อนอีเมลของบัญชีบริการที่คุณสร้างขึ้นในส่วนก่อนหน้าในช่องอีเมลของบัญชีบริการ หากไม่ทราบ อีเมลของบัญชีบริการ ให้ค้นหาค่าใน หน้า บัญชีบริการ
  9. คลิกเพิ่ม กล่องโต้ตอบ "สร้างแหล่งข้อมูลเรียบร้อยแล้ว" จะปรากฏขึ้น
  10. คลิก ตกลง จดบันทึกรหัสแหล่งข้อมูล สำหรับแหล่งข้อมูลที่สร้างขึ้นใหม่ เราจะใช้รหัสแหล่งข้อมูลเพื่อกำหนดค่าเครื่องมือเชื่อมต่อเนื้อหา

สร้างโทเค็นเพื่อการเข้าถึงส่วนบุคคลสำหรับ GitHub API

เครื่องมือเชื่อมต่อต้องมีสิทธิ์เข้าถึง GitHub API ที่ผ่านการตรวจสอบสิทธิ์เพื่อให้มีโควต้าเพียงพอ เครื่องมือเชื่อมต่อใช้ประโยชน์จากโทเค็นเพื่อการเข้าถึงส่วนบุคคลแทน OAuth เพื่อความสะดวก โทเค็นส่วนบุคคลช่วยให้ตรวจสอบสิทธิ์ในฐานะผู้ใช้ที่มีชุดสิทธิ์ที่จำกัดคล้ายกับ OAuth

  1. เข้าสู่ระบบ GitHub
  2. คลิกรูปโปรไฟล์ที่มุมขวาบน เมนูแบบเลื่อนลงจะปรากฏขึ้น
  3. คลิกการตั้งค่า
  4. คลิกการตั้งค่าสำหรับนักพัฒนาซอฟต์แวร์
  5. คลิกโทเค็นเพื่อการเข้าถึงส่วนบุคคล
  6. คลิกสร้างโทเค็นเพื่อการเข้าถึงส่วนบุคคล
  7. ป้อน "Cloud Search tutorial" ในช่องหมายเหตุ
  8. เลือกขอบเขต public_repo
  9. คลิกสร้างโทเค็น
  10. จดบันทึกโทเค็นที่สร้างขึ้น เครื่องมือเชื่อมต่อจะใช้โทเค็นนี้เพื่อเรียกใช้ GitHub API และให้โควต้า API เพื่อทำการจัดทำดัชนี

กำหนดค่าเครื่องมือเชื่อมต่อ

หลังจากสร้างข้อมูลเข้าสู่ระบบและแหล่งข้อมูลแล้ว ให้อัปเดตการกำหนดค่าเครื่องมือเชื่อมต่อให้มีค่าต่อไปนี้

  1. เปลี่ยนไดเรกทอรีเป็น cloud-search-samples/end-to-end/connector/ จากบรรทัดคำสั่ง
  2. เปิดไฟล์ sample-config.properties ด้วยเครื่องมือแก้ไขข้อความ
  3. ตั้งค่าพารามิเตอร์ api.serviceAccountPrivateKeyFile เป็นเส้นทางไฟล์ของข้อมูลเข้าสู่ระบบของบริการที่คุณดาวน์โหลดไว้ก่อนหน้านี้
  4. ตั้งค่าพารามิเตอร์ api.sourceId เป็นรหัสของแหล่งข้อมูลที่คุณสร้างไว้ก่อนหน้านี้
  5. ตั้งค่าพารามิเตอร์ github.user เป็นชื่อผู้ใช้ GitHub ของคุณ
  6. ตั้งค่าพารามิเตอร์ github.token เป็นโทเค็นเพื่อการเข้าถึงที่คุณสร้างไว้ก่อนหน้านี้
  7. บันทึกไฟล์

อัปเดตสคีมา

เครื่องมือเชื่อมต่อจะจัดทำดัชนีทั้งเนื้อหาที่มีโครงสร้างและไม่มีโครงสร้าง คุณต้องอัปเดตสคีมาสำหรับแหล่งข้อมูลก่อนที่จะจัดทำดัชนีข้อมูล เรียกใช้คำสั่งต่อไปนี้เพื่ออัปเดตสคีมา

mvn exec:java -Dexec.mainClass=com.google.cloudsearch.tutorial.SchemaTool \
    -Dexec.args="-Dconfig=sample-config.properties"

เรียกใช้เครื่องมือเชื่อมต่อ

หากต้องการเรียกใช้เครื่องมือเชื่อมต่อและเริ่มการจัดทำดัชนี ให้เรียกใช้คำสั่งต่อไปนี้

mvn exec:java -Dexec.mainClass=com.google.cloudsearch.tutorial.GithubConnector \
    -Dexec.args="-Dconfig=sample-config.properties"

การกำหนดค่าเริ่มต้นสำหรับเครื่องมือเชื่อมต่อคือการจัดทำดัชนีที่เก็บเดียวในองค์กร googleworkspace การจัดทำดัชนีที่เก็บจะใช้เวลาประมาณ 1 นาที หลังจากจัดทำดัชนีครั้งแรก เครื่องมือเชื่อมต่อจะทำการโพลการเปลี่ยนแปลงที่เก็บอย่างต่อเนื่องซึ่งต้องแสดงในดัชนี Cloud Search

การตรวจสอบโค้ด

ส่วนที่เหลือจะตรวจสอบวิธีสร้างเครื่องมือเชื่อมต่อ

การเริ่มต้นแอปพลิเคชัน

จุดเริ่มต้นของเครื่องมือเชื่อมต่อคือคลาส GithubConnector เมธอด main จะสร้างอินสแตนซ์ IndexingApplication ของ SDK และเริ่มต้น

GithubConnector.java
/**
 * Main entry point for the connector. Creates and starts an indexing
 * application using the {@code ListingConnector} template and the sample's
 * custom {@code Repository} implementation.
 *
 * @param args program command line arguments
 * @throws InterruptedException thrown if an abort is issued during initialization
 */
public static void main(String[] args) throws InterruptedException {
  Repository repository = new GithubRepository();
  IndexingConnector connector = new ListingConnector(repository);
  IndexingApplication application = new IndexingApplication.Builder(connector, args)
      .build();
  application.start();
}

ListingConnector ที่ SDK จัดเตรียมให้จะใช้กลยุทธ์การข้ามผ่าน ที่ใช้ประโยชน์จากคิว Cloud Search เพื่อติดตามสถานะของรายการในดัชนี โดยจะมอบหมายให้ GithubRepository ซึ่งเครื่องมือเชื่อมต่อตัวอย่างเป็นผู้ใช้เพื่อเข้าถึงเนื้อหาจาก GitHub

การข้ามผ่านที่เก็บ GitHub

ระหว่างการข้ามผ่านแบบเต็ม ระบบจะเรียกใช้getIds() เมธอดเพื่อพุชรายการที่อาจต้องจัดทำดัชนีลงในคิว

เครื่องมือเชื่อมต่อสามารถจัดทำดัชนีที่เก็บหรือองค์กรหลายแห่ง ระบบจะข้ามผ่านที่เก็บ GitHub ทีละรายการเพื่อลดผลกระทบจากความล้มเหลว ระบบจะส่งคืนจุดตรวจสอบพร้อมผลลัพธ์ของการข้ามผ่านซึ่งมีรายการที่เก็บที่จะจัดทำดัชนีในการเรียกใช้ getIds() ครั้งต่อๆ ไป หากเกิดข้อผิดพลาด ระบบจะจัดทำดัชนีต่อที่ที่เก็บปัจจุบันแทนที่จะเริ่มจากจุดเริ่มต้น

GithubRepository.java
/**
 * Gets all of the existing item IDs from the data repository. While
 * multiple repositories are supported, only one repository is traversed
 * per call. The remaining repositories are saved in the checkpoint
 * are traversed on subsequent calls. This minimizes the amount of
 * data that needs to be reindex in the event of an error.
 *
 * <p>This method is called by {@link ListingConnector#traverse()} during
 * <em>full traversals</em>. Every document ID and metadata hash value in
 * the <em>repository</em> is pushed to the Cloud Search queue. Each pushed
 * document is later polled and processed in the {@link #getDoc(Item)} method.
 * <p>
 * The metadata hash values are pushed to aid document change detection. The
 * queue sets the document status depending on the hash comparison. If the
 * pushed ID doesn't yet exist in Cloud Search, the document's status is
 * set to <em>new</em>. If the ID exists but has a mismatched hash value,
 * its status is set to <em>modified</em>. If the ID exists and matches
 * the hash value, its status is unchanged.
 *
 * <p>In every case, the pushed content hash value is only used for
 * comparison. The hash value is only set in the queue during an
 * update (see {@link #getDoc(Item)}).
 *
 * @param checkpoint value defined and maintained by this connector
 * @return this is typically a {@link PushItems} instance
 */
@Override
public CheckpointCloseableIterable<ApiOperation> getIds(byte[] checkpoint)
    throws RepositoryException {
  List<String> repositories;
  // Decode the checkpoint if present to get the list of remaining
  // repositories to index.
  if (checkpoint != null) {
    try {
      FullTraversalCheckpoint decodedCheckpoint = FullTraversalCheckpoint
          .fromBytes(checkpoint);
      repositories = decodedCheckpoint.getRemainingRepositories();
    } catch (IOException e) {
      throw new RepositoryException.Builder()
          .setErrorMessage("Unable to deserialize checkpoint")
          .setCause(e)
          .build();
    }
  } else {
    // No previous checkpoint, scan for repositories to index
    // based on the connector configuration.
    try {
      repositories = scanRepositories();
    } catch (IOException e) {
      throw toRepositoryError(e, Optional.of("Unable to scan repositories"));
    }
  }

  if (repositories.isEmpty()) {
    // Nothing left to index. Reset the checkpoint to null so the
    // next full traversal starts from the beginning
    Collection<ApiOperation> empty = Collections.emptyList();
    return new CheckpointCloseableIterableImpl.Builder<>(empty)
        .setCheckpoint((byte[]) null)
        .setHasMore(false)
        .build();
  }

  // Still have more repositories to index. Pop the next repository to
  // index off the list. The remaining repositories make up the next
  // checkpoint.
  String repositoryToIndex = repositories.get(0);
  repositories = repositories.subList(1, repositories.size());

  try {
    log.info(() -> String.format("Traversing repository %s", repositoryToIndex));
    Collection<ApiOperation> items = collectRepositoryItems(repositoryToIndex);
    FullTraversalCheckpoint newCheckpoint = new FullTraversalCheckpoint(repositories);
    return new CheckpointCloseableIterableImpl.Builder<>(items)
        .setHasMore(true)
        .setCheckpoint(newCheckpoint.toBytes())
        .build();
  } catch (IOException e) {
    String errorMessage = String.format("Unable to traverse repo: %s",
        repositoryToIndex);
    throw toRepositoryError(e, Optional.of(errorMessage));
  }
}

เมธอด collectRepositoryItems() จะจัดการการข้ามผ่านที่เก็บ GitHub เดียว เมธอดนี้จะส่งคืนคอลเล็กชัน ApiOperations ซึ่งแสดงถึงรายการที่จะพุชลงในคิว ระบบจะพุชรายการเป็นชื่อทรัพยากรและค่าแฮชที่แสดงถึงสถานะปัจจุบันของรายการ

ระบบจะใช้ค่าแฮชในการข้ามผ่านที่เก็บ GitHub ครั้งต่อๆ ไป ค่านี้จะช่วยตรวจสอบแบบเบาๆ เพื่อดูว่าเนื้อหาเปลี่ยนแปลงไปหรือไม่โดยไม่ต้องอัปโหลดเนื้อหาเพิ่มเติม เครื่องมือเชื่อมต่อจะจัดคิวรายการทั้งหมดโดยไม่เลือก หากรายการเป็นรายการใหม่หรือค่าแฮชเปลี่ยนแปลงไป ระบบจะทำให้รายการพร้อมสำหรับการโพลในคิว มิฉะนั้นจะถือว่ารายการไม่เปลี่ยนแปลง

GithubRepository.java
/**
 * Fetch IDs to  push in to the queue for all items in the repository.
 * Currently captures issues & content in the master branch.
 *
 * @param name Name of repository to index
 * @return Items to push into the queue for later indexing
 * @throws IOException if error reading issues
 */
private Collection<ApiOperation> collectRepositoryItems(String name)
    throws IOException {
  List<ApiOperation> operations = new ArrayList<>();
  GHRepository repo = github.getRepository(name);

  // Add the repository as an item to be indexed
  String metadataHash = repo.getUpdatedAt().toString();
  String resourceName = repo.getHtmlUrl().getPath();
  PushItem repositoryPushItem = new PushItem()
      .setMetadataHash(metadataHash);
  PushItems items = new PushItems.Builder()
      .addPushItem(resourceName, repositoryPushItem)
      .build();

  operations.add(items);
  // Add issues/pull requests & files
  operations.add(collectIssues(repo));
  operations.add(collectContent(repo));
  return operations;
}

การประมวลผลคิว

หลังจากที่การข้ามผ่านแบบเต็มเสร็จสมบูรณ์ เครื่องมือเชื่อมต่อจะเริ่มโพลคิวเพื่อหารายการที่ต้องจัดทำดัชนี ระบบจะเรียกใช้เมธอด getDoc() สำหรับแต่ละรายการที่ดึงมาจากคิว เมธอดจะอ่านรายการจาก GitHub และแปลงรายการเป็นรูปแบบที่เหมาะสมสำหรับการจัดทำดัชนี

เนื่องจากเครื่องมือเชื่อมต่อทำงานกับข้อมูลจริงที่อาจเปลี่ยนแปลงได้ทุกเมื่อ getDoc() จึงจะตรวจสอบด้วยว่ารายการในคิวยังคงถูกต้องและลบรายการที่ไม่มีอยู่ออกจากดัชนี

GithubRepository.java
/**
 * Gets a single data repository item and indexes it if required.
 *
 * <p>This method is called by the {@link ListingConnector} during a poll
 * of the Cloud Search queue. Each queued item is processed
 * individually depending on its state in the data repository.
 *
 * @param item the data repository item to retrieve
 * @return the item's state determines which type of
 * {@link ApiOperation} is returned:
 * {@link RepositoryDoc}, {@link DeleteItem}, or {@link PushItem}
 */
@Override
public ApiOperation getDoc(Item item) throws RepositoryException {
  log.info(() -> String.format("Processing item: %s ", item.getName()));
  Object githubObject;
  try {
    // Retrieve the item from GitHub
    githubObject = getGithubObject(item.getName());
    if (githubObject instanceof GHRepository) {
      return indexItem((GHRepository) githubObject, item);
    } else if (githubObject instanceof GHPullRequest) {
      return indexItem((GHPullRequest) githubObject, item);
    } else if (githubObject instanceof GHIssue) {
      return indexItem((GHIssue) githubObject, item);
    } else if (githubObject instanceof GHContent) {
      return indexItem((GHContent) githubObject, item);
    } else {
      String errorMessage = String.format("Unexpected item received: %s",
          item.getName());
      throw new RepositoryException.Builder()
          .setErrorMessage(errorMessage)
          .setErrorType(RepositoryException.ErrorType.UNKNOWN)
          .build();
    }
  } catch (FileNotFoundException e) {
    log.info(() -> String.format("Deleting item: %s ", item.getName()));
    return ApiOperations.deleteItem(item.getName());
  } catch (IOException e) {
    String errorMessage = String.format("Unable to retrieve item: %s",
        item.getName());
    throw toRepositoryError(e, Optional.of(errorMessage));
  }
}

สำหรับออบเจ็กต์ GitHub แต่ละรายการที่เครื่องมือเชื่อมต่อจัดทำดัชนี เมธอด indexItem() ที่เกี่ยวข้องจะจัดการการสร้างรูปแบบรายการสำหรับ Cloud Search ตัวอย่างเช่น หากต้องการสร้างรูปแบบสำหรับรายการเนื้อหา ให้ทำดังนี้

GithubRepository.java
/**
 * Build the ApiOperation to index a content item (file).
 *
 * @param content      Content item to index
 * @param previousItem Previous item state in the index
 * @return ApiOperation (RepositoryDoc if indexing,  PushItem if not modified)
 * @throws IOException if unable to create operation
 */
private ApiOperation indexItem(GHContent content, Item previousItem)
    throws IOException {
  String metadataHash = content.getSha();

  // If previously indexed and unchanged, just requeue as unmodified
  if (canSkipIndexing(previousItem, metadataHash)) {
    return notModified(previousItem.getName());
  }

  String resourceName = new URL(content.getHtmlUrl()).getPath();
  FieldOrValue<String> title = FieldOrValue.withValue(content.getName());
  FieldOrValue<String> url = FieldOrValue.withValue(content.getHtmlUrl());

  String containerName = content.getOwner().getHtmlUrl().getPath();
  String programmingLanguage = FileExtensions.getLanguageForFile(content.getName());

  // Structured data based on the schema
  Multimap<String, Object> structuredData = ArrayListMultimap.create();
  structuredData.put("organization", content.getOwner().getOwnerName());
  structuredData.put("repository", content.getOwner().getName());
  structuredData.put("path", content.getPath());
  structuredData.put("language", programmingLanguage);

  Item item = IndexingItemBuilder.fromConfiguration(resourceName)
      .setTitle(title)
      .setContainerName(containerName)
      .setSourceRepositoryUrl(url)
      .setItemType(IndexingItemBuilder.ItemType.CONTAINER_ITEM)
      .setObjectType("file")
      .setValues(structuredData)
      .setVersion(Longs.toByteArray(System.currentTimeMillis()))
      .setHash(content.getSha())
      .build();

  // Index the file content too
  String mimeType = FileTypeMap.getDefaultFileTypeMap()
      .getContentType(content.getName());
  AbstractInputStreamContent fileContent = new InputStreamContent(
      mimeType, content.read())
      .setLength(content.getSize())
      .setCloseInputStream(true);
  return new RepositoryDoc.Builder()
      .setItem(item)
      .setContent(fileContent, IndexingService.ContentFormat.RAW)
      .setRequestMode(IndexingService.RequestMode.SYNCHRONOUS)
      .build();
}

จากนั้นให้ติดตั้งใช้งานอินเทอร์เฟซการค้นหา

ก่อนหน้า ถัดไป