कनेक्टर को डिप्लॉय करें

Cloud Search ट्यूटोरियल के इस पेज में डेटा को इंडेक्स करने के लिए, डेटा सोर्स और कॉन्टेंट कनेक्टर को सेट अप करने का तरीका बताया गया है. इस ट्यूटोरियल की शुरुआत से शुरू करने के लिए, Cloud Search शुरू करने का ट्यूटोरियल देखें

कनेक्टर बनाएं

अपनी वर्किंग डायरेक्ट्री को cloud-search-samples/end-to-end/connector डायरेक्ट्री में बदलें और यह निर्देश चलाएं:

mvn package -DskipTests

निर्देश, कॉन्टेंट कनेक्टर बनाने के लिए ज़रूरी डिपेंडेंसी डाउनलोड करता है और कोड को कंपाइल करता है.

सेवा खाते के क्रेडेंशियल बनाएं

Cloud Search API को कॉल करने के लिए, कनेक्टर को सेवा खाते के क्रेडेंशियल की ज़रूरत होती है. क्रेडेंशियल बनाने के लिए:

  1. Google Cloud Console पर वापस जाएं.
  2. बाईं ओर मौजूद नेविगेशन में, क्रेडेंशियल पर क्लिक करें. "क्रेडेंशियल" पेज दिखेगा.
  3. + क्रेडेंशियल बनाएं ड्रॉप-डाउन सूची पर क्लिक करें और सेवा खाता चुनें. आपको "सेवा खाता बनाएं" पेज दिखेगा.
  4. सेवा खाते का नाम फ़ील्ड में, "ट्यूटोरियल" डालें.
  5. सेवा खाता आईडी की वैल्यू नोट करें (सेवा खाते के नाम के ठीक बाद). इस वैल्यू का इस्तेमाल बाद में किया जाता है.
  6. बनाएं पर क्लिक करें. आपको "सेवा खाते की अनुमतियां (ज़रूरी नहीं)" डायलॉग दिखेगा.
  7. जारी रखें पर क्लिक करें. आपको "उपयोगकर्ताओं को इस सेवा खाते का ऐक्सेस दें (ज़रूरी नहीं)" डायलॉग दिखेगा.
  8. हो गया पर क्लिक करें. "क्रेडेंशियल" स्क्रीन दिखेगी.
  9. सेवा खातों में जाकर, सेवा खाते के ईमेल पर क्लिक करें. "सेवा खाते की जानकारी" पेज के बारे में बताने वाला पेज.
  10. 'कुंजी' में, कुंजी जोड़ें की ड्रॉप-डाउन सूची पर क्लिक करें और नई कुंजी बनाएं चुनें. आपको "निजी पासकोड बनाएं" डायलॉग दिखेगा.
  11. बनाएं पर क्लिक करें.
  12. (ज़रूरी नहीं) अगर "क्या आपको Console.cloud.google.com पर डाउनलोड करने की अनुमति देनी है?” डायलॉग दिखता है, तो अनुमति दें पर क्लिक करें.
  13. आपके कंप्यूटर पर एक निजी कुंजी फ़ाइल सेव की गई है. डाउनलोड की गई फ़ाइल की जगह को नोट करें. इस फ़ाइल का इस्तेमाल कॉन्टेंट कनेक्टर को कॉन्फ़िगर करने के लिए किया जाता है, ताकि Google Cloud Search API को कॉल करते समय यह अपनी पहचान की पुष्टि कर सके.

तीसरे पक्ष से मिलने वाली सहायता शुरू करें

किसी दूसरे Cloud Search API को कॉल करने से पहले, आपको Google Cloud Search के लिए तीसरे पक्ष की सहायता शुरू करनी होगी.

Cloud Search के लिए, तीसरे पक्ष से मिलने वाली सहायता को शुरू करने के लिए:

  1. आपके Cloud Search प्लैटफ़ॉर्म प्रोजेक्ट में, सेवा खाते के क्रेडेंशियल मौजूद हैं. हालांकि, तीसरे पक्ष से मदद पाने के लिए, आपको वेब ऐप्लिकेशन क्रेडेंशियल बनाने होंगे. वेब ऐप्लिकेशन क्रेडेंशियल बनाने के तरीके के बारे में निर्देशों के लिए, क्रेडेंशियल बनाएं देखें. यह चरण पूरा करने के बाद, आपके पास एक क्लाइंट आईडी और क्लाइंट सीक्रेट फ़ाइल होनी चाहिए.

  2. ऐक्सेस टोकन पाने के लिए, Google के OAuth 2 प्लेग्राउंड का इस्तेमाल करें:

    1. सेटिंग पर क्लिक करें और उपयोगकर्ता के लिए, पुष्टि करने के अपने क्रेडेंशियल पर सही का निशान लगाएं.
    2. पहले चरण में क्लाइंट आईडी और क्लाइंट सीक्रेट डालें.
    3. बंद करें पर क्‍लिक करें.
    4. स्कोप फ़ील्ड में, https://www.googleapis.com/auth/cloud_search.settings टाइप करें और अनुमति दें पर क्लिक करें. OAuth 2 प्लेग्राउंड एक ऑथराइज़ेशन कोड दिखाता है.
    5. टोकन के लिए ऑथराइज़ेशन कोड एक्सचेंज करें पर क्लिक करें. टोकन लौटाया जाता है.
  3. Cloud Search के लिए तीसरे पक्ष से मिलने वाली सहायता शुरू करने के लिए, यहां दिया गया कर्ल कमांड इस्तेमाल करें. [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 का एक इंस्टेंस शामिल होता है. उदाहरण के लिए:

    {
    name: "operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY"
    }
    

    अगर ऐसा नहीं हो पाता है, तो Cloud Search की सहायता टीम से संपर्क करें.

  4. operations.get का इस्तेमाल करके, इस बात की पुष्टि करें कि तीसरे पक्ष से सहायता मिलने की सुविधा शुरू की गई है या नहीं:

    curl \
    'https://cloudsearch.googleapis.com/v1/operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY?key=
    [YOUR_API_KEY]' \
    --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
    --header 'Accept: application/json' \
    --compressed
    

    तीसरे पक्ष की प्रोसेस शुरू होने के बाद, इसमें फ़ील्ड done को true पर सेट किया जाता है. उदाहरण के लिए:

    {
    name: "operations/customers/01b3fqdm/lro/AOIL6eBv7fEfiZ_hUSpm8KQDt1Mnd6dj5Ru3MXf-jri4xK6Pyb2-Lwfn8vQKg74pgxlxjrY"
    done: true
    }
    

डेटा सोर्स बनाना

इसके बाद, Admin console में एक डेटा सोर्स बनाएं. डेटा सोर्स, कनेक्टर का इस्तेमाल करके कॉन्टेंट को इंडेक्स करने के लिए एक नेमस्पेस देता है.

  1. Google Admin console खोलें.
  2. ऐप्लिकेशन आइकॉन पर क्लिक करें. आपको "ऐप्लिकेशन एडमिन" पेज दिखेगा.
  3. Google Workspace पर क्लिक करें. आपको "Google Workspace एडमिन" पेज दिखेगा.
  4. नीचे की ओर स्क्रोल करें और Cloud Search पर क्लिक करें. ऐसा करने पर, आपको "Google Workspace के लिए सेटिंग" पेज दिखेगा.
  5. तीसरे पक्ष के डेटा सोर्स पर क्लिक करें. इसके बाद, "डेटा सोर्स" पेज दिखेगा.
  6. पीले रंग के गोल + पर क्लिक करें. इसके बाद, "नया डेटा सोर्स जोड़ें" डायलॉग दिखेगा.
  7. डिसप्ले नेम फ़ील्ड में, "ट्यूटोरियल" टाइप करें.
  8. सेवा खाते के ईमेल पते फ़ील्ड में, पिछले सेक्शन में बनाए गए सेवा खाते का ईमेल पता डालें. अगर आपको सेवा खाते का ईमेल पता नहीं पता है, तो सेवा खाते पेज पर वैल्यू देखें.
  9. जोड़ें पर क्लिक करें. आपको "डेटा सोर्स बन गया" डायलॉग दिखेगा.
  10. *ठीक है पर क्लिक करें. नए बनाए गए डेटा सोर्स के सोर्स आईडी को नोट करें. सोर्स आईडी का इस्तेमाल, कॉन्टेंट कनेक्टर को कॉन्फ़िगर करने के लिए किया जाता है.

GitHub API के लिए निजी ऐक्सेस टोकन जनरेट करें

कनेक्टर को ज़रूरत के मुताबिक कोटा होने के लिए, GitHub एपीआई की पुष्टि की गई ऐक्सेस की ज़रूरत होती है. इसे आसानी से समझने के लिए, कनेक्टर OAuth के बजाय निजी ऐक्सेस टोकन का इस्तेमाल करता है. निजी टोकन की मदद से, एक ऐसे उपयोगकर्ता के तौर पर पुष्टि की जा सकती है जिसके पास OAuth जैसी सीमित अनुमतियां होती हैं.

  1. GitHub में लॉग इन करें.
  2. सबसे ऊपर दाएं कोने में, अपनी प्रोफ़ाइल फ़ोटो पर क्लिक करें. इसके बाद, आपको एक ड्रॉप-डाउन मेन्यू दिखेगा.
  3. सेटिंग पर क्लिक करें.
  4. डेवलपर सेटिंग पर क्लिक करें.
  5. निजी ऐक्सेस टोकन पर क्लिक करें.
  6. निजी ऐक्सेस टोकन जनरेट करें पर क्लिक करें.
  7. Note फ़ील्ड में, "Cloud Search ट्यूटोरियल" डालें.
  8. public_repo स्कोप की जांच करें.
  9. टोकन जनरेट करें पर क्लिक करें.
  10. जनरेट किए गए टोकन को नोट करें. कनेक्टर इसका इस्तेमाल, GitHub एपीआई को कॉल करने के लिए करता है. साथ ही, इंडेक्स करने के लिए एपीआई कोटा देता है.

कनेक्टर को कॉन्फ़िगर करें

क्रेडेंशियल और डेटा सोर्स बनाने के बाद, इन वैल्यू को शामिल करने के लिए कनेक्टर कॉन्फ़िगरेशन अपडेट करें:

  1. कमांड लाइन से, डायरेक्ट्री को cloud-search-samples/end-to-end/connector/ में बदलें.
  2. sample-config.properties फ़ाइल को टेक्स्ट एडिटर में खोलें.
  3. पहले डाउनलोड किए गए सेवा क्रेडेंशियल के फ़ाइल पाथ में, api.serviceAccountPrivateKeyFile पैरामीटर सेट करें.
  4. api.sourceId पैरामीटर को उस डेटा सोर्स के आईडी पर सेट करें जिसे आपने पहले बनाया था.
  5. अपने GitHub उपयोगकर्ता नाम के लिए, github.user पैरामीटर सेट करें.
  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 संगठन में किसी एक रिपॉज़िटरी (डेटा स्टोर करने की जगह) को इंडेक्स करना होता है. डेटा स्टोर करने की जगह को इंडेक्स करने में करीब एक मिनट लगता है. शुरुआती इंडेक्स करने के बाद, कनेक्टर डेटा स्टोर करने की जगह में उन बदलावों के लिए पोल जारी रखता है जिन्हें Cloud Search इंडेक्स में दिखाना ज़रूरी होता है.

कोड की समीक्षा करना

बाकी सेक्शन से पता चलता है कि कनेक्टर कैसे बनाया गया है.

ऐप्लिकेशन शुरू किया जा रहा है

कनेक्टर का एंट्री पॉइंट, GithubConnector क्लास है. main वाला तरीका, SDK टूल के IndexingApplication को इंस्टैंशिएट करता है और उसे शुरू करता है.

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

SDK टूल से मिला ListingConnector, एक ट्रैवर्सल रणनीति लागू करता है. यह इंडेक्स में आइटम की स्थिति को ट्रैक करने के लिए, Cloud Search सूची का इस्तेमाल करती है. यह, GitHub से कॉन्टेंट ऐक्सेस करने के लिए GithubRepository को डेलिगेट करता है, जिसे सैंपल कनेक्टर की मदद से लागू किया जाता है.

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

इसके बाद, सर्च इंटरफ़ेस डिप्लॉय करें.

पीछे जाएं आगे बढ़ें