* @return a <code>TermPositionVector</code> for the given text.
*/
private TermPositionVector createTermPositionVector(String text)
{
// term -> TermVectorOffsetInfo[]
final SortedMap termMap = new TreeMap();
Reader r = new StringReader(text);
TokenStream ts = index.getTextAnalyzer().tokenStream("", r);
Token t = new Token();
try
{
while ((t = ts.next(t)) != null)
{
String termText = t.term();
TermVectorOffsetInfo[] info = (TermVectorOffsetInfo[])termMap.get(termText);
if (info == null)
{
info = new TermVectorOffsetInfo[1];
}
else
{
TermVectorOffsetInfo[] tmp = info;
info = new TermVectorOffsetInfo[tmp.length + 1];
System.arraycopy(tmp, 0, info, 0, tmp.length);
}
info[info.length - 1] = new TermVectorOffsetInfo(t.startOffset(), t.endOffset());
termMap.put(termText, info);
}
}
catch (IOException e)
{
if (LOG.isTraceEnabled())
{
LOG.trace("An exception occurred: " + e.getMessage());
}
}
return new TermPositionVector()
{
private String[] terms = (String[])termMap.keySet().toArray(new String[termMap.size()]);
public int[] getTermPositions(int index)
{
return null;
}
public TermVectorOffsetInfo[] getOffsets(int index)
{
TermVectorOffsetInfo[] info = TermVectorOffsetInfo.EMPTY_OFFSET_INFO;
if (index >= 0 && index < terms.length)
{
info = (TermVectorOffsetInfo[])termMap.get(terms[index]);
}
return info;
}
public String getField()
{
return "";
}
public int size()
{
return terms.length;
}
public String[] getTerms()
{
return terms;
}
public int[] getTermFrequencies()
{
int[] freqs = new int[terms.length];
for (int i = 0; i < terms.length; i++)
{
freqs[i] = ((TermVectorOffsetInfo[])termMap.get(terms[i])).length;
}
return freqs;
}
public int indexOf(String term)