Examples of MessageSearchException


Examples of com.stimulus.archiva.exception.MessageSearchException

    }

    public void indexMessage(EmailID emailID) throws MessageSearchException {
        if (emailID==null)
              throw new MessageSearchException("assertion failure: null emailId",logger);
        indexQueue.addFirst(emailID);
    }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

    }

    public String createIndexDir(Volume volume) throws MessageSearchException {

        if (volume==null)
              throw new MessageSearchException("assertion failure: null volume",logger);

        File indexDir = new File(volume.getIndexPath());
          if (!indexDir.exists()) {
         logger.info("index directory does not exist. will proceed with creation {location='" + volume.getIndexPath() + "'}");
         boolean success = indexDir.mkdir();
         if (!success)
             throw new MessageSearchException("failed to create index directory {location='" + volume.getIndexPath() + "'}",logger);
         logger.info("index directory successfully created {location='" + volume.getIndexPath() + "'}");
         }
          return volume.getPath();
    }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

          return volume.getPath();
    }

    public Search searchMessage(Search search) throws MessageSearchException {
        if (search==null)
             throw new MessageSearchException("assertion failure: null search",logger);
       
        if (search.getUserRole()==null || search.getUserName()==null)
            throw new MessageSearchException("assertion failure: null userRole or userName",logger);
         
          String queryStr = search.getSearchQuery();
         
          Date sentAfter = search.getSentAfter();
          Date sentBefore = search.getSentBefore();
          if (sentAfter==null)
              sentAfter = new Date(0);
          if (sentBefore==null)
              sentBefore = new Date();
        if (queryStr.trim().compareTo("")==0)
            queryStr += " sentdate:[d"+format.format(sentAfter) + " TO d" + format.format(sentBefore)+"]"
        logger.debug("search {searchquery='"+queryStr+"'}");
        ParallelMultiSearcher searcher = null;
        ArchivaAnalyzer analyzer = new ArchivaAnalyzer();

        Query query = null;
        QueryFilter filter = null;
        Query filterQuery = null;

      try {
          query = QueryParser.parse(queryStr,"body",analyzer);

          //query = MultiFieldQueryParser.parse(queryStr,fields, analyzer);
        //query = QueryParser.parse(queryStr,"body", analyzer);
          if (search.getUserRole().compareToIgnoreCase("user")==0) {
            filterQuery = QueryParser.parse("to:"+search.getUserName()+" from:"+search.getUserName(),"to",analyzer);
            filter = new QueryFilter(filterQuery);
        }
      } catch (ParseException pe)
      {
        throw new MessageSearchException("failed to parse search query {searchquery='"+search.getSearchQuery()+"'}",pe,logger);
      }

      List volumes = Config.getConfig().getVolumes().getVolumes();
      ArrayList searchers = new ArrayList();
      Iterator vl = volumes.iterator();
     
      while (vl.hasNext()) {
          Volume volume = (Volume)vl.next();
          if (volume.getModified()!=null && sentAfter.compareTo(volume.getModified())>0)
                  continue;
          if (volume.getCreated()!=null && sentBefore.compareTo(volume.getCreated())<0)
                  continue;
          try {
              if (volume.getStatusID()==Volume.ACTIVE || volume.getStatusID()==Volume.CLOSED) {
                  Searcher volsearcher = new IndexSearcher(volume.getIndexPath());
                  searchers.add(volsearcher);
              }
          } catch (IOException io) {
              logger.error("failed to open index for search {"+volume+"}.");
          }
      }

      /*Searcher[] searchers = new Searcher[volumes.size()];

      for (int j=0;j<volumes.size();j++) {
          Volume volume = (Volume)volumes.get(j);
          try {
          searchers[j] = new IndexSearcher(volume.getIndexPath());
          } catch (IOException io) {
          throw new MessageSearchException("failed to open index for searching {"+volume+"}",logger);
          }
      }*/
      Searcher[] searcherarraytype = new Searcher[searchers.size()];
      Searcher[] allsearchers = (Searcher[])(searchers.toArray(searcherarraytype));

      logger.debug("searching for email {query="+queryStr+"}");
       try {
           searcher = new ParallelMultiSearcher(allsearchers);
      } catch (IOException io) {
          throw new MessageSearchException("failed to open/create one or more index searchers",logger);
      }

      Hits hits = null;
      try {
            Sort sort;
            String sortField = search.getSortField();
            boolean sortOrder = search.getSortOrder();
            if (sortField.compareToIgnoreCase("score")==0)
                sort = new Sort(new SortField[]{SortField.FIELD_SCORE,new SortField("sentdate",false)});
            else if (sortField.compareToIgnoreCase("sentdate")==0) {
                sort = new Sort(new SortField(sortField,SortField.STRING,sortOrder));
            } else
                sort = new Sort(new SortField[]{new SortField(sortField,SortField.STRING,sortOrder),SortField.FIELD_SCORE,new SortField("sentdate",false)});
          //logger.debug("executing search query {query='"+query+"',filter='"+filter+"',sort='"+sort+"'}");

            hits = searcher.search(query,filter,sort);
          logger.info("search executed successfully {query='"+query.toString()+"', nohits='"+hits.length()+"'}");
       } catch (IOException io)
       {
        throw new MessageSearchException("failed to execute search query {searchquery='"+search.getSearchQuery()+"}",io,logger);
       }

        String messageUidDebugOutput = "search results returned following unique message ID's:";

      long norecords = hits.length() > MAX_SEARCH_RESULTS ? MAX_SEARCH_RESULTS : hits.length();

      for (int start = 0; start < norecords; start++)
      {
          Document doc = null;
        try {

          doc = hits.doc(start);
          float score = hits.score(start);
          search.addMessage(new LuceneEmailID(start,hits),score);
          messageUidDebugOutput+=doc.get("uid")+",";
        } catch (IOException io)
        {
          throw new MessageSearchException("failed to retrieve indexed value from search query {searchquery='"+search.getSearchQuery()+"'}",io,logger);
        }
      }
      logger.debug(messageUidDebugOutput);
      try {
        searcher.close();
      } catch (IOException io) {
        throw new MessageSearchException("failed to close search indexes (opened for read)",io,logger);
      }

      return search;
    }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

    }

    // deliberately non recursive (so we avoid situations where the whole h/d is deleted)
    public void deleteIndex(Volume volume) throws MessageSearchException {
        if (volume == null)
              throw new MessageSearchException("assertion failure: null volume",logger);

        logger.debug("delete index {indexpath='"+volume.getIndexPath()+"'}");
        File indexDir = new File(volume.getIndexPath());
        if (!indexDir.exists()) return;
        if (indexDir.isDirectory()) {
              String[] children = indexDir.list();
              for (int i=0; i<children.length; i++) {
                  String filepath = volume.getIndexPath()+File.separatorChar+children[i];
                  logger.debug("deleting file {path='" + filepath +"'}");
                  boolean success = new File(filepath).delete();
                  if (!success)
                        throw new MessageSearchException("failed to delete file in existing index {filepath='"+filepath+"'}",logger);
                     else
                         logger.debug("deleted file successfully {filepath='" + filepath +"'}");
              }
        }
    }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

          }


          public void openIndex(Volume volume) throws MessageSearchException {
              if (volume == null)
                throw new MessageSearchException("assertion failure: null volume",logger);
              logger.info("opening index for write {"+volume+"}");
              createIndexDir(volume);
           File indexFile = new File(volume.getIndexPath()+File.separatorChar+"segments"); // create index if segments doesn't exist
            boolean createIndex = !indexFile.exists();
            if (createIndex)
              logger.debug("index does not exist. creating new index {segments='"+indexFile.getPath()+"'}");
           logger.debug("opening search index for write {indexpath='"+volume.getIndexPath()+"', createIndex='"+createIndex+"'}");
           try {
             writer = new IndexWriter(volume.getIndexPath(), analyzer, createIndex);
             writer.mergeFactor = 2;
             writer.maxMergeDocs = 7000000;
             writer.minMergeDocs = 5;
             } catch (IOException io)
           {
                 throw new MessageSearchException("failed to open/create index writer {location='"+volume.getIndexPath()+"'}",io,logger);
           }
          }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

           }
          }

          public void index(Email message) throws MessageSearchException {
              if (message == null)
                throw new MessageSearchException("assertion failure: null message",logger);

            logger.debug("indexing message {"+message+"}");
            Document doc = new Document();

          try {
             writeMessageToDocument(message,doc);
              writer.addDocument(doc);
              logger.debug("message indexed successfully {"+message+"}");
          } catch (MessagingException me)
          {
             throw new MessageSearchException("failed to decode message during indexing",me,logger);
          } catch (IOException me) {
              throw new MessageSearchException("failed to index message {"+message+"}",me,logger);
          } catch (ExtractionException ee)
          {
             throw new MessageSearchException("failed to decode attachments in message {"+message+"}",ee,logger);
          } catch (Exception e) {
              throw new MessageSearchException("failed to index message",e,logger);
          }
          }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

   
    }

    public void searchMessage(Search search) throws MessageSearchException {
      if (search==null)
             throw new MessageSearchException("assertion failure: null search",logger);
        if (search.getUserRole()==null || search.getUserName()==null)
            throw new MessageSearchException("assertion failure: null userRole or userName",logger);
        String queryStr = search.getSearchQuery();
        logger.debug("search {searchquery='"+queryStr+"'}");
        search.searchMessage();
    }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

        searchQuery += and(searchQuery,dateQuery);
        try {
          query = queryParser.parse(searchQuery);
          logger.debug("successfully parsed search query {query='"+searchQuery+"'}");
        } catch (Exception e) {
          throw new MessageSearchException("failed to parse search query {query='"+searchQuery+"'}",e,logger);
        }
        return query;
   
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

          Query query = filterQueryParser.parse(filterstr);
          queryFilter = new QueryWrapperFilter(query);
          logger.debug("successfully parsed filter query {query='"+filterstr+"'}");
      } catch (Exception pe)
      {
        throw new MessageSearchException("failed to parse search query {searchquery='"+getSearchQuery()+"'}",pe,logger);
      }
      return queryFilter;
    }
View Full Code Here

Examples of com.stimulus.archiva.exception.MessageSearchException

              logger.error("failed to open index for search {"+volume+"}.");
          }
      }
     
      if (!searcherPresent)
        throw new MessageSearchException("no volumes are ready to search",logger);

      Searcher[] searcherarraytype = new Searcher[searchers.size()];
      Searcher[] allsearchers = (Searcher[])(searchers.toArray(searcherarraytype));

      Searcher searcher;
       try {
           searcher = new ParallelMultiSearcher(allsearchers);
      } catch (IOException io) {
          throw new MessageSearchException("failed to open/create one or more index searchers",logger);
      }
      return searcher;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.