KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > searcher > Hits


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.searcher;
5
6 import java.io.DataInput JavaDoc;
7 import java.io.DataOutput JavaDoc;
8 import java.io.IOException JavaDoc;
9
10 import net.nutch.io.Writable;
11
12 import java.util.logging.Logger JavaDoc;
13 import net.nutch.util.LogFormatter;
14
15 /** A set of hits matching a query. */
16 public final class Hits implements Writable {
17   private static final Logger JavaDoc LOG =
18     LogFormatter.getLogger("net.nutch.searcher.Hits");
19
20   private long total;
21   private boolean totalIsExact = true;
22   private Hit[] top;
23
24   public Hits() {}
25
26   public Hits(long total, Hit[] top) {
27     this.total = total;
28     this.top = top;
29   }
30
31   /** Returns the total number of hits for this query. This may be an estimate
32    * when (@link totalIsExact()} is false. */

33   public long getTotal() { return total; }
34
35   /** True if {@link getTotal()} gives the exact number of hits, or false if
36    * it is only an estimate of the total number of hits. */

37   public boolean totalIsExact() { return totalIsExact; }
38
39   /** Set {@link totalIsExact()}. */
40   public void setTotalIsExact(boolean isExact) { totalIsExact = isExact; }
41
42   /** Returns the number of hits included in this current listing. */
43   public int getLength() { return top.length; }
44
45   /** Returns the <code>i</code><sup>th</sup> hit in this list. */
46   public Hit getHit(int i) { return top[i]; }
47
48   /** Returns a subset of the hit objects. */
49   public Hit[] getHits(int start, int length) {
50     Hit[] results = new Hit[length];
51     for (int i = 0; i < length; i++) {
52       results[i] = top[start+i];
53     }
54     return results;
55   }
56
57
58   public void write(DataOutput JavaDoc out) throws IOException JavaDoc {
59     out.writeLong(total);
60     out.writeInt(top.length);
61     for (int i = 0; i < top.length; i++) {
62       top[i].write(out);
63     }
64   }
65
66   public void readFields(DataInput JavaDoc in) throws IOException JavaDoc {
67     total = in.readLong();
68     top = new Hit[in.readInt()];
69     for (int i = 0; i < top.length; i++) {
70       top[i] = new Hit();
71       top[i].readFields(in);
72     }
73   }
74
75 }
76
Popular Tags