Package net.sf.regain

Examples of net.sf.regain.RegainException


          // All indexes has to be build with the same analyzer
          mAnalyzer = indexSearcherManagers[0].getAnalyzer();
          mIndexName = "multiindex";

        } catch (IOException ex) {
          throw new RegainException("Couldn't instantiate MultiSearcher.", ex);
        }

      }

      mIndexConfig = indexConfigs[0];
      mQuery = null;
      if (queryText != null && queryText.length() > 0) {
        // start the creation of the lucene query object

        try {
          mQuery = new BooleanQuery();

          for (int k = 0; k < indexConfigs.length; k++) {

            String[] searchFieldArr = indexConfigs[k].getSearchFieldList();
            for (int i = 0; i < searchFieldArr.length; i++) {

              QueryParser parser = new QueryParser(Version.LUCENE_30, searchFieldArr[i], mAnalyzer);
              parser.setDefaultOperator(QueryParser.AND_OPERATOR);
              parser.setAllowLeadingWildcard(true);
              Query fieldQuery = parser.parse(queryText);

              // Add as OR
              mQuery.add(fieldQuery, Occur.SHOULD);
            }
            //System.out.println("Query: '" + queryText + "' -> '" + mQuery.toString() + "'");

          }
        } catch (ParseException exc) {
          throw new RegainException("Error while parsing search pattern '" + mQueryText +
                  "': " + exc.getMessage(), exc);
        }

        // Check whether access control is used
        if (allGroups != null && allGroups.length > 0) {
          // Create a query that matches any group
          BooleanQuery groupQuery = new BooleanQuery();
          for (int i = 0; i < allGroups.length; i++) {
            // Add as OR
            groupQuery.add(new TermQuery(new Term("groups", allGroups[i])), Occur.SHOULD);
          }

          // Create a main query that contains the group query and the search query
          // combined with AND
          BooleanQuery mainQuery = new BooleanQuery();
          mainQuery.add(mQuery, Occur.MUST);
          mainQuery.add(groupQuery, Occur.MUST);

          // Set the main query as query to use
          mQuery = mainQuery;
        }
      }

      // Add the mimetype field search
      if (mimeTypeFieldText != null) {
        BooleanQuery mimetypeFieldQuery = new BooleanQuery();
        mimetypeFieldQuery.add(new TermQuery(new Term("mimetype",
                mimeTypeFieldText.substring(9).replace("\"", ""))),
                Occur.SHOULD);
        BooleanQuery mainQuery = new BooleanQuery();
        if (mQuery != null) {
          mainQuery.add(mQuery, Occur.MUST);
        }
        mainQuery.add(mimetypeFieldQuery, Occur.MUST);

        // Set the main query as query to use
        mQuery = mainQuery;
      }

      if (mQuery != null) {
        //System.out.println("Query: '" + mQueryText + "' -> '" + mQuery.toString() + "'");

        try {
          SortingOption sortingOption = new SortingOption(request.getParameter("order"));
          Sort sort = new Sort(sortingOption.getSortField());
          //System.out.println(sortingOption.toString());

          topDocsCollector = TopFieldCollector.create(sort, 10000, true, true, true, false);

          mIndexSearcher.search(mQuery, topDocsCollector);
          hitScoreDocs = topDocsCollector.topDocs().scoreDocs;

        } catch (IOException exc) {
          throw new RegainException("Searching query failed", exc);
        }

      }

      String openInNewWindowRegex = indexConfigs[0].getOpenInNewWindowRegex();
      if (openInNewWindowRegex != null) {
        try {
          mOpenInNewWindowRegex = new RE(openInNewWindowRegex);
        } catch (RESyntaxException exc) {
          throw new RegainException("Syntax error in openInNewWindowRegex: '" + openInNewWindowRegex + "'", exc);
        }
      }

    } else {
      // no index given
View Full Code Here


      // at this position
      if (currDoc.getFields().isEmpty()) {
        lazyHitList.set(index, mIndexSearcher.doc(hitScoreDocs[index].doc));
      }
    } catch (Exception ex) {
      throw new RegainException("Error while accessing index", ex);
    }
    return (Document) lazyHitList.get(index);

  }
View Full Code Here

  @Override
  public float getHitScore(int index) throws RegainException {
    try {
      return hitScoreDocs[index].score;
    } catch (Exception exc) {
      throw new RegainException("Error while getting score of search hit #" + index, exc);
    }
  }
View Full Code Here

          // write back the transformed document
          setHitDocument(index, document);
        }
      }
    } catch (DataFormatException dataFormatException) {
      throw new RegainException("Error while searching pattern: " + mQueryText, dataFormatException);
    }

  }
