"What if? Why not? Challenge the Convention! Let's do some incredible things!"  More Quotes

Welcome to Aspire Knowledge Central (AKC)

   Home   Public Library   Author Content

Choose a data format:   classic-xml   object-xml   embedded-xml   text   excel

15.02 samplecode: Reading term frequency vectors

Click here to provide feedback or comments at the bottom of this page

	/**
	 * 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;
	}


Subject (Don't use any html tags)

Description (Use html tags: h3, h4, p, pre, a, etc.)

Name Email