๐Ÿ”Ž Site Search

Last updated๏ผš2026-11-25

The system ships with a built-in on-site search page /search, which performs cross-table LIKE retrieval over published news, products, and cases (up to 20 items per type). Admin switch: Settings โ†’ Interactive Features โ†’ Enable "On-site Search" (feature_search=1); when disabled, accessing /search renders the error page error.html (with the message “Search is not enabled”). The page template is templates/search.html and its styling can be changed freely.

๐Ÿ”’ Read-only ยท No Persistence: search is pure query, computed on the fly, never written to the database โ€” no results table is created, and no search history / audit logs are recorded; each request is independent and results are only returned to the current browser.

โฑ๏ธ Rate Limiting: rate-limited by IP, at most 30 requests per 60 seconds; when exceeded, {{.SearchError}} = “Too many requests, please try again later” and the results area is empty. This prevents scripts from hammering the API and dragging down the DB, while being invisible to normal users.

โœ‚๏ธ Keyword Handling: automatically TrimSpaced and stripped of SQL wildcards % / _ (protecting against LIKE injection), truncated to at most 50 characters; an empty keyword returns an empty results area (no error).

๐Ÿ“‹ Search Page Variables

  • {{.Keyword}} The keyword the user entered (already cleaned, already truncated to 50 chars) โ€” text
  • {{.Results}} Results array; per-item fields are listed below under Result Object; an empty array when there is no keyword or when rate-limited โ€” array
  • {{.ResultCount}} Total number of hits (= len(Results)) โ€” number
  • {{.SearchError}} Message shown when rate-limited; normally an empty string โ€” text
  • {{.PageTitle}} Page title, in the form “Search: keyword” โ€” text

Common variables (site name, navigation, SEO, etc.) are the same as the home page; see 02-Common Tags.

๐Ÿงฉ Result Object (inside {{range .Results}})

  • {{.Type}} Content type: ๆ–ฐ้—ป / ไบงๅ“ / ๆกˆไพ‹ (note these are Chinese, not news/product/case) โ€” text
  • {{.Title}} Content title โ€” text
  • {{.URL}} Detail page link (already carries the site prefix, in a form like /news/5.html, determined by the admin “URL Rules”; platform sites standardize on flat nesting + .html suffix) โ€” URL
  • {{.Snippet}} Summary: summary trimmed of whitespace and truncated to 120 characters; shows “Click to view details” when empty โ€” text

๐Ÿ’ป Template Example (already built into the default search.html)

<!-- Search box -->
<form method="get" action="/search">
  <input type="text" name="q" value="{{.Keyword}}" placeholder="Enter keywords to searchโ€ฆ">
  <button type="submit">Search</button>
</form>

{{if .SearchError}}
  <p class="error">{{.SearchError}}</p>
{{end}}

{{if .Keyword}}
  <p>"{{.Keyword}}" found {{.ResultCount}} results</p>
  <div class="results">
  {{range .Results}}
    <div class="result">
      <h3><a href="{{.URL}}">{{.Title}}</a><span class="tag">{{.Type}}</span></h3>
      <div class="snippet">{{.Snippet}}</div>
    </div>
  {{end}}
  </div>
{{else}}
  <p>Please enter keywords to start searching.</p>
{{end}}
๐Ÿ“ API and Scope Notes
Item Description
Request parameter Only ?q=keyword (this is the tenant site engine’s on-site search, unrelated to the platform template marketplace); no type filter, no pagination, no JSON API
Search scope Three types: news / products / cases (single pages not included), at most 20 items per type
Disabled When “On-site Search” is not enabled in the admin, /search renders the error page error.html (with the message “Search is not enabled”)
Result ordering Each type by id DESC (newest first)

Do not confuse this with the platform template marketplace search: the /search?q= in this chapter is the tenant site engine’s on-site search โ€” dynamic query, no persistence; the platform template marketplace search has been changed to /templates/search/<token>.html (form POST โ†’ 303), path-style, without ?. Their code and templates are entirely separate.

[โ† Friend Links](16-friendlink.html) [Multilingual Sites โ†’](18-multilang.html)
This site uses cookies for essential functionality and to improve your experience. See our Privacy Policy.