From 5056c59747376bb1acff0f13de09dcae94660e6b Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sun, 20 Mar 2011 17:59:31 +0000 Subject: [PATCH] + imp. of the search results display --- src/common/kiwix/cluceneIndexer.cpp | 5 ++++- src/common/kiwix/cluceneIndexer.h | 5 ++++- src/common/kiwix/indexer.cpp | 19 ++++++++++++++++++- src/common/kiwix/indexer.h | 6 +++++- src/common/kiwix/searcher.cpp | 3 +++ src/common/kiwix/searcher.h | 3 +++ src/common/kiwix/xapianIndexer.cpp | 8 +++++++- src/common/kiwix/xapianIndexer.h | 5 ++++- src/common/kiwix/xapianSearcher.cpp | 3 +++ static/results.tmpl | 2 +- 10 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/common/kiwix/cluceneIndexer.cpp b/src/common/kiwix/cluceneIndexer.cpp index 34ffeacde..f5490ae43 100644 --- a/src/common/kiwix/cluceneIndexer.cpp +++ b/src/common/kiwix/cluceneIndexer.cpp @@ -37,7 +37,10 @@ namespace kiwix { const string &title, const string &unaccentedTitle, const string &keywords, - const string &content) { + const string &content, + const string &snippet, + const string &size, + const string &wordCount) { Document doc; diff --git a/src/common/kiwix/cluceneIndexer.h b/src/common/kiwix/cluceneIndexer.h index 3df646bfc..5c8a92821 100644 --- a/src/common/kiwix/cluceneIndexer.h +++ b/src/common/kiwix/cluceneIndexer.h @@ -47,7 +47,10 @@ namespace kiwix { const string &title, const string &unaccentedTitle, const string &keywords, - const string &content); + const string &content, + const string &snippet, + const string &size, + const string &wordCount); void indexNextPercentPost(); void stopIndexing(); diff --git a/src/common/kiwix/indexer.cpp b/src/common/kiwix/indexer.cpp index da92298b7..4ae31d487 100644 --- a/src/common/kiwix/indexer.cpp +++ b/src/common/kiwix/indexer.cpp @@ -126,11 +126,28 @@ namespace kiwix { accentedTitle = currentArticle.getTitle(); } + /* count words */ + stringstream st; + st << countWords(this->htmlParser.dump); + const std::string wordCountString = st.str(); + + /* snippet */ + const std::string snippet = std::string(this->htmlParser.dump, 0, 300); + + /* size */ + st << content.size(); + const std::string size = st.str(); + this->indexNextArticle(url, accentedTitle, removeAccents(this->htmlParser.title), removeAccents(this->htmlParser.keywords), - removeAccents(this->htmlParser.dump)); + removeAccents(this->htmlParser.dump), + snippet, + size, + wordCountString + ); + } } } diff --git a/src/common/kiwix/indexer.h b/src/common/kiwix/indexer.h index 9fa2f9866..040c62008 100644 --- a/src/common/kiwix/indexer.h +++ b/src/common/kiwix/indexer.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -48,7 +49,10 @@ namespace kiwix { const string &title, const string &unaccentedTitle, const string &keywords, - const string &content) = 0; + const string &content, + const string &snippet, + const string &size, + const string &wordCount) = 0; virtual void indexNextPercentPost() = 0; virtual void stopIndexing() = 0; diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index eb45a74c0..6b0690118 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -135,6 +135,9 @@ namespace kiwix { CDT result; result["title"] = this->resultOffset->title; result["url"] = this->resultOffset->url; + result["snippet"] = this->resultOffset->snippet; + result["size"] = this->resultOffset->size; + result["wordCount"] = this->resultOffset->wordCount; resultsCDT.PushBack(result); this->resultOffset++; } diff --git a/src/common/kiwix/searcher.h b/src/common/kiwix/searcher.h index 684d9294d..7c9192d46 100644 --- a/src/common/kiwix/searcher.h +++ b/src/common/kiwix/searcher.h @@ -50,6 +50,9 @@ struct Result string url; string title; int score; + string snippet; + int wordCount; + int size; }; namespace kiwix { diff --git a/src/common/kiwix/xapianIndexer.cpp b/src/common/kiwix/xapianIndexer.cpp index e08cf36db..19e8da1ca 100644 --- a/src/common/kiwix/xapianIndexer.cpp +++ b/src/common/kiwix/xapianIndexer.cpp @@ -54,12 +54,18 @@ namespace kiwix { const string &title, const string &unaccentedTitle, const string &keywords, - const string &content) { + const string &content, + const string &snippet, + const string &size, + const string &wordCount) { /* Put the data in the document */ Xapian::Document currentDocument; currentDocument.clear_values(); currentDocument.add_value(0, title); + currentDocument.add_value(1, snippet); + currentDocument.add_value(2, size); + currentDocument.add_value(3, wordCount); currentDocument.set_data(url); indexer.set_document(currentDocument); diff --git a/src/common/kiwix/xapianIndexer.h b/src/common/kiwix/xapianIndexer.h index 21c227665..899492c7a 100644 --- a/src/common/kiwix/xapianIndexer.h +++ b/src/common/kiwix/xapianIndexer.h @@ -38,7 +38,10 @@ namespace kiwix { const string &title, const string &unaccentedTitle, const string &keywords, - const string &content); + const string &content, + const string &snippet, + const string &size, + const string &wordCount); void indexNextPercentPost(); void stopIndexing(); diff --git a/src/common/kiwix/xapianSearcher.cpp b/src/common/kiwix/xapianSearcher.cpp index 8a9079a3d..4270a7bdc 100644 --- a/src/common/kiwix/xapianSearcher.cpp +++ b/src/common/kiwix/xapianSearcher.cpp @@ -58,6 +58,9 @@ namespace kiwix { Result result; result.url = doc.get_data(); result.title = doc.get_value(0); + result.snippet = doc.get_value(1); + result.size = atoi(doc.get_value(2).c_str()); + result.wordCount = atoi(doc.get_value(3).c_str()); result.score = i.get_percent(); this->results.push_back(result); diff --git a/static/results.tmpl b/static/results.tmpl index 75dc5c8cb..9239295ea 100644 --- a/static/results.tmpl +++ b/static/results.tmpl @@ -104,7 +104,7 @@
  • - + ...
    KB ( words)