From 34953af21ba47bbce4590d5c1fc9b6ab519eb634 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sat, 6 Nov 2010 16:44:05 +0000 Subject: [PATCH] + small test version of the CluceneReader --- src/common/kiwix/cluceneSearcher.cpp | 32 +++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/common/kiwix/cluceneSearcher.cpp b/src/common/kiwix/cluceneSearcher.cpp index 60b35b5b3..bd43758e6 100644 --- a/src/common/kiwix/cluceneSearcher.cpp +++ b/src/common/kiwix/cluceneSearcher.cpp @@ -2,6 +2,30 @@ namespace kiwix { + + typedef std::basic_string tstring; + + TCHAR* StringToTCHAR(string& s) + { + tstring tstr; + const char* all = s.c_str(); + int len = 1 + strlen(all); + wchar_t* t = new wchar_t[len]; + if (NULL == t) throw std::bad_alloc(); + mbstowcs(t, all, len); + return (TCHAR*)t; + } + + std::string TCHARToString(const TCHAR* ptsz) + { + int len = wcslen((wchar_t*)ptsz); + char* psz = new char[2*len + 1]; + wcstombs(psz, (wchar_t*)ptsz, 2*len + 1); + std::string s = psz; + delete [] psz; + return s; + } + /* Constructor */ CluceneSearcher::CluceneSearcher(const string &cluceneDirectoryPath) : kiwix::Searcher() { @@ -23,16 +47,18 @@ namespace kiwix { IndexSearcher searcher(reader); SimpleAnalyzer analyzer; QueryParser parser(_T("content"), &analyzer); - Query* query = parser.parse((const wchar_t*)search.c_str()); + Query* query = parser.parse(StringToTCHAR(search)); Hits* hits = searcher.search(query); - + cout << "--------------------------------" << hits->length() << endl; + + /* for (size_t i=0; i < hits->length() && i<10; i++) { Document* d = &hits->doc(i); _tprintf(_T("#%d. %s (score: %f)\n"), i, d->get(_T("contents")), hits->score(i)); } - + */ /* Result result; result.url = doc.get_data();