๐ Site Search
Last updated๏ผ2026-11-25
๐ On-site Full-text Search
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 +.htmlsuffix) โ 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)
CloudSite SaaS