View Javadoc

1   package com.atlassian.sal.api.search;
2   
3   import com.atlassian.sal.api.message.Message;
4   
5   import java.util.List;
6   import java.util.ArrayList;
7   import java.util.Collections;
8   
9   /**
10   * Provides searchresults for a query.  If there were any errors, check the list of errors.  The searchresult will also
11   * contain the total searchtime (in milliseconds).
12   *
13   * @since 2.0
14   */
15  public class SearchResults
16  {
17      private final List<Message> errors = new ArrayList<Message>();
18      private final List<SearchMatch> matches = new ArrayList<SearchMatch>();
19      private final long searchTime;
20      private final int totalResults;
21  
22      /**
23       * Constructs search results that contained errors
24       *
25       * @param errors The error list
26       */
27      public SearchResults(List<Message> errors)
28      {
29          this.errors
30                  .addAll(errors);
31          searchTime = 0L;
32          totalResults = 0;
33      }
34  
35      /**
36       * Constructs search results with successful matches
37       *
38       * @param matches      The list of matches
39       * @param totalResults The total number of available results
40       * @param searchTime   The time the search took in milliseconds
41       */
42      public SearchResults(List<SearchMatch> matches, int totalResults, long searchTime)
43      {
44          this.totalResults = totalResults;
45          this.matches
46                  .addAll(matches);
47          this.searchTime = searchTime;
48      }
49  
50      /**
51       * @return search errors
52       */
53      public List<Message> getErrors()
54      {
55          return Collections.unmodifiableList(errors);
56      }
57  
58      /**
59       * @return the matches
60       */
61      public List<SearchMatch> getMatches()
62      {
63          return Collections.unmodifiableList(matches);
64      }
65  
66      /**
67       * @return the time the search took in milliseconds
68       */
69      public long getSearchTime()
70      {
71          return searchTime;
72      }
73  
74      /**
75       * @return the total results available
76       */
77      public int getTotalResults()
78      {
79          return totalResults;
80      }
81  }