How to implement keyword search and display results on the document list page?

Calendar 👁️ 75

How to help visitors quickly and accurately find the information they need among the increasingly vast content of a website is the key to improving user experience and website value.AnQiCMS (AnQiCMS) deeply understands the art of content management, providing us with a powerful and flexible keyword search mechanism that allows the document list page to easily implement keyword search and elegantly present the results.

Understand the search core of Anqi CMS:archiveListThe clever use of tags

The core of AnQi CMS's keyword search implementation lies in its powerful template tag system, especiallyarchiveListwith the tag andqThe clever combination of parameters. As the content of our website grows continuously, visitors hope to search quickly through keywords, Anqi CMS can achieve this througharchiveListTags to accurately filter documents containing specific keywords and display them on the search results page.This process is very intuitive for template developers, and can be implemented without complex programming.

Build a user-friendly search form

Firstly, we need to provide a search entry on the website, which is usually a search box. Building such a search form in Anqi CMS is very simple, it is a standard HTML<form>Labels. To make search engines friendly and facilitate user sharing of search results, we usually chooseGETa method to submit the form.

This is an example of a typical search form, you can place it at the top of the website, in the sidebar, or any place where you want to provide a search function:

<form method="get" action="/search">
    <div>
        <input type="text" name="q" placeholder="请输入搜索关键词" value="{{urlParams.q}}">
        <button type="submit">搜索</button>
    </div>
</form>

In this form,action="/search"indicated the URL path that the search result page usually corresponds toinputelementname="q"is a key point that tells Anqi CMS to use the text entered by the user as the search keyword.value="{{urlParams.q}}"This part is a small trick, it allows the search box to automatically display the user's last input keyword on the search results page, greatly enhancing the user experience.

Display search results on the document list page

After the user submits the search form, the website will jump to/searchpage. On this page, the corresponding template file (usuallysearch/index.htmlorsearch.html) needs to be used.archiveListTag to get and display search results.

archiveListTag throughtype="page"Parameter to enable pagination mode and through.limitParameter defines the number of documents to display per page. More intelligent is that if the URL carries.q=关键词.archiveListThe tag will automatically capture and use this keyword to search, without the need for us to write additional code in the template to parse URL parameters.

This is an example of the template code displayed on the search results page:

