// ir_web.cpp - dynamic page translation (ir_web.usp => ir_web.cpp) #include #include "ir_session.h" #include #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, U_NULLPTR) U_INTERNAL_ASSERT_EQUALS(query, U_NULLPTR) U_INTERNAL_ASSERT_EQUALS(crono, U_NULLPTR) U_INTERNAL_ASSERT_EQUALS(footer, U_NULLPTR) 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."), U_CONSTANT_TO_TRACE(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; } extern "C" { extern U_EXPORT void runDynamicPage_ir_web(int param); U_EXPORT void runDynamicPage_ir_web(int param) { U_TRACE(0, "::runDynamicPage_ir_web(%d)", param) if (param) { if (param == U_DPAGE_INIT) { usp_init_ir_web(); return; } if (param == U_DPAGE_DESTROY) { usp_end_ir_web(); return; } if (param >= U_DPAGE_FORK) return; } UHTTP::mime_index = U_html; U_http_info.endHeader = 0; if (UHTTP::getDataSession() == false) UHTTP::setSessionCookie(); 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 = U_NULLPTR; IR_SESSION.timerun = UStringExt::numberToString(crono->getTimeElapsedInSecond()); UHTTP::num_page_cur = 1; } else { UHTTP::setBadMethod(); return; } (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("\n\n ULib search engine: a full-text search system for communities\n \n\n\n
\n
\n\n \n\n
\n \n\t\t \n
\n\n
\n per page\n
\n
\n
\n\n") ); if (form_with_help) { (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("\t
\n\t

Help

\n\n\t

What is This?

\n\n\t

This is a full-text search system. You can search for documents including some specified words.

\n\n\t

How to Use

\n\n\t

Input search phrase into the field at the top of the page. For example, if you search for documents including \"computer\", input the\n\t following.

\n\t
computer
\n\n\t

If you search for documents including both of \"network\" and \"socket\", input the following.

\n\t
network socket
\n\n\t

It is the same as the following.

\n\t
network AND socket
\n\n\t

If you search for documents including \"network\" followed by \"socket\", input the following.

\n\t
\"network socket\"
\n\n\t

If you search for documents including one or both of \"network\" and \"socket\", input the following.

\n\t
network OR socket
\n\n\t

If you search for documents including \"network\" but without \"socket\", input the following.

\n\t
network AND NOT socket
\n\n\t

For more complex query, you can use \"(\". Note that the priority of \"(\" is higher than that of \"AND\",\n\t \"OR\" and \"NOT\". So, the following is to search for documents including one of \"F1\", \"F-1\", \"Formula One\", and including\n\t one of \"champion\" and \"victory\".

\n\t
(F1 OR F-1 OR \"Formula One\") AND (champion OR victory)
\n\n\t

You can use DOS wildcard characters

\n\n\t

If you search for documents including some words beginning with \"inter\", input the following.

\n\t
inter*
\n\n\t

If you search for documents including some words ending with \"sphere\", input the following.

\n\t
*sphere
\n\n\t

If you search for documents matching some words matching \"?n*able\" (unable, unavoidable, inevitable, ...), input the following.

\n\t
?n*able
\n\n\t

Other Faculties

\n\n\t

\"[...] per page\" specifies the number of shown documents per page. If documents over one page correspond, you can move to another\n\t page via anchors of \"PREV\" and \"NEXT\" at the bottom of the page.

\n\n\t

Information

\n\n\t

See the project site for more detail.

\n\t
\n\n") ); } else { if (num_args == 0) { (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("\t
\n\t\t

ULib search engine

\n\t\t
a full-text search system for communities
\n\t
\n\n") ); } else { UString link_paginazione = UHTTP::getLinkPagination(); USP_PRINTF("
\n" "
\n" " Results of %u - %u of about %u for %v (%v sec.)\n" "
\n", UHTTP::num_page_start, UHTTP::num_page_end, UHTTP::num_item_tot, IR_SESSION.query.rep, IR_SESSION.timerun.rep); if (UHTTP::num_item_tot == 0) { (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("\t\t\t

Your search did not match any documents.

\n") ); } 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("
%v\n" "
%v ...
\n" "
file://%v
\n" "
\n", pathname1.rep, basename.rep, snippet_doc.rep, pathname2.rep); } } USP_PRINTF("
%v
\n", link_paginazione.rep); } } (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("
\n Powered by ULib search engine ") ); (void) UClientImage_Base::wbuffer->append((*footer)); (void) UClientImage_Base::wbuffer->append( U_CONSTANT_TO_PARAM("
\n\n") ); UHTTP::putDataSession(); } }