mirror of https://github.com/apache/lucene.git
Reformatted. Do we have any style guides special to Lucene different than Jakarta standards?
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150022 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b2bd68e84
commit
0b53524a11
|
@ -83,8 +83,9 @@ public final class Hits {
|
|||
// Tries to add new documents to hitDocs.
|
||||
// Ensures that the hit numbered <code>min</code> has been retrieved.
|
||||
private final void getMoreDocs(int min) throws IOException {
|
||||
if (hitDocs.size() > min)
|
||||
if (hitDocs.size() > min) {
|
||||
min = hitDocs.size();
|
||||
}
|
||||
|
||||
int n = min * 2; // double # retrieved
|
||||
TopDocs topDocs = searcher.search(query, filter, n);
|
||||
|
@ -92,14 +93,16 @@ public final class Hits {
|
|||
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
|
||||
|
||||
float scoreNorm = 1.0f;
|
||||
if (length > 0 && scoreDocs[0].score > 1.0f)
|
||||
if (length > 0 && scoreDocs[0].score > 1.0f) {
|
||||
scoreNorm = 1.0f / scoreDocs[0].score;
|
||||
}
|
||||
|
||||
int end = scoreDocs.length < length ? scoreDocs.length : length;
|
||||
for (int i = hitDocs.size(); i < end; i++)
|
||||
hitDocs.addElement(new HitDoc(scoreDocs[i].score*scoreNorm,
|
||||
for (int i = hitDocs.size(); i < end; i++) {
|
||||
hitDocs.addElement(new HitDoc(scoreDocs[i].score * scoreNorm,
|
||||
scoreDocs[i].doc));
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the total number of hits available in this set. */
|
||||
public final int length() {
|
||||
|
@ -121,8 +124,9 @@ public final class Hits {
|
|||
oldLast.doc = null; // let doc get gc'd
|
||||
}
|
||||
|
||||
if (hitDoc.doc == null)
|
||||
if (hitDoc.doc == null) {
|
||||
hitDoc.doc = searcher.doc(hitDoc.id); // cache miss: read document
|
||||
}
|
||||
|
||||
return hitDoc.doc;
|
||||
}
|
||||
|
@ -139,19 +143,23 @@ public final class Hits {
|
|||
|
||||
|
||||
private final HitDoc hitDoc(int n) throws IOException {
|
||||
if (n >= length)
|
||||
if (n >= length) {
|
||||
throw new IndexOutOfBoundsException("Not a valid hit number: " + n);
|
||||
if (n >= hitDocs.size())
|
||||
getMoreDocs(n);
|
||||
}
|
||||
|
||||
return (HitDoc)hitDocs.elementAt(n);
|
||||
if (n >= hitDocs.size()) {
|
||||
getMoreDocs(n);
|
||||
}
|
||||
|
||||
return (HitDoc) hitDocs.elementAt(n);
|
||||
}
|
||||
|
||||
private final void addToFront(HitDoc hitDoc) { // insert at front of cache
|
||||
if (first == null)
|
||||
if (first == null) {
|
||||
last = hitDoc;
|
||||
else
|
||||
} else {
|
||||
first.prev = hitDoc;
|
||||
}
|
||||
|
||||
hitDoc.next = first;
|
||||
first = hitDoc;
|
||||
|
@ -161,18 +169,21 @@ public final class Hits {
|
|||
}
|
||||
|
||||
private final void remove(HitDoc hitDoc) { // remove from cache
|
||||
if (hitDoc.doc == null) // it's not in the list
|
||||
if (hitDoc.doc == null) { // it's not in the list
|
||||
return; // abort
|
||||
}
|
||||
|
||||
if (hitDoc.next == null)
|
||||
if (hitDoc.next == null) {
|
||||
last = hitDoc.prev;
|
||||
else
|
||||
} else {
|
||||
hitDoc.next.prev = hitDoc.prev;
|
||||
}
|
||||
|
||||
if (hitDoc.prev == null)
|
||||
if (hitDoc.prev == null) {
|
||||
first = hitDoc.next;
|
||||
else
|
||||
} else {
|
||||
hitDoc.prev.next = hitDoc.next;
|
||||
}
|
||||
|
||||
numDocs--;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class QueryFilter extends Filter {
|
|||
public BitSet bits(IndexReader reader) throws IOException {
|
||||
|
||||
synchronized (cache) { // check cache
|
||||
BitSet cached = (BitSet)cache.get(reader);
|
||||
BitSet cached = (BitSet) cache.get(reader);
|
||||
if (cached != null)
|
||||
return cached;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue