Package net.sf.regain

Examples of net.sf.regain.RegainException


        // nutzen.
        mContentAsFile = file;
      }
    }
    catch (RegainException exc) {
      throw new RegainException("Creating file that contains the "
        + "document from '" + mUrl + "' failed", exc);
    }
  }
View Full Code Here


      File tmpFile;
      try {
        tmpFile = File.createTempFile("lucenesearch_", extension);
      }
      catch (IOException exc) {
        throw new RegainException("Getting temporary File failed", exc);
      }

      // write content in temporary file
      writeToFile(tmpFile);
View Full Code Here

  public void printEndTag(PageRequest request, PageResponse response)
    throws RegainException
  {
    Float score = (Float) request.getContextAttribute(ATTR_CURRENT_HIT_SCORE);
    if (score == null) {
      throw new RegainException("Tag " + getTagName()
          + " must be inside a list tag!");
    }

    response.print(Math.round(score.floatValue() * 100) + "%");
  }
View Full Code Here

  {
    // Load the preparators
    HashMap preparatorHash = new HashMap();
    File preparatorDir = new File("preparator");
    if (! preparatorDir.exists()) {
      throw new RegainException("Preparator directory not found: " +
          preparatorDir.getAbsolutePath());
    }
    File[] jarFileArr = preparatorDir.listFiles();
    for (int i = 0; i < jarFileArr.length; i++) {
      if (jarFileArr[i].getName().toLowerCase().endsWith(".jar")) {
        loadPrepararorJar(jarFileArr[i], preparatorHash, preparatorSettingsArr);
      }
    }
   
    // Create the preparator array
    Preparator[] preparatorArr = new Preparator[preparatorHash.size()];
    int prepIdx = 0;

    // Add the configured preparators in the configured order
    for (int i = 0; i < preparatorSettingsArr.length; i++) {
      if (preparatorSettingsArr[i].isEnabled()) {
        // Add the preparator with this class
        // NOTE: We remove the preparator to avoid a double initializeation
        //       and to get easily the unconfigured preparators
        String prepClassName = preparatorSettingsArr[i].getPreparatorClassName();
        Preparator prep = (Preparator) preparatorHash.remove(prepClassName);
        if (prep == null) {
          mLog.warn("Crawler configuration contains non-existing preparator: "
              + prepClassName);
        } else {
          // Initialize the preparator
          prep.init(preparatorSettingsArr[i].getPreparatorConfig());
         
          // Set the url regex
          String urlRegexAsString = preparatorSettingsArr[i].getUrlRegex();
          if (urlRegexAsString != null) {
            RE urlRegex;
            try {
              urlRegex = new RE(urlRegexAsString);
            }
            catch (RESyntaxException exc) {
              throw new RegainException("urlRegex of preparator " + prepClassName
                  + " has wrong syntax", exc);
            }
            prep.setUrlRegex(urlRegex);
          }
         
View Full Code Here

      // Read the class names
      Attributes attributes = manifest.getMainAttributes();
      String classNameCsv = attributes.getValue("Preparator-Classes");
      if (classNameCsv == null) {
        throw new RegainException("The manifest in preparator file '" + file
            + "' has no 'Preparator-Classes' attribute");
      }
      String[] classNameArr = RegainToolkit.splitString(classNameCsv, ";", true);
     
      // Load the classes if they are not disabled
      URLClassLoader loader = null;
      for (int i = 0; i < classNameArr.length; i++) {
        // Get the class name
        String className = classNameArr[i];
        if (className.startsWith(".")) {
          className = PreparatorSettings.DEFAULT_PREPARATOR_PACKAGE + className;
        }
       
        if (isPreparatorEnabled(className, preparatorSettingsArr)) {
          // Create the class loader if nessesary
          if (loader == null) {
            loader = new URLClassLoader(new URL[] { file.toURI().toURL() });
          }
         
          // Load the preparator and add it to the preparatorHash
          Preparator prep = (Preparator) RegainToolkit.createClassInstance(className, Preparator.class, loader);
          preparatorHash.put(className, prep);
        }
      }
    }
    catch (Throwable thr) {
      throw new RegainException("Loading preparator file '" + file
          + "' failed", thr);
    }
    finally {
      if (jarFile != null) {
        try { jarFile.close(); } catch (IOException exc) {}
View Full Code Here

    mQuarantineIndexDir = new File(indexDir, QUARANTINE_INDEX_SUBDIR);
    mTempIndexDir = new File(indexDir, TEMP_INDEX_SUBDIR);
    try {
      mLuceneTempIndexDir = FSDirectory.open(mTempIndexDir);
    } catch (IOException ioEx) {
      throw new RegainException("Couldn't open tmpIndexDir", ioEx);
    }
    mBreakpointIndexDir = new File(indexDir, BREAKPOINT_INDEX_SUBDIR);

    mErrorLogFile = new File(mTempIndexDir, "log/error.log");

    // Delete the old temp index directory if it should still exist
    if (mTempIndexDir.exists()) {
      RegainToolkit.deleteDirectory(mTempIndexDir);
    }
    // and create a new, empty one
    if (!mTempIndexDir.mkdir()) {
      throw new RegainException("Creating working directory failed: " + mTempIndexDir.getAbsolutePath());
    }

    // Get the untokenized field names
    String[] untokenizedFieldNames = config.getUntokenizedFieldNames();

    // Create the Analyzer
    // NOTE: Make shure you use the same Analyzer in the SearchContext too!
    String analyzerType = config.getAnalyzerType();
    String[] stopWordList = config.getStopWordList();
    String[] exclusionList = config.getExclusionList();
    mAnalyzer = RegainToolkit.createAnalyzer(analyzerType, stopWordList,
            exclusionList, untokenizedFieldNames);

    // Alten Index kopieren, wenn Index aktualisiert werden soll
    if (updateIndex) {
      if (!copyExistingIndex(indexDir, analyzerType)) {
        mUpdateIndex = updateIndex = false;
      }
    }

    // Check whether we have to create a new index
    boolean createNewIndex = !updateIndex;
    if (createNewIndex) {
      // Create a new index
      try {
        mIndexWriter = createIndexWriter(true);
      } catch (IOException exc) {
        throw new RegainException("Creating new index failed", exc);
      }
    }

    if (updateIndex) {
      // Force an unlock of the index (we just created a copy so this is save)
      setIndexMode(READING_MODE);
      try {

        IndexWriter.unlock(mIndexReader.directory());
        mInitialDocCount = mIndexReader.numDocs();
      } catch (IOException exc) {
        throw new RegainException("Forcing unlock failed", exc);
      }
    }

    // Write the stopWordList and the exclusionList in a file so it can be found
    // by the search mask
    RegainToolkit.writeToFile(analyzerType, new File(mTempIndexDir, "analyzerType.txt"));
    RegainToolkit.writeListToFile(stopWordList, new File(mTempIndexDir, "stopWordList.txt"));
    RegainToolkit.writeListToFile(exclusionList, new File(mTempIndexDir, "exclusionList.txt"));
    if (untokenizedFieldNames.length != 0) {
      RegainToolkit.writeListToFile(untokenizedFieldNames, new File(mTempIndexDir, "untokenizedFieldNames.txt"));
    }

    // Prepare the analysis directory if wanted
    if (config.getWriteAnalysisFiles()) {
      mAnalysisDir = new File(mTempIndexDir.getAbsolutePath() + File.separator + "analysis");

      if (!mAnalysisDir.mkdir()) {
        throw new RegainException("Creating analysis directory failed: " + mAnalysisDir.getAbsolutePath());
      }
    }

    mDocumentFactory = new DocumentFactory(config, mAnalysisDir);
  }
View Full Code Here

      try {
        new File(mTempIndexDir, "log").mkdir();
        mErrorLogStream = new FileOutputStream(mErrorLogFile, true);
        mErrorLogWriter = new PrintWriter(mErrorLogStream);
      } catch (IOException exc) {
        throw new RegainException("Opening error log file of the index failed", exc);
      }
    }

    if (thr == null) {
      mErrorLogWriter.println(msg);
View Full Code Here

      if (mIndexReader != null) {
        try {
          mIndexReader.close();
          mIndexReader = null;
        } catch (IOException exc) {
          throw new RegainException("Closing IndexReader failed", exc);
        }
      }
    }

    // Close the mIndexWriter in READING_MODE and ALL_CLOSED_MODE
    if ((mode == READING_MODE) || (mode == ALL_CLOSED_MODE)) {
      if (mIndexWriter != null) {
        try {
          mIndexWriter.close();
          mIndexWriter = null;
        } catch (IOException exc) {
          throw new RegainException("Closing IndexWriter failed", exc);
        }
      }
    }

    // Close the mIndexSearcher in ALL_CLOSED_MODE
    if ((mode == ALL_CLOSED_MODE) && (mIndexSearcher != null)) {
      try {
        mIndexSearcher.close();
        mIndexSearcher = null;
      } catch (IOException exc) {
        throw new RegainException("Closing IndexSearcher failed", exc);
      }
    }

    // Open the mIndexWriter in WRITING_MODE
    if ((mode == WRITING_MODE) && (mIndexWriter == null)) {
      mLog.info("Switching to index mode: adding mode");
      try {
        mIndexWriter = createIndexWriter(false);
      } catch (IOException exc) {
        throw new RegainException("Creating IndexWriter failed", exc);
      }
    }

    // Open the mIndexReader in READING_MODE
    if ((mode == READING_MODE) && (mIndexReader == null)) {
      mLog.info("Switching to index mode: deleting mode");
      try {
        mIndexReader = IndexReader.open(mLuceneTempIndexDir, false);
      } catch (IOException exc) {
        throw new RegainException("Creating IndexReader failed", exc);
      }
    }

    // Open the mIndexSearcher in SEARCHING_MODE
    if ((mode == SEARCHING_MODE) && (mIndexSearcher == null)) {
      mLog.info("Switching to index mode: searching mode");
      try {
        mIndexSearcher = new IndexSearcher(mLuceneTempIndexDir, false);
      } catch (IOException exc) {
        throw new RegainException("Creating IndexSearcher failed", exc);
      }
    }

    // Tell the user, when switching to ALL_CLOSED_MODE
    if (mode == ALL_CLOSED_MODE) {
View Full Code Here

          // we found one hit for our URL
          result = true;

        }
      } catch (IOException exc) {
        throw new RegainException("Searching old index entry failed for " + url, exc);
      }
    }
    return result;
  }
View Full Code Here

          doc = mIndexSearcher.doc(hits[0].doc);
        } else {
          doc = null;
        }
      } catch (IOException exc) {
        throw new RegainException("Searching old index entry failed for " + rawDocument.getUrl(), exc);
      }

      // If we found an entry, check whether it is up-to-date
      if (doc != null) {
        // Get the last modification date from the document
View Full Code Here

TOP

Related Classes of net.sf.regain.RegainException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.