+ small test version of the CluceneReader

This commit is contained in:
kelson42 2010-11-06 16:44:05 +00:00
parent e7923b75e9
commit 34953af21b
1 changed files with 29 additions and 3 deletions

View File

@ -2,6 +2,30 @@
namespace kiwix {
typedef std::basic_string<TCHAR> 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();