[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CSE494 - Creating a Term from query String



Hi,
 Some of the people had a problem figuring out how to convert a query into
a Term. 
 Here is the exact code below. I create a term and also use it to retrieve
the results of the match. And strangely I get the exact answer as the
searchFiles.java. Goes to show what is exactly happening behind all the
Hits schema ;-)

 //create a new term
 TermDocs termdocs = reader.termDocs(new Term("contents","subbarao"));
	    while(termdocs.next())
	// a complex but single line way to get the URL of the documents.	
	System.out.println((reader.document(termdocs.doc())).get("url")


Here is a new showVector() method of VectorViewer.java that will show
you how above code works. Cut paste into your VectorViewer.java  if you
are not convinced by my explanation.

-----------------------------------------------------------------
 public void  showVector()
    {
	// lists the vector
	try{
	IndexReader reader = IndexReader.open("index");
	System.out.println(" Number of Docs in Index :" +
reader.numDocs());
	    TermDocs termdocs = reader.termDocs(new Term("contents","subbarao"));
	    while(termdocs.next())
          System.out.println((reader.document(termdocs.doc())).get("url"));

		}catch(IOException e){
	    System.out.println("IO Error has occured: "+ e);
	    return;
 }
-----------------------------------------------------------------------------------------


Ullas

"Well Begun is Half Done"