Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 267 lines (204 sloc) 8.245 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
<!--#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)

   ir = U_NEW(IR);
   query = U_NEW(Query);
   crono = U_NEW(UCrono);
   footer = U_NEW(UString(200U));

   UString cfg_index;

   if ((ir->loadFileConfig(cfg_index) &&
        ir->openCDB(false)) == false)
      {
      U_ERROR("usp_init() of servlet ir_web failed...");
      }

   footer->snprintf("ver. %s, with %u documents and %u words.", ULIB_VERSION, cdb_names->size(), cdb_words->size());

   UHTTP::data_session = U_NEW(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()) return HTTP_BAD_REQUEST;

   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
   {
   return HTTP_BAD_METHOD;
   }
-->
<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( "/doc/%.*s", U_STRING_TO_TRACE(filename));
            pathname2.snprintf("%w/doc/%.*s", U_STRING_TO_TRACE(filename));

            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>
Something went wrong with that request. Please try again.