16-Aug-05 (Created: 16-Aug-05) | More in 'Lucene'

15.02 samplecode: Reading term frequency vectors

	/**
	 * Given a unique key such as a URL, locate the document
	 * and return its term frequency vector.
	 * 
	 * return null if the key is not found.
	 * 
	 * When a document is located its docnum is used to retrieve the
	 * term frequency vector
	 * 
	 * @param url
	 * @return
	 * @throws IOException
	 */
	public TermFreqVector getTermVectors(String url) throws IOException
	{
		//Locate the matching document
		LuceneIndex li = LuceneIndexHolder.getLuceneIndex();
		int docnum = li.locateIndexedUrlDocNumber(url);
		
		//Document not found
		if (docnum == -1)
		{
			return null;
		}
		
		//Document found
		IndexReader reader = li.getReader();
		
		//Log.log("Index has " + reader.numDocs() + " documents.");
		TermFreqVector tfv = reader.getTermFreqVector(docnum,"content");
		return tfv;
	}