1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-10-05 19:18:01 +08:00
ULib/examples/IR/query.cpp
stefanocasazza 4838528c74 MACOSX fix
2015-10-30 19:37:21 +01:00

75 lines
1.3 KiB
C++

// query.cpp
#include <ulib/query/parser.h>
#undef PACKAGE
#define PACKAGE "query"
#undef ARGS
#define ARGS "<query>"
#define U_OPTIONS \
"purpose 'search in index database of document files...'\n" \
"option c config 1 'path of configuration file' ''\n"
#include "cquery.h"
class Application : public IR {
public:
Application()
{
U_TRACE(5, "Application::Application()")
query = 0;
}
~Application()
{
U_TRACE(5, "Application::~Application()")
if (query)
{
delete posting;
posting = 0;
delete query;
}
}
void run(int argc, char* argv[], char* env[])
{
U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env)
IR::run(argc, argv, env);
// manage arg operation
const char* ptr = argv[optind];
U_INTERNAL_DUMP("optind = %d", optind)
if (ptr == 0) U_ERROR("<query> not specified");
UString::str_allocate(STR_ALLOCATE_QUERY_PARSER);
if (IR::openCDB(false))
{
uint32_t len;
query = U_NEW(Query);
ptr = Query::checkQuoting(argv, len);
query->run(ptr, len, 0);
WeightWord::dumpObjects();
IR::deleteDB();
}
}
private:
Query* query; // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
};
U_MAIN