⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchservlet.java

📁 关于Ultraseek的一些用法,刚初学,所以都是比较简单
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                  /* Ultraseek 5.3.2 or below will fail for every log request                     unless a patch is installed (contact Technical Support).                     Don't fill up the Servlet logs with these errors. */                  diagnosticLog.debug("Remote Ultraseek server does not support logging", exc);              } catch (IOException exc2) { // during versionAtLeast()                // log the original exception                log("Problem logging query", exc);              }            }          } catch (IOException exc) {            log("Problem logging query", exc);          }        }      }    }    /**     * Determine what servers and collections to search for this search query.     * <p>     * Using the <code>col</code> parameter, determine which servers and      * collections should be searched for this query.     * The following properties should be set by this method:     * <blockquote>     * <table border=1>     * <tr><th>Property</th><th>Meaning</th></tr>     * <tr><td>menuItem</td><td>The menu item being searched.       *                          menuItem.ID is used for query logging</td></tr>     * <tr><td>server</td><td>The <code>SearchServer</code> to use for resolving     *                        topic ID's and making thesaurus suggestions.     *                          </td></tr>     * <tr><td>searchable</td><td>The <code>Searchable</code> which will be searched.     *                            This should be an instance of <code>CompositeSearchable</code>     *                            if multiple <code>SearchServer</code>s are to be searched.     *                          </td></tr>     * <tr><td>speller</td><td>The speller to use, or <code>null</code> if no     *                         spell suggestion is to be performed.     *                         </td></tr>     * <tr><td>quickLinks</td><td>The quicklinks generator ot use, or <code>null</code> if no     *                            quick links are to be used.     *                          </td></tr>     * </table>     * </blockquote>     */    protected void determineSearchCollection() {      // Get the appropriate Search Server and Searchable from the       // search menu.      SearchMenuItem sm = null;      if (col!=null)        sm = (SearchMenuItem) searchMenu.get(col);      // If we can't find the specified collection, pick      // the first menu item as the searchable.      if (sm==null) {        sm = (SearchMenuItem) searchMenu.get(searchMenu.firstKey());        col = sm.ID;      }        menuItem   = sm;      server     = sm.server;      searchable = sm.searchable;      speller    = sm.speller;      quickLinks = sm.quickLinks;    }    /**     * Sets <code>style</code> and <code>styleSettings</code> to the appropriate     * style definitions for this <code>SearchRequest</code>.     * <p>     * Either value may be <code>null</code> if the style cannot be     * resolved (which can occur if the Ultraseek server is older than version 5.1.1).     * @see #showStyleSheet     * @see #getStyleSettingObject     */    protected void parseStyleSetting() {      // Named display styles      String newstyle = getParameterString("style");      try {        if (!ultraseek.versionAtLeast(5,1,1)) {          style = null;          styleSettings = null;          return;        }        // Ultraseek version 5.1 supports multiple display styles        if (!ultraseek.getStyles().contains(newstyle))          newstyle = ultraseek.getDefaultStyle();        style = newstyle;        if (style != null)          styleSettings = ultraseek.getStyleSettings(style);      } catch (IOException e) {        log( "Problem in parseStyleSetting", e );      };    }    protected String decodeParameterString(String raw) {      String charset = req.getParameter("charset");      try {        if (charset==null) return decode(raw,"UTF-8");        return decode(raw,charset);      } catch (Exception e) {        // Could be UnsupportedEncodingException or IllegalArgumentException        log("Unexpected problem:", e);        return raw;      }    }    /**     * Return the value of a query parameter, encoded in Unicode.     */    protected String getParameterString(String param) {      if (param==null) return null;      String raw = req.getParameter(param);      if (raw==null) return null;      return decodeParameterString(raw);    }    /**     * Return the concatenated String value of a set of query parameters.     */    protected String getMultiParameterString(String param) {      if (param==null) return null;      String raw[] = req.getParameterValues(param);      if (raw==null) return null;      if (raw.length < 1) return null;      StringBuffer sb = new StringBuffer();      String joiner = "";      for (int i = 0; i < raw.length; i++) {        sb.append(joiner);        joiner = ", ";        sb.append( decodeParameterString(raw[i]) );      }      return sb.toString();    }    protected void parseQueryParameters()       throws IOException, ServletException {      session = req.getSession(false);      parseStyleSetting();      if (!isEmpty(style) && !style.equals(ultraseek.getDefaultStyle()))        query_nodef.put("style",style);      // Locale param      // la = getParameterString("la");      // la already processed in constructor.      // Always pass language to prevent auto-reset by browser accept-language      query_nodef.put("la",la);      // Collections to search      col = getParameterString("col");      if (!isEmpty(col))        query_nodef.put("col",col);       // starting hit number      st = getIntParameter(req,"st",1);      if (st < 1) st = 1;      if (st > 500) st = 500;      if (st!=1)        query_nodef.put("st",""+st);      // query mode      qm = getParameterOrStyleInt("qm","default_qm");      if (qm < QM_NEW_SEARCH || qm > QM_SEARCH_THIS_TOPIC)        qm = getStyleSettingInt("default_qm");      // requested query      rq = getParameterInt("rq",QM_NEW_SEARCH);      if (rq < QM_NEW_SEARCH || rq > QM_SEARCH_THIS_TOPIC)        rq = QM_NEW_SEARCH;      if (rq!=QM_NEW_SEARCH)        query_nodef.put("rq",""+rq);      // number of hits to show      nh = getParameterOrStyleInt("nh","default_nh");      if (nh < 1) nh = getStyleSettingInt("default_nh",10);      if (nh > 500) nh = 500;      // look of results pages      lk = getParameterOrStyleInt("lk","default_lk");      // results filter (sorting order, relevance algorithm)      rf = getParameterOrStyleInt("rf","default_rf");      if (rf < RF_RELEVANCE || rf > RF_DATE_SORT) rf = getStyleSettingInt("default_rf");      // Site Clustering (group by location, group by topic)      sc = getParameterOrStyleInt("sc","default_sc");      if (getParameterString("sc")==null &&           getStyleSettingInt("default_sc")==SC_NO_GROUPING &&          getStyleSettingBoolean("group_results_by_topic"))        sc = SC_GROUP_BY_TOPIC;      //previous results filter      pf = getIntParameter(req,"pf",rf);      if(pf!=rf) st = 1; //for switching between output sort order      // query prefix, search syntax string         // example:  "site:division.corp.com"      // prepended to user's qtxt with " || "      qp = getMultiParameterOrStyleString("qp", "default_qp");      // query suffix, search syntax string      // example: " -site:archive.corp.com"      // appended to user's qtxt with ", "      qs = getMultiParameterOrStyleString("qs", "default_qs");      // old query      oq = getParameterString("oq");      if (!isEmpty(oq))        query_nodef.put("oq",oq);      // query text      qt = getMultiParameterString("qt");      if (!isEmpty(qt))        query_nodef.put("qt",qt);      // Query Level: a==Advanced      ql = getParameterOrStyleString("ql","default_ql");      // Home Topic:      ht = getParameterOrStyleString("ht","default_ht");      if (ht==null) ht = "0";      // Current Topic:      ct = getParameterString("ct");      // Thesaurus Expansions terms      ex = getMultiParameterString("ex");      if (!isEmpty(ex))        query_nodef.put("ex",ex);      // Show Word Scores:      ws = getParameterOrStyleInt("ws","show_word_scores");      // Page Width:      pw = getParameterOrStyleString("pw","default_pw");      // Show All Topics      tt = getParameterInt("tt", 0);      if (!getStyleSettingBoolean("show_all_topics"))        tt = 0;      else if (tt!=0)        query_nodef.put("tt",""+tt);      /** oldqt - used when smart no-hits redirects based on spelling suggestion       *  Interaction:       *    qt==null              : Initial search page       *    qt!=null oldqt==null  : Normal search       *    qt!=null oldqt!=qt    : Automatically attempting spelling suggestion       *    qt!=null oldqt==qt    : Automatic suggestion had no hits, reverting to original       */      oldqt = getParameterString("oldqt");      if (!isEmpty(oldqt))        query_nodef.put("oldqt",oldqt);      // find similar      fs = getParameterString("fs");      if (!isEmpty(fs))        query_nodef.put("fs",fs);    }    protected void setupSearch()      throws IOException, ServletException {      determineSearchCollection();      //Locale and Character set      // are determined during constructor            // Pick up translation matrix      textMap = la_textMap(la);      // make query text      qtxt = makeQueryText();      // make topic      topic = makeTopic();      fmt = DateFormat.getDateInstance(DateFormat.SHORT,locale);      after = makeAfter(req);      before = makeBefore(req);      // make query object      query = makeQuery();      // Add post-search processing (Title Sort, Score using Date, etc)      searchable = addSearchableProcessing(searchable);    }    /**     * Sets the client browser caching headers for the HTTP response.     * Use a caching interval of 0 to specify "do not cache" to the client's     * browser.     * @param interval time for the client brower to cache the response, in millis.     * Note that the HTTP protocol specifies precision of 1 second for caching.     * @see #CLIENT_CACHE_INTERVAL     * @see #setCaching()     */    protected void setCaching(long interval) {      if (interval <= 0) {        resp.setHeader("Pragma","no-cache");        resp.setHeader("Cache-control","no-cache");        resp.setDateHeader("Expires",System.currentTimeMillis());      } else {        resp.setHeader("Cache-control","private");        resp.setDateHeader("Expires",System.currentTimeMillis() + interval);      }    }    /*     * Sets the client browser caching headers for the HTTP response.     * @see #CLIENT_CACHE_INTERVAL     * @see #setCaching(long)     */    protected void setCaching() {      setCaching(CLIENT_CACHE_INTERVAL);    }      protected void showHTMLHeader()      throws IOException, ServletException {      setCaching();      // Show HTML header.      out.print("<!DOCTYPE HTML PUBLIC");      out.println(" \"-//W3C//DTD HTML 4.01 Transitional//EN\"");      out.println(" \"http://www.w3.org/TR/html4/loose.dtd\">");      out.println("<html>");      out.println("<head>");      out.print("<meta http-equiv=\"Content-type\" content=\"");      out.print("text/html; charset=");      out.print(page_output_charset);      out.println("\">");      showStyleSheet();      out.print("<title>");      showTitle();      out.println("</title>");      // contents of this generated page should not be spidered      out.println("<meta name=robots content=none>");      out.println("</head>");    }    protected final int MODE_QUERY_RESULTS = 0;    protected final int MODE_TOPIC_BROWSE = 1;    protected final int MODE_INDEX_PAGE = 2;    protected int getPageDisplayMode() {      if (!isEmpty(qtxt) || !isEmpty(fs))        return MODE_QUERY_RESULTS;      if (!isEmpty(ct) && !ht.equals(ct))        return MODE_TOPIC_BROWSE;      return MODE_INDEX_PAGE;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -