br.addSelection(sizeSel);
br.setTermVectorsToFetch(new HashSet<String>(Arrays.asList(new String[] { "tv", "tvPositions",
"tvOffsets", "tvPositionsAndOffsets" })));
BrowseResult result = null;
BoboBrowser boboBrowser = null;
try {
boboBrowser = newBrowser();
result = boboBrowser.browse(br);
assertEquals(1, result.getNumHits());
BrowseHit hit = result.getHits()[0];
assertNull(hit.getStoredFields());
br.setFetchStoredFields(true);
result = boboBrowser.browse(br);
assertEquals(1, result.getNumHits());
hit = result.getHits()[0];
Map<String, List<BoboTerm>> tvMap = hit.getTermVectorMap();
assertNotNull(tvMap);
assertEquals(4, tvMap.size());
List<BoboTerm> tv = tvMap.get("tv");
assertNotNull(tv);
assertEquals("bobo", tv.get(0).term);
assertEquals(2, tv.get(0).freq.intValue());
assertEquals(null, tv.get(0).positions);
assertEquals(null, tv.get(0).startOffsets);
assertEquals(null, tv.get(0).endOffsets);
assertEquals("lucene", tv.get(1).term);
assertEquals(3, tv.get(1).freq.intValue());
assertEquals(null, tv.get(1).positions);
assertEquals(null, tv.get(1).startOffsets);
assertEquals(null, tv.get(1).endOffsets);
assertEquals("test", tv.get(2).term);
assertEquals(1, tv.get(2).freq.intValue());
assertEquals(null, tv.get(2).positions);
assertEquals(null, tv.get(2).startOffsets);
assertEquals(null, tv.get(2).endOffsets);
tv = tvMap.get("tvPositions");
assertNotNull(tv);
assertEquals("bobo", tv.get(0).term);
assertEquals(2, tv.get(0).freq.intValue());
List<Integer> positions = new ArrayList<Integer>(Arrays.asList(0, 1));
assertEquals(positions, tv.get(0).positions);
List<Integer> startOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1));
assertEquals(startOffsets, tv.get(0).startOffsets);
List<Integer> endOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1));
assertEquals(endOffsets, tv.get(0).endOffsets);
assertEquals("lucene", tv.get(1).term);
assertEquals(3, tv.get(1).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(2, 3, 4));
assertEquals(positions, tv.get(1).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1, -1));
assertEquals(startOffsets, tv.get(1).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(-1, -1, -1));
assertEquals(endOffsets, tv.get(1).endOffsets);
assertEquals("test", tv.get(2).term);
assertEquals(1, tv.get(2).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(5));
assertEquals(positions, tv.get(2).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(-1));
assertEquals(startOffsets, tv.get(2).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(-1));
assertEquals(endOffsets, tv.get(2).endOffsets);
tv = tvMap.get("tvOffsets");
assertNotNull(tv);
assertEquals("bobo", tv.get(0).term);
assertEquals(2, tv.get(0).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(-1, -1));
assertEquals(positions, tv.get(0).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(0, 5));
assertEquals(startOffsets, tv.get(0).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(4, 9));
assertEquals(endOffsets, tv.get(0).endOffsets);
assertEquals("lucene", tv.get(1).term);
assertEquals(3, tv.get(1).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(-1, -1, -1));
assertEquals(positions, tv.get(1).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(10, 17, 24));
assertEquals(startOffsets, tv.get(1).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(16, 23, 30));
assertEquals(endOffsets, tv.get(1).endOffsets);
assertEquals("test", tv.get(2).term);
assertEquals(1, tv.get(2).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(-1));
assertEquals(positions, tv.get(2).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(31));
assertEquals(startOffsets, tv.get(2).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(35));
assertEquals(endOffsets, tv.get(2).endOffsets);
tv = tvMap.get("tvPositionsAndOffsets");
assertNotNull(tv);
assertEquals("bobo", tv.get(0).term);
assertEquals(2, tv.get(0).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(0, 1));
assertEquals(positions, tv.get(0).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(0, 5));
assertEquals(startOffsets, tv.get(0).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(4, 9));
assertEquals(endOffsets, tv.get(0).endOffsets);
assertEquals("lucene", tv.get(1).term);
assertEquals(3, tv.get(1).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(2, 3, 4));
assertEquals(positions, tv.get(1).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(10, 17, 24));
assertEquals(startOffsets, tv.get(1).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(16, 23, 30));
assertEquals(endOffsets, tv.get(1).endOffsets);
assertEquals("test", tv.get(2).term);
assertEquals(1, tv.get(2).freq.intValue());
positions = new ArrayList<Integer>(Arrays.asList(5));
assertEquals(positions, tv.get(2).positions);
startOffsets = new ArrayList<Integer>(Arrays.asList(31));
assertEquals(startOffsets, tv.get(2).startOffsets);
endOffsets = new ArrayList<Integer>(Arrays.asList(35));
assertEquals(endOffsets, tv.get(2).endOffsets);
} catch (BrowseException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (IOException ioe) {
fail(ioe.getMessage());
} finally {
if (boboBrowser != null) {
try {
if (result != null) result.close();
boboBrowser.close();
} catch (IOException e) {
fail(e.getMessage());
}
}