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

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

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

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

mvn package -DskipTests

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

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

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

  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 एपीआई को कॉल करने से पहले, आपको Google Cloud Search के लिए तीसरे पक्ष की सहायता शुरू करनी होगी.

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

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

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

    1. सेटिंग पर क्लिक करें और उपयोगकर्ता के पुष्टि करने के क्रेडेंशियल देखें.
    2. पहले चरण में दिया गया क्लाइंट आईडी और क्लाइंट सीक्रेट डालें.
    3. बंद करें पर क्‍लिक करें.
    4. स्कोप फ़ील्ड में, https://www.googleapis.com/auth/cloud_search.settings टाइप करें और Authorize पर क्लिक करें. 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. Apps आइकन पर क्लिक करें. "ऐप्लिकेशन एडमिन" पेज दिखेगा.
  3. Google Workspace पर क्लिक करें. आपको "ऐप्लिकेशन के लिए Google Workspace एडमिन" पेज दिखेगा.
  4. नीचे स्क्रॉल करें और Cloud Search पर क्लिक करें. ऐसा करने पर, "Google Workspace की सेटिंग" पेज दिखेगा.
  5. तीसरे पक्ष के डेटा सोर्स पर क्लिक करें. "डेटा सोर्स" पेज दिखेगा.
  6. गोल पीले रंग के + आइकॉन पर क्लिक करें. इसके बाद, "नया डेटा सोर्स जोड़ें" डायलॉग दिखेगा.
  7. डिसप्ले नेम फ़ील्ड में, "ट्यूटोरियल" लिखें.
  8. सेवा खाते के ईमेल पते फ़ील्ड में, उस सेवा खाते का ईमेल पता डालें जिसे आपने पिछले सेक्शन में बनाया था. अगर आपको सेवा खाते का ईमेल पता नहीं पता है, तो सेवा खाते पेज पर दी गई वैल्यू देखें.
  9. जोड़ें पर क्लिक करें. आपको "डेटा सोर्स बनाया गया" वाला डायलॉग बॉक्स दिखेगा.
  10. *ठीक है पर क्लिक करें. नए डेटा सोर्स का सोर्स आईडी नोट करें. सोर्स आईडी का इस्तेमाल कॉन्टेंट कनेक्टर को कॉन्फ़िगर करने के लिए किया जाता है.

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

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

  1. GitHub में लॉग इन करें.
  2. सबसे ऊपर दाएं कोने में, अपनी प्रोफ़ाइल फ़ोटो पर क्लिक करें. एक ड्रॉप-डाउन मेन्यू दिखेगा.
  3. सेटिंग पर क्लिक करें.
  4. डेवलपर सेटिंग पर क्लिक करें.
  5. निजी ऐक्सेस टोकन पर क्लिक करें.
  6. निजी ऐक्सेस टोकन जनरेट करें पर क्लिक करें.
  7. नोट फ़ील्ड में, "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();
}

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

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