Package net.sf.regain

Examples of net.sf.regain.RegainException


        setIndexMode(WRITING_MODE);
        mIndexWriter.addDocument(doc);
        mAddToIndexProfiler.stopMeasuring(rawDocument.getLength());
      } catch (IOException exc) {
        mAddToIndexProfiler.abortMeasuring();
        throw new RegainException("Adding document to index failed", exc);
      }
    }
  }
View Full Code Here


        // Document lesen
        Document doc;
        try {
          doc = mIndexReader.document(docIdx);
        } catch (Throwable thr) {
          throw new RegainException("Getting document #" + docIdx + " from index failed.", thr);
        }

        // URL und last-modified holen
        String url = doc.get("url");
        String lastModified = doc.get("last-modified");

        // Prüfen, ob die URL gelöscht werden soll
        boolean shouldBeDeleted;
        if (url != null) {
          // Prüfen, ob dieser Eintrag zum Löschen vorgesehen ist
          if (isMarkedForDeletion(doc)) {
            shouldBeDeleted = true;
          } // Check whether all other documents should NOT be deleted
          else if ((urlChecker == null)) {
            shouldBeDeleted = false;
          } // Check whether this document should be kept in the index
          else if (urlChecker.shouldBeKeptInIndex(url)) {
            shouldBeDeleted = false;
          } // Prüfen, ob die URL zu einem zu-verschonen-Präfix passt
          else {
            shouldBeDeleted = true;
            for (int i = 0; i < preserveUrlMatcherArr.length; i++) {
              if (preserveUrlMatcherArr[i].matches(url)) {
                shouldBeDeleted = false;
                break;
              }
            }
          }

          if (shouldBeDeleted) {
            try {
              mLog.info("Deleting from index: " + url + " from " + lastModified);
              mIndexReader.deleteDocument(docIdx);
            } catch (IOException exc) {
              throw new RegainException("Deleting document #" + docIdx + " from index failed: " + url + " from " + lastModified, exc);
            }
          }
        }
      }
    }
View Full Code Here

   * @throws RegainException If preparing the breakpoint failed.
   */
  private void prepareBreakpoint() throws RegainException {
    // Testen, ob noch Eintr�ge für die L�schung vorgesehen sind
    if (mUrlsToDeleteHash != null) {
      throw new RegainException("There are still documents marked for deletion." + " The method removeObsoleteEntires(...) has to be called first.");
    }

    // Switch to ALL_CLOSED_MODE
    setIndexMode(ALL_CLOSED_MODE);

    // Close the error log of the index
    if (mErrorLogStream != null) {
      mErrorLogWriter.close();
      try {
        mErrorLogStream.close();
      } catch (IOException exc) {
        throw new RegainException("Closing error log file failed", exc);
      }

      mErrorLogWriter = null;
      mErrorLogStream = null;
    }
View Full Code Here

        String value = XmlToolkit.getAttribute(nodeArr[i], "value");
        boolean toLowerCase = XmlToolkit.getAttributeAsBoolean(nodeArr[i],
                "toLowerCase", true);
        int urlRegexGroup = XmlToolkit.getAttributeAsInt(nodeArr[i], "regexGroup", -1);
        if ((value == null) && (urlRegexGroup == -1)) {
          throw new RegainException("The node 'auxiliaryField' must have " +
                "either the attribute 'value' or the attribute 'regexGroup'");
        }

        boolean store    = XmlToolkit.getAttributeAsBoolean(nodeArr[i], "store", true);
        boolean index    = XmlToolkit.getAttributeAsBoolean(nodeArr[i], "index", true);
View Full Code Here

      // Delete the old breakpoint if it exists
      deleteOldIndex(mBreakpointIndexDir);

      // Rename the temp directory and let it become the new breakpoint
      if (!tempDir.renameTo(mBreakpointIndexDir)) {
        throw new RegainException("Renaming temporary copy directory failed: " +
                tempDir.getAbsolutePath());
      }

      // Stop measuring
      long breakpointSize = RegainToolkit.getDirectorySize(mBreakpointIndexDir);
View Full Code Here

          int flags = caseSensitive ? RE.MATCH_NORMAL : RE.MATCH_CASEINDEPENDENT;
          try {
              return new RE(regex, flags);
          } catch (RESyntaxException exc) {
              throw new RegainException("Regex of node '" + node.getNodeName()
                  + "' has a wrong syntax: '" + regex + "'", exc);
          }
      } else {
          // This is the old style -> Use the text as regex
          String regex = XmlToolkit.getText(node, true);
          try {
              return new RE(regex, RE.MATCH_CASEINDEPENDENT);
          } catch (RESyntaxException exc) {
              throw new RegainException("Regex of node '" + node.getNodeName()
                  + "' has a wrong syntax: '" + regex + "'", exc);
          }
      }
  }
