List<TermVectorOffsetInfo> results = new ArrayList<TermVectorOffsetInfo>();
TermFreqVector tfv = ir.getTermFreqVector(docNo, fieldName);
Map<String,Integer> termToID = new HashMap<String,Integer>();
if(tfv instanceof TermPositionVector) {
TermPositionVector tpv = (TermPositionVector)tfv;
String [] terms = tpv.getTerms();
for(int i=0;i<tpv.getTerms().length;i++) {
if(simpleTerms.contains(new Term(fieldName, terms[i]))) {
//System.out.println(terms[i]);
TermVectorOffsetInfo[] tps = tpv.getOffsets(i);
int[] positions = tpv.getTermPositions(i);
for(int j=0;j<tps.length;j++) {
results.add(tps[j]);
//System.out.println(terms[i] + "\t" + positions[j] + "\t" + tps[j].getStartOffset() + "\t" + tps[j].getEndOffset());
}
}
if(ptt.contains(terms[i])) {
termToID.put(terms[i], i);
}
}
for(List<Term> phraseTerm : phraseTerms) {
String firstWord = phraseTerm.get(0).text();
if(termToID.containsKey(firstWord)) {
//System.out.println(firstWord);
Map<Integer,List<TermVectorOffsetInfo>> phrases = new HashMap<Integer,List<TermVectorOffsetInfo>>();
int id = termToID.get(firstWord);
TermVectorOffsetInfo[] tps = tpv.getOffsets(id);
int[] positions = tpv.getTermPositions(id);
for(int i=0;i<positions.length;i++) {
List<TermVectorOffsetInfo> tvoil = new ArrayList<TermVectorOffsetInfo>();
tvoil.add(tps[i]);
phrases.put(positions[i], tvoil);
//System.out.println(firstWord + "\t" + positions[i]);
}
for(int i=1;i<phraseTerm.size();i++) {
String word = phraseTerm.get(i).text();
if(!termToID.containsKey(word)) {
phrases = null;
break;
}
int cid = termToID.get(word);
TermVectorOffsetInfo[] ctps = tpv.getOffsets(cid);
int[] cpositions = tpv.getTermPositions(cid);
for(int j=0;j<cpositions.length;j++) {
//System.out.println(word + "\t" + cpositions[j]);
if(phrases.containsKey(cpositions[j] - i)) {
//System.out.println(phrases.get(cpositions[j] - i));
phrases.get(cpositions[j] - i).add(ctps[j]);