Lexer::Lexer(QueryParserBase* queryparser, const TCHAR* query) { //Func - Constructor //Pre - query != NULL and contains the query string //Post - An instance of Lexer has been created this->queryparser = queryparser; CND_PRECONDITION(query != NULL, "query is NULL"); //The InputStream of Reader must be destroyed in the destructor delSR = true; StringReader *r = _CLNEW StringReader(query); //Check to see if r has been created properly CND_CONDITION(r != NULL, "Could not allocate memory for StringReader r"); //Instantie a FastCharStream instance using r and assign it to reader reader = _CLNEW FastCharStream(r); //Check to see if reader has been created properly CND_CONDITION(reader != NULL, "Could not allocate memory for FastCharStream reader"); //The InputStream of Reader must be destroyed in the destructor delSR = true; }
//========================================================================== // Class: ConfigFile // Function: StringReader // // Description: Reads the specified data into another string. // // Input Arguments: // data = const std::string& // // Output Arguments: // value = std::string& // // Return Value: // bool, true for success, false otherwise // //========================================================================== bool ConfigFile::StringVectorReader(const std::string &data, std::vector<std::string> &value) { std::string s; if (!StringReader(data, s)) return false; value.push_back(s); return true; }
void getAnalyzedString(const wchar_t* input, wchar_t* output) { CL_NS_USE(index) CL_NS_USE(util) CL_NS_USE(store) CL_NS_USE(search) CL_NS_USE(document) CL_NS_USE(queryParser) CL_NS_USE(analysis) CL_NS_USE2(analysis,standard) /* * StandardAnalyzer sAnalyser; * Used before but this but this includes stopwords filters */ CustomAnalyzer sAnalyser((const wchar_t*)L"stdtokens>stdfilter>lowercase"); Reader* reader = _CLNEW StringReader(input); TokenStream* ts = sAnalyser.tokenStream(_T("dummy"), reader ); Token t; while(ts->next(&t)) { wcscat(output,t.termText()); wcscat(output,L"* "); } size_t len = wcslen(output); if(len == 0) wcscpy(output,L"*"); else { if(output[len-1] == L' ') output[len-1] = L'\0'; } ts->close(); _CLDELETE(ts); _CLDELETE(reader); }
Query* QueryParser::parse(const TCHAR* query){ //Func - Returns a parsed Query instance //Pre - query != NULL and contains the query value to be parsed //Post - Returns a parsed Query Instance CND_PRECONDITION(query != NULL, "query is NULL"); //Instantie a Stringer that can read the query string Reader* r = _CLNEW StringReader(query); //Check to see if r has been created properly CND_CONDITION(r != NULL, "Could not allocate memory for StringReader r"); //Pointer for the return value Query* ret = NULL; try{ //Parse the query managed by the StringReader R and return a parsed Query instance //into ret ret = parse(r); }_CLFINALLY ( _CLDELETE(r); );