KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > search > JahiaSearchResult


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 // DJ 03.01.2001
14
// NK 06.05.2002 Added BitSet and accessors addHit(), results(), getHitCount(), bits()
15
//
16
//
17
package org.jahia.data.search;
18
19 import java.util.BitSet JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Vector JavaDoc;
24 import org.jahia.services.search.JahiaSearchResultHandler;
25
26 /**
27  * An instance of this class is returned by the SearchEngine (and the corresponding search
28  * service). It contains a vector of JahiaSearchHit and a hit counter.
29  *
30  * @see org.jahia.engines.search.Search_Engine
31  * @author DJ
32  * @author NK
33  */

34 public class JahiaSearchResult
35 {
36
37     /**
38      * Vector of JahiaSearchHitInterface
39      */

40     private Vector JavaDoc results = new Vector JavaDoc(); // vector of JahiaSearchHit
41

42     /**
43      * The BitSet of matching ids, the id could by page id, container id depending
44      * of the search level
45      */

46     private BitSet JavaDoc bits = new BitSet JavaDoc(); // vector of matching ids as bits
47

48     /**
49      * The collection of raw parsedObject instance
50      *
51      */

52     private Collection JavaDoc parsedObjects; // the collection of row ParsedObjects instance
53

54     /**
55      * The map of hits grouped by page key=pageID, value = vector of JahiaSearchHit
56      */

57     private Map JavaDoc hitsByPage = new HashMap JavaDoc();
58
59     private JahiaSearchResultHandler searchResultHandler;
60
61     /**
62      * number of hits
63      */

64     private int hitcount ;
65
66     public JahiaSearchResult(JahiaSearchResultHandler searchResultHandler){
67         this.searchResultHandler = searchResultHandler;
68     }
69
70     public JahiaSearchResult(JahiaSearchResultHandler searchResultHandler,
71                              Collection JavaDoc parsedObjects){
72         this.searchResultHandler = searchResultHandler;
73         this.parsedObjects = parsedObjects;
74     }
75
76     //--------------------------------------------------------------------------
77
/**
78      * Add a hit and use the hit's id to set the corresponding bit in the BitSet to true.
79      * Increment the hitcount counter.
80      *
81      * @param JahiaSearchHit a hit
82      */

83     public void addHit(JahiaSearchHit hit ){
84         if ( hit == null )
85             return;
86
87         results.add(hit);
88         bits.set(((JahiaSearchHit)hit).id);
89         hitcount++;
90     }
91
92     //--------------------------------------------------------------------------
93
/**
94      * Returns the results.
95      *
96      * @return Vector results, the results.
97      */

98     public Vector JavaDoc results(){
99         if ( results == null ){
100             results = new Vector JavaDoc();
101         }
102         return results;
103     }
104
105     //--------------------------------------------------------------------------
106
/**
107      * Returns the BitSet of matching ids.
108      *
109      * @return BitSet the bit set.
110      */

111     public BitSet JavaDoc bits(){
112         return bits;
113     }
114
115     //--------------------------------------------------------------------------
116
/**
117      * Returns the collection of raw ParsedObject.
118      *
119      * @return Vector results, the results.
120      */

121     public Collection JavaDoc parsedObjects(){
122         if ( parsedObjects == null ){
123             this.parsedObjects = new Vector JavaDoc();
124         }
125         return this.parsedObjects;
126     }
127
128     //--------------------------------------------------------------------------
129
/**
130      *
131      * @param parsedObjects Collection
132      */

133     public void setParsedObjects(Collection JavaDoc parsedObjects){
134         this.parsedObjects = parsedObjects;
135     }
136
137     //--------------------------------------------------------------------------
138
/**
139      * Returns the number of hits
140      *
141      * @return int hitcount, the umber of hits.
142      */

143     public int getHitCount(){
144         return hitcount;
145     }
146
147     //--------------------------------------------------------------------------
148
/**
149      * Returns the hits by pageID
150      *
151      * @return int hitcount, the umber of hits.
152      */

153     public Map JavaDoc getHitsByPage(){
154         if ( this.hitsByPage == null ){
155             this.hitsByPage = this.searchResultHandler.groupResultByPage(this);
156             if ( this.hitsByPage == null ){
157                 this.hitsByPage = new HashMap JavaDoc();
158             }
159         }
160         return this.hitsByPage;
161     }
162
163     //--------------------------------------------------------------------------
164
//
165
// Deprecated
166
//
167
//
168

169     /**
170      * Vector of JahiaSearchHit
171      * Deprecated , use results instead.
172      *
173      * @Deprecated
174      */

175     public Vector JavaDoc pages = new Vector JavaDoc(); // vector of JahiaSearchHit
176

177     /**
178      * Deprecated , use hitcount instead.
179      * number of hits
180      */

181     public int pagecount = 0;
182 }
183
Popular Tags