Пример #1
0
  public void init(IndexUpdater indexUpdater, IndexRebuilder indexRebuilder, XWikiContext context) {
    super.init(context);

    try {
      @SuppressWarnings("unchecked")
      Class<? extends Analyzer> clazz =
          (Class<? extends Analyzer>)
              Class.forName(context.getWiki().Param(PROP_ANALYZER, DEFAULT_ANALYZER));
      this.analyzer = clazz.getConstructor(Version.class).newInstance(Version.LUCENE_36);
    } catch (Exception e) {
      LOGGER.error("Error instantiating analyzer: {}", e.getMessage());
      LOGGER.warn("Using default analyzer class: " + DEFAULT_ANALYZER);
      try {
        @SuppressWarnings("unchecked")
        Class<? extends Analyzer> clazz =
            (Class<? extends Analyzer>) Class.forName(DEFAULT_ANALYZER);
        this.analyzer = clazz.getConstructor(Version.class).newInstance(Version.LUCENE_36);
      } catch (Exception e1) {
        throw new RuntimeException(
            "Instantiation of default analyzer " + DEFAULT_ANALYZER + " failed", e1);
      }
    }
    Map<String, Analyzer> specialAnalyzers = new HashMap<String, Analyzer>();
    Analyzer preserve = new KeywordAnalyzer();
    specialAnalyzers.put(IndexFields.DOCUMENT_EXACTSPACE, preserve);
    specialAnalyzers.put(IndexFields.DOCUMENT_WIKI, preserve);
    specialAnalyzers.put(IndexFields.DOCUMENT_TYPE, preserve);
    specialAnalyzers.put(IndexFields.DOCUMENT_LANGUAGE, preserve);
    this.analyzer = new PerFieldAnalyzerWrapper(this.analyzer, specialAnalyzers);

    LOGGER.debug("Assigning index updater: {}", indexUpdater);

    if (this.indexDirs == null) {
      this.indexDirs = context.getWiki().Param(PROP_INDEX_DIR);
      if (StringUtils.isEmpty(this.indexDirs)) {
        File workDir = getLuceneWorkDirectory();
        this.indexDirs = workDir.getAbsolutePath();
      }
    }

    this.indexUpdater = indexUpdater;
    this.indexUpdater.setAnalyzer(this.analyzer);
    this.indexUpdaterThread = new Thread(indexUpdater, "Lucene Index Updater");
    this.indexUpdaterThread.start();
    this.indexRebuilder = indexRebuilder;

    openIndexReaders(context);

    // Register the Index Updater as an Event Listener so that modified documents/attachments are
    // added to the
    // Lucene indexing queue.
    // If the Index Updater is already registered don't do anything.
    ObservationManager observationManager = Utils.getComponent(ObservationManager.class);
    if (observationManager.getListener(indexUpdater.getName()) == null) {
      observationManager.addListener(indexUpdater);
    }

    LOGGER.debug("Lucene plugin initialized.");
  }
Пример #2
0
  public void init(IndexUpdater indexUpdater, XWikiContext context) {
    Directory directory = indexUpdater.getDirectory();

    boolean needInitialRebuild = true;
    needInitialRebuild = !DirectoryReader.indexExists(directory);

    IndexRebuilder indexRebuilder = new IndexRebuilder(indexUpdater, context);
    if (needInitialRebuild) {
      indexRebuilder.startRebuildIndex(context);
      LOGGER.info("Launched initial lucene indexing");
    }

    init(indexUpdater, indexRebuilder, context);
  }