예제 #1
0
  @Override
  public void work() throws Exception {
    if (ids.isEmpty()) {
      return;
    }
    initSession(repositoryName);
    // if the runtime has shutdown (normally because tests are finished)
    // this can happen, see NXP-4009
    if (session.getPrincipal() == null) {
      return;
    }

    fulltextInfo = RepositoryResolver.getModelFulltext(repositoryName);
    fulltextParserClass = RepositoryResolver.getFulltextParserClass(repositoryName);
    initFulltextParser();

    // we have all the info from the bundle, now do the extraction
    BlobsExtractor extractor = new BlobsExtractor();
    Collection<FulltextUpdaterInfo> infos = new ArrayList<FulltextUpdaterInfo>();
    int n = 0;
    setStatus("Extracting");
    for (String id : ids) {
      setProgress(new Progress(++n, ids.size()));
      IdRef docRef = new IdRef(id);
      if (!session.exists(docRef)) {
        // doc is gone
        continue;
      }
      DocumentModel doc = session.getDocument(docRef);
      if (doc.isProxy()) {
        // proxies don't have any fulltext attached, it's
        // the target document that carries it
        continue;
      }
      if (!fulltextInfo.isFulltextIndexable(doc.getType())) {
        // excluded by config
        continue;
      }

      // Iterate on each index to set the binaryText column
      for (String indexName : fulltextInfo.indexNames) {
        if (!fulltextInfo.indexesAllBinary.contains(indexName)
            && fulltextInfo.propPathsByIndexBinary.get(indexName) == null) {
          // nothing to do: index not configured for blob
          continue;
        }
        extractor.setExtractorProperties(
            fulltextInfo.propPathsByIndexBinary.get(indexName),
            fulltextInfo.propPathsExcludedByIndexBinary.get(indexName),
            fulltextInfo.indexesAllBinary.contains(indexName));
        List<Blob> blobs = extractor.getBlobs(doc);
        String text = blobsToText(blobs, id);
        fulltextParser.setStrings(new ArrayList<String>());
        fulltextParser.parse(text, null);
        text = StringUtils.join(fulltextParser.getStrings(), " ");

        FulltextUpdaterInfo info = new FulltextUpdaterInfo();
        info.jobId = doc.getId();
        info.indexName = indexName;
        info.text = text;
        infos.add(info);
      }
    }
    if (!infos.isEmpty()) {
      // false = binary text
      Work work = new FulltextUpdaterWork(false, repositoryName, infos);
      Framework.getLocalService(WorkManager.class).schedule(work);
    }
    setStatus(null);
  }