View Full Code Here

    // Index optimieren
    try {
      setIndexMode(WRITING_MODE);
      mIndexWriter.optimize();
    } catch (IOException exc) {
      throw new RegainException("Finishing IndexWriter failed", exc);
    }

    // Prefetch destinct field values
    String[] prefetchFields = mConfig.getValuePrefetchFields();
    if (prefetchFields != null && prefetchFields.length != 0) {
      String msg = "Prefetching destinct field values for: ";
      for (int i = 0; i < prefetchFields.length; i++) {
        msg += (i != 0 ? ", " : "") + prefetchFields[i];
      }
      mLog.info(msg);

      setIndexMode(READING_MODE);
      RegainToolkit.readFieldValues(mIndexReader, prefetchFields, mTempIndexDir);
    }

    // Prepare the final 'breakpoint'
    // NOTE: This will set the ALL_CLOSED_MODE
    prepareBreakpoint();

    // Ressourcen der DocumentFactory freigeben
    mDocumentFactory.close();

    // Write all terms in the index into a file
    if (mAnalysisDir != null) {
      File termFile = new File(mAnalysisDir.getAbsolutePath() + File.separator + "AllTerms.txt");
      writeTermFile(mTempIndexDir, termFile);
    }

    // Verzeichnis bestimmen, in das der Index kommen soll
    File targetDir;
    if (putIntoQuarantine) {
      targetDir = mQuarantineIndexDir;
    } else {
      targetDir = mNewIndexDir;
    }

    // If there is already the target directory -> delete it
    deleteOldIndex(targetDir);

    // Let the new index become the working index
    // Workaround: Siehe Javadoc von RENAME_TIMEOUT
    long deadline = System.currentTimeMillis() + RENAME_TIMEOUT;
    boolean renameSucceed = false;
    while ((!renameSucceed) && (System.currentTimeMillis() < deadline)) {
      renameSucceed = mTempIndexDir.renameTo(targetDir);
      try {
        Thread.sleep(100);
      } catch (Exception exc) {
      }
    }

    if (renameSucceed) {
      // Delete the last breakpoint if there should be one
      deleteOldIndex(mBreakpointIndexDir);
    } else {
      throw new RegainException("Renaming " + mTempIndexDir + " to " + targetDir + " failed after " + (RENAME_TIMEOUT / 1000) + " seconds!");
    }
  }
View Full Code Here

      for (int paramIdx = 0; paramIdx < paramArr.length; paramIdx++) {
        String paramName = XmlToolkit.getAttribute(paramArr[paramIdx], "name", true);
        String paramValue = XmlToolkit.getText(paramArr[paramIdx], true);

        if (paramMap.containsKey(paramName)) {
          throw new RegainException("Preparator configuration of '" + className
              + "' has multiple '" + paramName + "' parameters in section '"
              + sectionName + "'");
        }

        paramMap.put(paramName, paramValue);
View Full Code Here

      // case is very unlikely but it may happen once in 100.000 years...
      File secureDir = new File(oldIndexDir.getAbsolutePath() + "_del");
      if (oldIndexDir.renameTo(secureDir)) {
        RegainToolkit.deleteDirectory(secureDir);
      } else {
        throw new RegainException("Deleting old index failed: " +
                oldIndexDir.getAbsolutePath());
      }
    }
  }
View Full Code Here

  public SearchConfig createSearchConfig(PageRequest request)
    throws RegainException
  {
    String configFileName = request.getInitParameter("searchConfigFile");
    if (configFileName == null) {
      throw new RegainException("The init parameter 'searchConfigFile' was not specified.");
    }

    File configFile = new File(request.getWorkingDir(), configFileName);
    try {
      return new XmlSearchConfig(configFile);
    }
    catch (RegainException exc) {
      throw new RegainException("Loading configuration file failed: "
          + configFile.getAbsolutePath(), exc);
    }
  }
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.