<div>
    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
        <article class="search-result-item">
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description}}</p>
            <div class="meta-info">
                <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </div>
            {% if item.Thumb %}
            <div class="thumbnail">
                <a href="{{item.Link}}">
                    <img alt="{{item.Title}}" src="{{item.Thumb}}">
                </a>
            </div>
            {% endif %}
        </article>
        {% empty %}
        <div class="no-results">
            抱歉,没有找到与“{{urlParams.q}}”相关的结果。请尝试其他关键词。
        </div>
        {% endfor %}
    {% endarchiveList %}

    {# 分页导航区域 #}
    <nav class="pagination-area">
        {% pagination pages with show="5" %}
            <ul>
                <li class="page-info">总计 {{pages.TotalItems}} 条结果,共 {{pages.TotalPages}} 页</li>
                <li><a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a></li>
                {% if pages.PrevPage %}
                <li><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
                {% endif %}
                {% for item in pages.Pages %}
                <li><a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                <li><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li>
                {% endif %}
                <li><a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a></li>
            </ul>
        {% endpagination %}
    </nav>
</div>

In this template code, we did several important things:

  1. {% archiveList archives with type="page" limit="10" %}This line of code indicates that the system retrieves the document list in paginated mode, displaying 10 items per page.archivesis a custom variable name used to store the document data found.
  2. {% for item in archives %}Loop through each search result.itemThe variable represents the current document, from which we can obtain the document'sTitle(Title),Link(Link),Description(Description),Thumb(thumbnail) and other information.
  3. {% empty %}Block: This is a very practical function of Anqi CMS template tags. WhenarchiveListNo documents matching the criteria were found.emptyThe content within the block will be displayed instead of a blank page, thus providing a friendly 'no results' prompt.
  4. {% pagination pages with show="5" %}: To allow users to browse multiple pages of search results, we combinedpaginationtags. It will be based onarchiveListThe tag returns pagination data, automatically generating 'Home', 'Previous Page', 'Next Page', and the navigation links of the middle page numbers.show="5"Specify up to 5 page number buttons.

Suggestion for optimizing search experience

  • Keyword retention:As mentioned before, in the search form'sinputelement usagevalue="{{urlParams.q}}"Let users see the keywords they entered previously on the search results page, convenient for modification or searching again.
  • No results feedback:Make full use ofarchiveListlabel's{% empty %}Block, provide users with clear and friendly no result prompts, and suggest trying other keywords or browsing other content.
  • SEO optimization:The TDK (Title, Description, Keywords) on the search results page is also worth paying attention to.Although the TDK tags of AnQi CMS are default served for articles, categories, single pages, etc., we can make the TDK of the search result page more targeted by customizing templates or combining backend settings, such as integrating search keywords into the page title to enhance the search engine's understanding of the search result page.

The keyword search function of Anqi CMS is not only easy to implement, but also seamlessly integrated with built-in templates and SEO functions, providing website visitors with an efficient way to discover content and website administrators with flexible content presentation capabilities, which is a way to improve

Related articles

How to filter and display a document list based on specific recommendation attributes (such as 'Headline', 'Recommendation')?

The flexible application of content recommendation properties in AnQiCMS is a key link in enhancing the visibility and user experience of website content.Whether you want to highlight important news on the homepage or recommend selected content in specific sections, AnQiCMS provides a convenient and efficient solution.This article will delve into how to filter and display document lists based on specific attributes such as 'Headlines' and 'Recommendations', helping you better manage and present website content.### Part One: Understanding Recommendation Properties and Their Settings Recommendation properties are a very practical feature in the AnQiCMS content management system

2025-11-08

How to call and display the data of the custom model field in the document?

In Anqi CMS, the flexible content model is one of its core strengths, allowing us to create various information carriers such as articles, products, and more according to different business needs and define unique properties for them.How to present the data of these customized fields in the website front-end after we have set them for the document is a major concern for many users.This article will provide a detailed explanation of this process, helping you easily master the custom model fields of Anqi CMS. ### Understanding the Value of Custom Model Fields Firstly, let's clarify the importance of custom model fields.

2025-11-08

How to display the titles and links of the previous and next documents on the document detail page?

In website content operation, it is crucial to provide readers with a smooth reading experience.If a user finishes reading a document and can easily navigate to the previous or next related content, it not only effectively extends the user's stay on the website and increases page views, but also helps search engines better understand the structure and content relevance of the website, thereby having a positive impact on SEO.AnQiCMS (AnQiCMS) has fully considered this point in the design of template functions, providing simple and powerful tags, making it easy to display the title and link of the previous and next documents on the document detail page

2025-11-08

How to display a list of recommended documents related to the current document on the document detail page?

In website content operations, providing users with relevant recommended content not only effectively enhances the depth and duration of page browsing, but also optimizes user experience, indirectly assisting in the SEO performance.In AnQiCMS (AnQi Content Management System), implementing this feature is flexible and direct.Next, we will discuss how to seamlessly integrate and display the recommended document list closely related to the current document on the document detail page. ### Core Value: Why should recommended documents be displayed on the document detail page?

2025-11-08

How to implement multi-condition (such as custom parameters) filtering function on the document list page?

In AnQi CMS, implementing multi-condition filtering functionality on the document list page, especially filtering based on custom parameters, is crucial for improving user experience and helping users quickly find the content they need.AnQi CMS with its flexible content model and powerful template tag system makes this feature highly efficient and intuitive.The entire process can be divided into several core steps: First, define your content model and custom filter fields in the background;Secondly, build the display interface for the filtering conditions in the template; finally, present the filtering results in the document list using list tags.--- ### One

2025-11-08

How to set pagination for a document list and display page navigation?

In modern website operations, setting up pagination for content lists is almost indispensable.It can not only significantly improve the user's browsing experience, avoid the slow loading caused by the long content of a single page, but also help search engines better crawl and index the website content.For friends using AnQi CMS, implementing pagination for the document list and displaying page navigation is a very intuitive and powerful feature.Our AnQi CMS provides flexible template tags, allowing full control over content display.To set pagination for the document list and display page navigation in a friendly manner

2025-11-08

How to display the name of a specified category

Flexible display of category names in AnQiCMS: A comprehensive template call guide Content categories are the core of the website structure, not only helping to organize and manage massive information, but also guiding users to browse the website and improve the user experience.Whether it is an article list, product details, or side navigation, clearly displaying category names can make the content of your website more organized.

2025-11-08

How to define a string array directly in the AnQi CMS template?

In AnQi CMS template development, we often encounter the need to display some list data on the page, such as navigation menus, category tags, or some fixed options.When this data is not suitable for dynamic retrieval from the backend database, or when we just need a simple and fixed set of strings, defining a string array directly in the template is very convenient and efficient.Our Anqi CMS provides a flexible way to handle such requirements based on the Django template engine syntax.

2025-11-08