5 // 5 January 2007 -- tds
7 // BSD License (http://galagosearch.org/license)
10 #include "indri/ScoredExtentResult.hpp"
11 #include "indri/Parameters.hpp"
12 #include "lemur/Exception.hpp"
13 #include "Retrieval.hpp"
23 std::cerr
<< "galago --query.text=hi --query.number=1 --count=10 --index=myindex" << std::endl
;
31 static void require( indri::api::Parameters param
, const std::string
& p
) {
32 if( !param
.exists(p
) )
40 static void command_line( Retrieval
& retrieval
, indri::api::Parameters
& parameters
) {
41 // record results requested
42 int requested
= parameters
.get( "count", 1000 );
44 // for each query, run it, get the results, look up the docnos, print in TREC format
45 indri::api::Parameters queries
= parameters
["query"];
47 for( int i
=0; i
<queries
.size(); i
++ ) {
48 std::string queryText
= queries
[i
]["text"];
49 std::string queryName
= queries
[i
]["number"];
50 int threshold
= (int)(INT64
)queries
[i
].get( "threshold", -1 );
52 std::vector
<indri::api::ScoredExtentResult
> results
;
53 std::vector
<QueryTerm
> terms
= Query::parse( queryText
);
54 results
= retrieval
.runQuery( terms
, requested
, threshold
);
56 for( int i
=0; i
<results
.size(); i
++ ) {
57 std::string document
= retrieval
.getDocument(results
[i
].document
);
58 int score
= (int)results
[i
].score
;
61 printf( "%s Q0 %s %d %d galago\n", queryName
.c_str(), document
.c_str(), rank
, score
);
70 int main( int argc
, char** argv
) {
73 indri::api::Parameters::instance().loadCommandLine( argc
, argv
);
74 indri::api::Parameters
& parameters
= indri::api::Parameters::instance();
77 std::string indexPath
= parameters
["index"];
78 Retrieval
* retrieval
= Retrieval::open( indexPath
);
80 command_line( *retrieval
, parameters
);
81 } catch( lemur::api::Exception
& e
) {