View Full Code Here

      setHitDocument(index, document);

      //System.out.println("The document: " + hitDocs.get(index).toString());

    } catch (org.apache.lucene.index.CorruptIndexException exCorr) {
      throw new RegainException("Error while searching pattern: " + mQueryText, exCorr);

    } catch (org.apache.lucene.search.highlight.InvalidTokenOffsetsException exToken) {
      throw new RegainException("Error while searching pattern: " + mQueryText, exToken);

    } catch (IOException exIO) {
      throw new RegainException("Error while searching pattern: " + mQueryText, exIO);

    } catch (DataFormatException ex) {
      throw new RegainException("Error while searching pattern: " + mQueryText, ex);
    }

  }
View Full Code Here

      }

      String regKey = "HKEY_LOCAL_MACHINE\\Software\\Classes";
      String[] classChildren = getRegistryKeyChildren(regKey);
      if (classChildren == null) {
        throw new RegainException("Reading windows registry failed");
      }

      ArrayList list = new ArrayList();
      for (int i = 0; i < classChildren.length; i++) {
        if (classChildren[i].startsWith(".")) {
View Full Code Here

  // overridden
  public void prepare(RawDocument rawDocument) throws RegainException {
    String url = rawDocument.getUrl();
    int dotPos = url.lastIndexOf('.');
    if (dotPos == -1) {
      throw new RegainException("Can't detect file extension: " + url);
    }
    String extension = url.substring(dotPos);

    IfilterWrapper ifilter = getIfilterWrapperForExtension(extension);
View Full Code Here

      //           default value of the sub key CLSID contains the CLSID associated
      //           with that file extension.
      regKey = "HKEY_LOCAL_MACHINE\\Software\\Classes\\" + extension;
      String extensionClass = getRegistryKeyValue(regKey);
      if (extensionClass == null) {
        throw new RegainException("Unknown file extension: " + extension);
      }
     
      regKey = "HKEY_LOCAL_MACHINE\\Software\\Classes\\" + extensionClass + "\\CLSID";
      String extensionClsid = getRegistryKeyValue(regKey);
      if (extensionClsid == null) {
        throw new RegainException("CLSID of extension class " + extensionClass
            + " not found");
      }
 
      // # Step 3: Next search for that CLSID under HKLM\Software\Classes\CLSID. The
      //           default value of the sub key called PersistentHandler gives you
      //           the GUID of the PersistentHandler.
      regKey = "HKEY_LOCAL_MACHINE\\Software\\Classes\\CLSID\\" + extensionClsid
        + "\\PersistentHandler";
      persistentHandlerGuid = getRegistryKeyValue(regKey);
      if (persistentHandlerGuid == null) {
        throw new RegainException("PersistentHandler of extension class "
            + extensionClass + " not found");
      }
    }
 
    // # Step 4: Search for that GUID under HKLM\Software\Classes\CLSID. Under it
    //           you will find a sub key PersistentAddinsRegistered which always
    //           has a sub key {89BCB740-6119-101A-BCB7-00DD010655AF} (this is the
    //           GUID of the IFilter interface). The default value of this key has
    //           the IFilter PersistentHandler GUID.
    regKey = "HKEY_LOCAL_MACHINE\\Software\\Classes\\CLSID\\"
      + persistentHandlerGuid
      + "\\PersistentAddinsRegistered\\{89BCB740-6119-101A-BCB7-00DD010655AF}";
    String ifilterGuid = getRegistryKeyValue(regKey);
    if (ifilterGuid == null) {
      throw new RegainException("GUIF of PersistentHandler not found for "
            + "extension " + extension);
    }
 
    // Strip the "{" and "}"
    ifilterGuid = "clsid:" + ifilterGuid.substring(1, ifilterGuid.length() - 1);
View Full Code Here

    if (mValueRegex == null) {
      try {
        mValueRegex = new RE("^\\s+(.*)\\s+REG_SZ\\s+(.*)$");
      } catch (RESyntaxException exc) {
        throw new RegainException("Creating registry value regex failed", exc);
      }
    }

    synchronized (mValueRegex) {
      for (int i = valueStartIdx; i < output.length; i++) {
View Full Code Here

      } else if (metaDataMap.containsKey("PID_TITLE")) {
        setTitle(metaDataMap.get("PID_TITLE"));
      }

    } catch (InvalidFormatException invalidFormatEx) {
      throw new RegainException("Invalid format while reading MS* (OpenXML) document. URL: "
              + rawDocument.getUrl(), invalidFormatEx);

    } catch (Exception e) {
      throw new RegainException("Reading MS* (OpenXML) document failed : " + rawDocument.getUrl(), e);

    } finally {
      if (stream != null) {
        try {
          stream.close();
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.