mirror of https://github.com/kiwix/libkiwix.git
+ imp. of the search results display
This commit is contained in:
parent
eece284b17
commit
5056c59747
|
@ -37,7 +37,10 @@ namespace kiwix {
|
||||||
const string &title,
|
const string &title,
|
||||||
const string &unaccentedTitle,
|
const string &unaccentedTitle,
|
||||||
const string &keywords,
|
const string &keywords,
|
||||||
const string &content) {
|
const string &content,
|
||||||
|
const string &snippet,
|
||||||
|
const string &size,
|
||||||
|
const string &wordCount) {
|
||||||
|
|
||||||
Document doc;
|
Document doc;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,10 @@ namespace kiwix {
|
||||||
const string &title,
|
const string &title,
|
||||||
const string &unaccentedTitle,
|
const string &unaccentedTitle,
|
||||||
const string &keywords,
|
const string &keywords,
|
||||||
const string &content);
|
const string &content,
|
||||||
|
const string &snippet,
|
||||||
|
const string &size,
|
||||||
|
const string &wordCount);
|
||||||
void indexNextPercentPost();
|
void indexNextPercentPost();
|
||||||
void stopIndexing();
|
void stopIndexing();
|
||||||
|
|
||||||
|
|
|
@ -126,11 +126,28 @@ namespace kiwix {
|
||||||
accentedTitle = currentArticle.getTitle();
|
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,
|
this->indexNextArticle(url,
|
||||||
accentedTitle,
|
accentedTitle,
|
||||||
removeAccents(this->htmlParser.title),
|
removeAccents(this->htmlParser.title),
|
||||||
removeAccents(this->htmlParser.keywords),
|
removeAccents(this->htmlParser.keywords),
|
||||||
removeAccents(this->htmlParser.dump));
|
removeAccents(this->htmlParser.dump),
|
||||||
|
snippet,
|
||||||
|
size,
|
||||||
|
wordCountString
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <xapian.h>
|
#include <xapian.h>
|
||||||
#include <unaccent.h>
|
#include <unaccent.h>
|
||||||
|
@ -48,7 +49,10 @@ namespace kiwix {
|
||||||
const string &title,
|
const string &title,
|
||||||
const string &unaccentedTitle,
|
const string &unaccentedTitle,
|
||||||
const string &keywords,
|
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 indexNextPercentPost() = 0;
|
||||||
virtual void stopIndexing() = 0;
|
virtual void stopIndexing() = 0;
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,9 @@ namespace kiwix {
|
||||||
CDT result;
|
CDT result;
|
||||||
result["title"] = this->resultOffset->title;
|
result["title"] = this->resultOffset->title;
|
||||||
result["url"] = this->resultOffset->url;
|
result["url"] = this->resultOffset->url;
|
||||||
|
result["snippet"] = this->resultOffset->snippet;
|
||||||
|
result["size"] = this->resultOffset->size;
|
||||||
|
result["wordCount"] = this->resultOffset->wordCount;
|
||||||
resultsCDT.PushBack(result);
|
resultsCDT.PushBack(result);
|
||||||
this->resultOffset++;
|
this->resultOffset++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,9 @@ struct Result
|
||||||
string url;
|
string url;
|
||||||
string title;
|
string title;
|
||||||
int score;
|
int score;
|
||||||
|
string snippet;
|
||||||
|
int wordCount;
|
||||||
|
int size;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
|
@ -54,12 +54,18 @@ namespace kiwix {
|
||||||
const string &title,
|
const string &title,
|
||||||
const string &unaccentedTitle,
|
const string &unaccentedTitle,
|
||||||
const string &keywords,
|
const string &keywords,
|
||||||
const string &content) {
|
const string &content,
|
||||||
|
const string &snippet,
|
||||||
|
const string &size,
|
||||||
|
const string &wordCount) {
|
||||||
|
|
||||||
/* Put the data in the document */
|
/* Put the data in the document */
|
||||||
Xapian::Document currentDocument;
|
Xapian::Document currentDocument;
|
||||||
currentDocument.clear_values();
|
currentDocument.clear_values();
|
||||||
currentDocument.add_value(0, title);
|
currentDocument.add_value(0, title);
|
||||||
|
currentDocument.add_value(1, snippet);
|
||||||
|
currentDocument.add_value(2, size);
|
||||||
|
currentDocument.add_value(3, wordCount);
|
||||||
currentDocument.set_data(url);
|
currentDocument.set_data(url);
|
||||||
indexer.set_document(currentDocument);
|
indexer.set_document(currentDocument);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,10 @@ namespace kiwix {
|
||||||
const string &title,
|
const string &title,
|
||||||
const string &unaccentedTitle,
|
const string &unaccentedTitle,
|
||||||
const string &keywords,
|
const string &keywords,
|
||||||
const string &content);
|
const string &content,
|
||||||
|
const string &snippet,
|
||||||
|
const string &size,
|
||||||
|
const string &wordCount);
|
||||||
void indexNextPercentPost();
|
void indexNextPercentPost();
|
||||||
void stopIndexing();
|
void stopIndexing();
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,9 @@ namespace kiwix {
|
||||||
Result result;
|
Result result;
|
||||||
result.url = doc.get_data();
|
result.url = doc.get_data();
|
||||||
result.title = doc.get_value(0);
|
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();
|
result.score = i.get_percent();
|
||||||
|
|
||||||
this->results.push_back(result);
|
this->results.push_back(result);
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
<TMPL_loop results>
|
<TMPL_loop results>
|
||||||
<li>
|
<li>
|
||||||
<a href="<TMPL_var url>"><TMPL_var title></a>
|
<a href="<TMPL_var url>"><TMPL_var title></a>
|
||||||
<cite><TMPL_var snippet></cite>
|
<cite><TMPL_if snippet><TMPL_var snippet>...</TMPL_if></cite>
|
||||||
<TMPL_if size><TMPL_if wordCount><div class="informations"><TMPL_var size> KB (<TMPL_var wordCount> words)</div></TMPL_if></TMPL_if>
|
<TMPL_if size><TMPL_if wordCount><div class="informations"><TMPL_var size> KB (<TMPL_var wordCount> words)</div></TMPL_if></TMPL_if>
|
||||||
</li>
|
</li>
|
||||||
</TMPL_loop>
|
</TMPL_loop>
|
||||||
|
|
Loading…
Reference in New Issue