1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
ULib/examples/IR/ir_web.usp
stefanocasazza 5c1a3c49ea sync
2016-10-06 16:09:35 +02:00

274 lines
8.1 KiB
Plaintext

<!--#declaration
#include "ir_session.h"
#include <ulib/debug/crono.h>
#define IR_SESSION (*(IRDataSession*)UHTTP::data_session)
static IR* ir;
static Query* query;
static UCrono* crono;
static UString* footer;
static void usp_init_ir_web()
{
U_TRACE(5, "::usp_init_ir_web()")
U_INTERNAL_ASSERT_EQUALS(ir,0)
U_INTERNAL_ASSERT_EQUALS(query,0)
U_INTERNAL_ASSERT_EQUALS(crono,0)
U_INTERNAL_ASSERT_EQUALS(footer,0)
U_NEW(IR, ir, IR);
U_NEW(Query, query, Query);
U_NEW(UCrono, crono, UCrono);
U_NEW(UString, footer, UString(200U));
ir->loadFileConfig();
if (ir->openCDB(false) == false)
{
U_ERROR("usp_init() of servlet ir_web failed");
}
footer->snprintf(U_CONSTANT_TO_PARAM("ver. %s, with %u documents and %u words."), ULIB_VERSION, cdb_names->size(), cdb_words->size());
U_NEW(IRDataSession, UHTTP::data_session, IRDataSession);
UHTTP::initSession();
}
static void usp_end_ir_web()
{
U_TRACE(5, "::usp_end_ir_web()")
U_INTERNAL_ASSERT_POINTER(ir)
U_INTERNAL_ASSERT_POINTER(query)
U_INTERNAL_ASSERT_POINTER(crono)
U_INTERNAL_ASSERT_POINTER(footer)
delete ir;
delete query;
delete crono;
delete footer;
}
-->
<!--#session
-->
<!--#code
const char* ref = "?ext=help";
uint32_t num_args = UHTTP::processForm() / 2;
bool form_with_help = false;
if (UHTTP::isGET())
{
if (num_args == 1)
{
UString ext_val = USP_FORM_VALUE_FROM_NAME("ext");
if (ext_val.equal(U_CONSTANT_TO_PARAM("help")))
{
ref = "ir_web";
form_with_help = true;
}
else
{
UHTTP::num_item_tot = IR_SESSION.size();
UHTTP::num_page_cur = USP_FORM_VALUE(0).strtol();
}
}
}
else if (UHTTP::isPOST())
{
IR_SESSION.query = USP_FORM_VALUE(0);
if (num_args != 2 ||
IR_SESSION.query.empty())
{
UHTTP::setBadRequest();
return;
}
IR_SESSION.for_page = UHTTP::num_item_for_page = USP_FORM_VALUE(1).strtol();
query->clear();
crono->start();
query->run(U_STRING_TO_PARAM(IR_SESSION.query), &IR_SESSION.vec);
crono->stop();
if ((UHTTP::num_item_tot = WeightWord::size()))
{
UHTTP::num_page_start = 1;
UHTTP::num_page_end = UHTTP::num_item_for_page;
WeightWord::sortObjects();
}
WeightWord::vec = 0;
IR_SESSION.timerun = UStringExt::numberToString(crono->getTimeElapsedInSecond());
UHTTP::num_page_cur = 1;
}
else
{
UHTTP::setBadMethod();
return;
}
-->
<html>
<head>
<title>ULib search engine: a full-text search system for communities</title>
<link title="Services" rel="stylesheet" href="/css/pagination.min.css" type="text/css">
</head>
<body>
<div id="estform" class="estform">
<form action="ir_web" method="post" id="form_self" name="form_self">
<div class="form_navi">
<a href="<!--#puts ref -->" class="navilink">help</a>
</div>
<div class="form_basic">
<input type="text" name="phrase" value="" size="80" id="phrase" class="text" tabindex="1" accesskey="0">
<input type="submit" value="Search" id="search" class="submit" tabindex="2" accesskey="1">
</div>
<div class="form_extension">
<select name="perpage" id="perpage" tabindex="3">
<option value="10" selected="selected">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="50">50</option>
<option value="60">60</option>
<option value="70">70</option>
<option value="80">80</option>
<option value="90">90</option>
<option value="100">100</option>
</select> per page
</div>
</form>
</div>
<!--#code
if (form_with_help) {
-->
<div class="help">
<h1 class="title">Help</h1>
<h2>What is This?</h2>
<p>This is a full-text search system. You can search for documents including some specified words.</p>
<h2>How to Use</h2>
<p>Input search phrase into the field at the top of the page. For example, if you search for documents including "computer", input the
following.</p>
<pre>computer</pre>
<p>If you search for documents including both of "network" and "socket", input the following.</p>
<pre>network socket</pre>
<p>It is the same as the following.</p>
<pre>network AND socket</pre>
<p>If you search for documents including "network" followed by "socket", input the following.</p>
<pre>"network socket"</pre>
<p>If you search for documents including one or both of "network" and "socket", input the following.</p>
<pre>network OR socket</pre>
<p>If you search for documents including "network" but without "socket", input the following.</p>
<pre>network AND NOT socket</pre>
<p>For more complex query, you can use "<code>(</code>". Note that the priority of "<code>(</code>" is higher than that of "<code>AND</code>",
"<code>OR</code>" and "<code>NOT</code>". So, the following is to search for documents including one of "F1", "F-1", "Formula One", and including
one of "champion" and "victory".</p>
<pre>(F1 OR F-1 OR "Formula One") AND (champion OR victory)</pre>
<h2>You can use DOS wildcard characters</h2>
<p>If you search for documents including some words beginning with "inter", input the following.</p>
<pre>inter*</pre>
<p>If you search for documents including some words ending with "sphere", input the following.</p>
<pre>*sphere</pre>
<p>If you search for documents matching some words matching "?n*able" (unable, unavoidable, inevitable, ...), input the following.</p>
<pre>?n*able</pre>
<h2>Other Faculties</h2>
<p>"<code>[...] per page</code>" specifies the number of shown documents per page. If documents over one page correspond, you can move to another
page via anchors of "<code>PREV</code>" and "<code>NEXT</code>" at the bottom of the page.</p>
<h2>Information</h2>
<p>See <a href="http://www.unirel.com/">the project site</a> for more detail.</p>
</div>
<!--#code
} else {
if (num_args == 0) {
-->
<div class="logo">
<h1 class="title">ULib search engine</h1>
<div class="caption">a full-text search system for communities</div>
</div>
<!--#code
} else {
UString link_paginazione = UHTTP::getLinkPagination();
USP_PRINTF("<div id=\"estresult\" class=\"estresult\">\n"
" <div class=\"resinfo\">\n"
" Results of <strong>%u</strong> - <strong>%u</strong> of about <strong>%u</strong> for <strong>%s</strong> (%.*s sec.)\n"
" </div>\n",
UHTTP::num_page_start, UHTTP::num_page_end, UHTTP::num_item_tot, IR_SESSION.query.data(), U_STRING_TO_TRACE(IR_SESSION.timerun));
if (UHTTP::num_item_tot == 0) {
-->
<p class="note">Your search did not match any documents.</p>
<!--#code
} else {
UString doc, snippet_doc(U_CAPACITY), basename, filename, pathname1(U_CAPACITY), pathname2(U_CAPACITY);
for (uint32_t i = UHTTP::num_page_start-1; i < UHTTP::num_page_end; ++i)
{
filename = IR_SESSION.vec[i]->filename;
basename = UStringExt::basename(filename);
pathname1.snprintf(U_CONSTANT_TO_PARAM( "/doc/%v"), filename.rep);
pathname2.snprintf(U_CONSTANT_TO_PARAM("%w/doc/%v"), filename.rep);
doc = UFile::contentOf(pathname2);
UXMLEscape::encode(doc, snippet_doc);
USP_PRINTF("<dl class=\"doc\"\n"
" <dt><a href=\"%s\" class=\"doc_title\">%.*s</a></dt>\n"
" <dd class=\"doc_text\">%s <code class=\"delim\">...</code></dd>\n"
" <dd class=\"doc_navi\"><span class=\"doc_link\">file://%s</span></dd>\n"
"</dl>\n",
pathname1.data(), U_STRING_TO_TRACE(basename), snippet_doc.data(), pathname2.data());
}
}
USP_PRINTF("<div class=\"paging\">%.*s</div></div>\n", U_STRING_TO_TRACE(link_paginazione));
}
}
-->
<div id="estinfo" class="estinfo">
Powered by <a href="http://www.unirel.com/">ULib search engine</a> <!--#puts *footer -->
</div>
</body>
</html>