Add search Capability?

  • dvltech

    dvltech - 2007-12-06

    I am planning to extend the code and introduce search capability.
    Can anyone throw light on my problem?

    1. In, Created a new method (Copy of existing with one parameter)
      public Message[] getMessages(String searchTermValue) throws MailboxFolderException,
              MessageRetrieveException {

        Message[] messages = null;

        // Folder updaten und oeffnen

        try {
            if (searchTermValue!=null && searchTermValue.trim().length()>0) {
            SearchTerm searchTerm = new OrTerm(
                       new SubjectTerm(searchTermValue),
                       new BodyTerm(searchTermValue));
            // Create a new from source term
            FromStringTerm fromStringTerm = new FromStringTerm(searchTermValue);
            // Combine from and search term
            searchTerm = new OrTerm(searchTerm, fromStringTerm);
            // Create a new date term (today's)
            ReceivedDateTerm receivedDateTerm =
              new ReceivedDateTerm(ComparisonTerm.EQ, new Date());
            // Combine date term
            searchTerm = new OrTerm(searchTerm,receivedDateTerm);
            // Induce search for messages
            messages =;
            } else {
                messages =  this.folder.getMessages();
        catch(MessagingException me) {

          throw(new MessageRetrieveException(("Konnte Nachrichten aus Folder \"" +
                  this.folder.getName() + "\" nicht beziehen."), me));


    So, Lets say basically i have got the search string from jsp to the controller and so on to this method.

    My problem is that the search works fine and returns exactly the message i expected.But the line
                        messages[ii] =

    is throwing ArrayStoreException. This happens only with search??

    • Stephan Sann

      Stephan Sann - 2007-12-07

      First of all a Stacktrace would be very helpful.

      I hope you get straight what you are doing. To perform the search over the messages, all messages of the folder have to be transfered from the mailbox-server to the yawebmail-server. This might be okay if there are only a few small messages, or both servers are on the same machine, but in most cases this isn't true and it will cost a lot of time and traffic...

      BTW: Do you know the constructor

      OrTerm(SearchTerm[] t)
                Constructor that takes an array of SearchTerms.


      Best regards

    • dvltech

      dvltech - 2007-12-08

      Thanks stephan. Yes, I did try with that constructor.. But as i said, The outcome of this method returns expected messages that fulfilled search.
      But actually its this line that is throwing the exception.

      messages[ii] =

      The stack is basically an ArrayStoreException on the above line.
      For some reason, the message[] returned from search is causing the problem. When i actually removed that search and instead applied after retrieving the messages, it works.

      My question is this seems little performance overhead. Like, first get all messages using folder.getMessages() then loop through the messages and apply the search on each message in the loop...

      Could you suggest any other alternative to cache the messages and apply search on it?? Planning to introduce Lucene.

      • Stephan Sann

        Stephan Sann - 2007-12-09

        You schould find out what causes the ArrayStoreException.

        Get yourself the latest version from Subversion, there's a remote-debug launch-configuration in it. Fire up your Servlet-container in debug-mode, set some breakpoints and launch the remote-debugging.

        Best regards


Log in to post a comment.