-
Notifications
You must be signed in to change notification settings - Fork 0
/
QryIopSyn.java
73 lines (56 loc) · 2.08 KB
/
QryIopSyn.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Copyright (c) 2016, Carnegie Mellon University. All Rights Reserved.
*/
import java.io.*;
import java.util.*;
/**
* The SYN operator for all retrieval models.
*/
public class QryIopSyn extends QryIop {
/**
* Evaluate the query operator; the result is an internal inverted
* list that may be accessed via the internal iterators.
* @throws IOException Error accessing the Lucene index.
*/
protected void evaluate () throws IOException {
// Create an empty inverted list. If there are no query arguments,
// that's the final result.
this.invertedList = new InvList (this.getField());
if (args.size () == 0) {
return;
}
// Each pass of the loop adds 1 document to result inverted list
// until all of the argument inverted lists are depleted.
while (true) {
// Find the minimum next document id. If there is none, we're done.
int minDocid = Qry.INVALID_DOCID;
for (Qry q_i: this.args) {
if (q_i.docIteratorHasMatch (null)) {
int q_iDocid = q_i.docIteratorGetMatch ();
if ((minDocid > q_iDocid) ||
(minDocid == Qry.INVALID_DOCID)) {
minDocid = q_iDocid;
}
}
}
if (minDocid == Qry.INVALID_DOCID)
break; // All docids have been processed. Done.
// Create a new posting that is the union of the posting lists
// that match the minDocid. Save it.
// Note: This implementation assumes that a location will not appear
// in two or more arguments. #SYN (apple apple) would break it.
List<Integer> positions = new ArrayList<Integer>();
for (Qry q_i: this.args) {
if (q_i.docIteratorHasMatch (null) &&
(q_i.docIteratorGetMatch () == minDocid)) {
Vector<Integer> locations_i =
((QryIop) q_i).docIteratorGetMatchPosting().positions;
positions.addAll (locations_i);
q_i.docIteratorAdvancePast (minDocid);
}
}
Collections.sort (positions);
this.invertedList.appendPosting (minDocid, positions);
}
}
}