ctpp2 as external lib on unix

This commit is contained in:
renaud gaudin 2013-08-10 22:14:18 +08:00
parent 741c15da0d
commit d2a2802897
2 changed files with 18 additions and 146 deletions

View File

@ -32,13 +32,13 @@ namespace kiwix {
resultEnd(0),
resultRange(20) {
}
/* Search strings in the database */
void Searcher::search(std::string &search, const unsigned int resultStart,
void Searcher::search(std::string &search, const unsigned int resultStart,
const unsigned int resultEnd, const bool verbose) {
this->reset();
if (verbose == true) {
cout << "Performing query `" << search << "'" << endl;
}
@ -53,7 +53,7 @@ namespace kiwix {
return;
}
/* Reset the results */
void Searcher::reset() {
this->results.clear();
@ -67,25 +67,25 @@ namespace kiwix {
unsigned int Searcher::getEstimatedResultCount() {
return this->estimatedResultCount;
}
/* Get next result */
bool Searcher::getNextResult(string &url, string &title, unsigned int &score) {
bool retVal = false;
if (this->resultOffset != this->results.end()) {
/* url */
url = this->resultOffset->url;
/* title */
title = this->resultOffset->title;
/* score */
score = this->resultOffset->score;
/* increment the cursor for the next call */
this->resultOffset++;
retVal = true;
}
@ -107,20 +107,20 @@ namespace kiwix {
}
string Searcher::getHtml() {
VMOpcodeCollector oVMOpcodeCollector;
StaticText oSyscalls;
StaticData oStaticData;
StaticText oStaticText;
HashTable oHashTable;
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
/* Load template & create template parser */
// cout << getResourceAsString("results.tmpl") << endl;
/* Parse template */
const STLW::string & sSourceFile = getResourceAsString("results.tmpl");
CTPP2TextLoader oSourceLoader;
CTPP2TextLoader oSourceLoader;
oSourceLoader.LoadTemplate(sSourceFile.c_str());
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, "template");
oCTPP2Parser.Compile();
@ -180,7 +180,7 @@ namespace kiwix {
pageCount = 10;
else if (pageCount == 1)
pageCount = 0;
for (unsigned int i=pageStart; i<pageStart+pageCount; i++) {
CDT page;
page["label"] = i + 1;
@ -215,5 +215,5 @@ namespace kiwix {
return sResult;
}
}

View File

@ -1,129 +1 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<style type="text/css">
body{
color: #00000;
font: small/normal Arial,Helvetica,Sans-Serif;
margin-top: 0.5em;
font-size: 90%;
}
a{
color: #04c;
}
a:visited {
color: #639
}
a:hover {
text-decoration: underline
}
.header {
font-size: 120%;
}
ul {
margin:0;
padding:0
}
.results {
font-size: 110%;
}
.results li {
list-style-type:none;
margin-top: 0.5em;
}
.results a {
font-size: 110%;
text-decoration: underline
}
cite {
font-style:normal;
word-wrap:break-word;
display: block;
font-size: 100%;
}
.informations {
color: #388222;
font-size: 100%;
}
.footer {
padding: 0;
margin-top: 1em;
width: 100%;
float: left
}
.footer a, .footer span {
display: block;
padding: .3em .7em;
margin: 0 .38em 0 0;
text-align:center;
text-decoration: none;
}
.footer a:hover {
background: #ededed;
}
.footer ul, .footer li {
list-style:none;
margin: 0;
padding: 0;
}
.footer li {
float: left;
}
.selected {
background: #ededed;
}
</style>
<title>Search: <TMPL_var searchPattern></title>
</head>
<body bgcolor="white">
<div class="header">
<TMPL_if results>
Results <b><TMPL_var resultStart>-<TMPL_var resultEnd></b> of <b><TMPL_var count></b> for <b><TMPL_var searchPattern></b><TMPL_else>No result were found for <b><TMPL_var searchPattern></b></TMPL_if>
</div>
<div class="results">
<ul>
<TMPL_loop results>
<li>
<a href="<TMPL_var protocolPrefix><TMPL_var contentId>/<TMPL_var url>"><TMPL_var title></a>
<cite><TMPL_if snippet><TMPL_var snippet>...</TMPL_if></cite>
<TMPL_if wordCount><div class="informations"><TMPL_var wordCount> words</div></TMPL_if>
</li>
</TMPL_loop>
</ul>
</div>
<div class="footer">
<ul>
<TMPL_if (resultLastPageStart>0)>
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=0&end=<TMPL_var resultRange>">◀</a></li>
</TMPL_if>
<TMPL_loop pages>
<li><a <TMPL_if selected>class="selected"</TMPL_if> href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var start>&end=<TMPL_var end>"><TMPL_var label></a></li>
</TMPL_LOOP>
<TMPL_if (resultLastPageStart>0)>
<li><a href="<TMPL_var searchProtocolPrefix>content=<TMPL_var contentId>&pattern=<TMPL_var searchPatternEncoded>&start=<TMPL_var resultLastPageStart>&end=<TMPL_var (resultLastPageStart+resultRange)>">▶</a></li>
</TMPL_if>
</ul>
</div>
</body>
</html>
SALUT