Basic Retrieval Tasks in Java
From LemurWiki
To perform a basic retrieval using the Java wrappers, first, create a QueryEnvironment object, and use the addIndex call to open your index. Use the runQuery call to get query results. To get the names of the documents, use the documentMetadata call.
The majority of the functionality in the exposed QueryEnvironment class in Java in much the same as the C++ equivalent. For detailed information, see the QueryEnvironment JavaDoc.
[edit] Example Retrieval in Java
The following code snippet is an example of how to use the Indri retrieval functions from Java. The main class (RunQuery) takes two arguments - the first is the path to the index, and the second is the query. The code simply opens the index, runs the query, and dumps out the raw results.
import lemurproject.indri.*; QueryEnvironment env = new QueryEnvironment(); ScoredExtentResult[] results; // open an Indri repository env.addIndex( myIndex ); // run an Indri query, returning 10 results results = env.runQuery( myQuery, 10 ); // fetch the names of the retrieved documents names = env.documentMetadata( results, "docno" ); for( int i=0; i<results.length; i++ ) { results[i].score + " " + results[i].begin + " " + results[i].end ); } env.close(); } }
