5 // 5 January 2007 -- tds
8 #include "indri/ScoredExtentResult.hpp"
9 #include "indri/Parameters.hpp"
10 #include "lemur/Exception.hpp"
11 #include "Retrieval.hpp"
21 std::cerr
<< "galago --query.text=hi --query.number=1 --count=10 --index=myindex" << std::endl
;
29 static void require( indri::api::Parameters param
, const std::string
& p
) {
30 if( !param
.exists(p
) )
38 static void command_line( Retrieval
& retrieval
, indri::api::Parameters
& parameters
) {
39 // record results requested
40 int requested
= parameters
.get( "count", 1000 );
42 // for each query, run it, get the results, look up the docnos, print in TREC format
43 indri::api::Parameters queries
= parameters
["query"];
45 for( int i
=0; i
<queries
.size(); i
++ ) {
46 std::string queryText
= queries
[i
]["text"];
47 std::string queryName
= queries
[i
]["number"];
48 int threshold
= (int)(INT64
)queries
[i
].get( "threshold", -1 );
50 std::vector
<indri::api::ScoredExtentResult
> results
;
51 std::vector
<QueryTerm
> terms
= Query::parse( queryText
);
52 results
= retrieval
.runQuery( terms
, requested
, threshold
);
54 for( int i
=0; i
<results
.size(); i
++ ) {
55 std::string document
= retrieval
.getDocument(results
[i
].document
);
56 int score
= (int)results
[i
].score
;
59 printf( "%s Q0 %s %d %d galago\n", queryName
.c_str(), document
.c_str(), rank
, score
);
68 int main( int argc
, char** argv
) {
71 indri::api::Parameters::instance().loadCommandLine( argc
, argv
);
72 indri::api::Parameters
& parameters
= indri::api::Parameters::instance();
75 std::string indexPath
= parameters
["index"];
76 Retrieval
* retrieval
= Retrieval::open( indexPath
);
78 command_line( *retrieval
, parameters
);
79 } catch( lemur::api::Exception
& e
) {