SearchResultsTable

    目次
    ヘッダーがありません
    /**
     * 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));
    */
    
    タグ (タグ編集)
    • No tags

    ファイル 0

     
    あなたはコメントを投稿するには ログイン しなければなりません。
    Powered by MindTouch Core