|
|
SearchResultsTableFrom $1Table of contentsNo headers/**
* Search Results Table
*
* @param uri $uri - base uri (default: page.uri)
* @param map $params - query params to preserve
* @param str $term - term to search for
* @param str $default - default sort (default: nil)
* @param num $perPage - results per page (default: 30)
*/
var uri = $uri ?? page.uri;
var params = $params ?? {};
var searchTerm = $term ?? "";
var defaultSort = $default;
var resultsPerPage = $perPage ?? 30;
var dateSince = $dateSince; // nullable
var dateBefore = $dateBefore ?? date.now;
var since = date.Format(dateSince, "yyyyMMddHHmmss");
var before = date.Format(dateBefore, "yyyyMMddHHmmss");
// compute the page
var currentPage = __request.args.page ?? 1;
if (currentPage < 1) {
let currentPage = 1;
}
var currentSort = __request.args.sortBy ?? defaultSort;
// fetch the results
var queryResults = searchanalytics.queries{
groupby: "query",
term: searchTerm,
offset: (currentPage - 1) * resultsPerPage,
limit: (resultsPerPage + 1),
since: since,
before: before
};
var queryCount = #queryResults.queries;
var moreResults = (queryCount > resultsPerPage);
if (moreResults) {
let queryCount -= 1;
}
// Paging
Template('MindTouch/Reports/Controls/SearchPagingNext', {
uri: uri,
params: params,
next: moreResults,
showing: queryCount,
perPage: resultsPerPage
});
<table class="table mt-report-results">
Template('MindTouch/Controls/TableSortHeading', {
uri: uri,
params: params,
columns: [
{width: "", label: wiki.localize("MindTouch.Reports.data.query")},
{width: "25", label: wiki.localize("MindTouch.Reports.data.searched")},
{width: "125", label: wiki.localize("MindTouch.Reports.data.clicked")},
{width: "25", label: wiki.localize("MindTouch.Reports.data.date.search")}
],
//default: defaultSort,
enabled: (queryCount > 0)
});
if (queryCount < 1) {
<tr>
<td colspan="4">
wiki.localize("MindTouch.Reports.data.empty")
</td>
</tr>
}
foreach (var queryResult in queryResults.queries where __index < queryCount) {
<tr class=("row-" .. (__count % 2))>
<td>
// @TODO guerrics: replace terms with real query id
<a href=(uri & params & {query: queryResult['sorted-terms']})>
queryResult['sorted-terms'];
</a>
</td>
<td>queryResult.count</td>
if (#queryResult['selected-results'] == 0) {
<td class="col-3">"--"</td>
} else {
Template('MindTouch/Reports/Controls/TableCellPage', {
id: queryResult['selected-results'][0].pageid,
class: "col-3"
});
}
<td>"--"</td>
</tr>
}
</table>
// Paging
Template('MindTouch/Reports/Controls/SearchPagingNext', {
uri: uri,
params: params,
more: moreResults,
showing: queryCount,
perPage: resultsPerPage
});
/*<h4>"Raw output"</h4>
web.pre(json.format(queryResults));
*/
Tags: (Edit tags)
|
Powered by MindTouch Core |
Disclaimer: Vespa Labs contains information that is VERY likely to wreck your scooter and possibly yourself both intentionally (i.e. gaining more peformance while sacrificing reliability + safety) and unintentionally (i.e. misleading or incorrect information). Vespa Labs is only a wiki and intended as a dumping ground for information and not as a properly reviewed source. The same disclaimers that wikipedia.org use apply to Vespa Labs. The short version is use information at your own risk, both information on the main wiki and in the user areas are intended to be used only as "thought provoking" for someone that knows what they are doing. If you try to implement a "thought" Vespa Labs is not reponsible and if something goes wrong we hope that you live and update the offending information with corrections to warn others.
Vespa Labs is an international site and therefore may contain information that is not road legal in some countries/states and may also invalidate insurance policies. Treat all information as experimental and for "race use only" (i.e. not for road use - even if it is implied or explicitly stated). Refer to and adhere to your local road and legal rules, as well as the manufacturers recommendations.