SearchQueriesTable

    Table of contents
    No 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 preserve = $params ?? {};
    var searchTerm = $term ?? "";
    var defaultSort = $default;
    var resultsPerPage = $perPage ?? 30;
    
    var dateSince = $dateSince; // nullable
    var dateBefore = $dateBefore ?? date.now;
    
    // 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: dateSince,
        before: dateBefore
    };
    
    var queryCount = #queryResults.queries;
    var moreResults = (queryCount > resultsPerPage);
    if (moreResults) {
        let queryCount -= 1;
    }
    
    // Paging
    Template('MindTouch/Reports/Controls/SearchPagingNext', {
        uri: uri,
        params: preserve,
        next: moreResults,
        showing: queryCount,
        perPage: resultsPerPage,
        showingKey: "MindTouch.SearchAnalytics.paging.results"
    });
    
    <table class="table mt-report-results">
        Template('MindTouch/Controls/TableSortHeading', {
            uri: uri,
            params: preserve,
            columns: [
                {
                    width: "300",
                    label: wiki.localize("MindTouch.SearchAnalytics.data.query")
                },
                {
                    width: "25",
                    label: wiki.localize("MindTouch.SearchAnalytics.data.hits"),
                    class: "data-type-numeric"
                },
                {
                    width: "",
                    label: wiki.localize("MindTouch.SearchAnalytics.data.date.search"),
                    class: "data-type-datetime"
                },
                {
                    width: "",
                    label: wiki.localize("MindTouch.SearchAnalytics.data.clicked")
                }
            ],
            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>
                if (#queryResult.sortedterms) {
                    <a href=(uri & preserve & {term: searchTerm, query: queryResult.sortedterms})>
                        queryResult.sortedterms;
                    </a>
                } else {
                    <em>wiki.localize("MindTouch.SearchAnalytics.terms.none")</em>
                }
                </td>
                <td class="data-type-numeric">
                    queryResult.count
                </td>
                <td class="data-type-datetime">
                    Template("MindTouch/Controls/DateTime", [queryResult.datesearched, "datetime"]);
                </td>
                if (#queryResult.selectedresults == 0) {
                    <td>"--"</td>
                } else {
                    Template(
                        "MindTouch/Reports/Controls/TableCellResult",
                        queryResult.selectedresults[0]
                    );
                }
            </tr>
        }
    </table>
    
    // Paging
    Template('MindTouch/Reports/Controls/SearchPagingNext', {
        uri: uri,
        params: preserve,
        more: moreResults,
        showing: queryCount,
        perPage: resultsPerPage,
        showingKey: "MindTouch.SearchAnalytics.paging.results"
    });
    
    // debugging
    //web.pre(json.format(queryResults));
    Tag page (Edit tags)
    • No tags
    Page statistics
    478 view(s), 1 edit(s) and 4085 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments