How to display the document list matching the keywords on the search results page?

Calendar 👁️ 62

When visitors come to your website and hope to quickly find the information they need, a highly efficient and accurate on-site search feature is particularly important.AnQiCMS (AnQiCMS) has fully considered this from the beginning, providing you with a flexible and powerful content management and template system, allowing you to easily display a list of documents matching keywords on the search results page.Next, let's take a look at how to implement this feature together.

Understand the search mechanism of Anqi CMS

The AnQi CMS is built with powerful search capabilities, it will automatically index the content you publish.When a user submits a search request on a website, the system will match the user's input keywords with the title, keywords, abstract, and even the content of the document, and return the most relevant document.All these results will be displayed through a dedicated search page template, allowing you to fully control the way they are presented.

First step: Ensure your content is searchable

All efficient searches rely on a high-quality content foundation. When publishing or editing documents in the Anqi CMS backend, please pay attention to the following key information:

FirstlyDocument titleThis is the first window for users and search engines to understand the content theme. The title should be clear, accurate, and include core keywords.

Next isDocument IntroductionIt provides a brief overview of the document, which is also what is usually displayed on the search engine results page. If not filled in, the system will automatically extract the first 150 words of the document content.

Most importantlyDocument keyword. On the 'Add Document' page, you can manually enter or select relevant keywords from the keyword library. It is recommended to use English commas between multiple keywords.,Separate it, this not only helps the internal search of the Aque CMS, but also conforms to the collection habits of search engines, and comprehensively improves the visibility of your documents in various search scenarios.

Step two: Configure your search results page template

In AnQi CMS, the display logic of search results is usually handled by a dedicated template file, which is located in your template directory.search/index.htmlThis template file is the core of your custom search results page layout and style.You can edit it to decide how the search box appears, how the search results list is arranged, and what information each document entry will display, such as thumbnails, titles, descriptions, etc.

Step 3: Use in the template.archiveListLabel to get search results

To besearch/index.htmlThe template displays documents that match the keywords, the core is to use the Anqi CMS providedarchiveListLabel. This label is very flexible and can be used to retrieve various document lists, including our search results.

When you are going toarchiveListlabel'stypethe parameter to"page"It will intelligently recognize the keyword parameters passed in the search form in the URL (usuallyq), and automatically filter and display documents based on these keywords.

Here is a basic example that shows how tosearch/index.htmlis usedarchiveListUse tags to cyclically display the searched documents:

{# 搜索结果页 (search/index.html) #}
<div>
    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <div>{{item.Description}}</div>
                <div>
                    <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    <span>{{item.Views}} 阅读</span>
                </div>
            </a>
            {% if item.Thumb %}
            <a href="{{item.Link}}">
                <img alt="{{item.Title}}" src="{{item.Thumb}}">
            </a>
            {% endif %}
        </li>
        {% empty %}
        <li>
            抱歉,没有找到匹配的文档。
        </li>
        {% endfor %}
    {% endarchiveList %}
</div>

In this code snippet,archiveListTags automatically retrieve search keywords from the current URL, match them, and display 10 results per page. Throughfor item in archivesLoop, you can access the title of each document (item.Title) and link (item.Link), Description (item.DescriptionPlease provide the information, and arrange it according to your design requirements.

Step 4: Add a friendly search form.

To enable visitors to easily input keywords for search, you need to place a search form in a prominent position on the website, such as the header or content area. The purpose of this form isaction="/search"and its text input box'snameattribute must be set toq.

At the same time, you can also make use of to improve the user experience{{urlParams.q}}This variable retains the keywords entered by the user after they submit a search. This way, if the user wants to modify the keywords or perform a second search, they do not have to re-enter them.

This is a simple search form example:

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

Step five: Implement pagination for search results

Pagination is the key to improving user experience when there are many search results. Anqi CMS'sarchiveListThe tag is intype="page"In mode, withpaginationtags perfectly match, allowing for easy pagination.

You just need to specify inarchiveListAfter the tag, addpaginationtag, and specify how many pagination buttons you want to display. For example,show="5"this means that up to 5 page number buttons are displayed.

{# 假设这是接在archiveList标签之后的分页代码 #}
<div>
    {% pagination pages with show="5" %}
        {# 首页 #}
        <a class="{% if pages.FirstPage.IsCurrent %}active{% endif %}" href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
        {# 上一页 #}
        {% if pages.PrevPage %}
        <a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
        {% endif %}
        {# 中间多页 #}
        {% for item in pages.Pages %}
        <a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>
        {% endfor %}
        {# 下一页 #}
        {% if pages.NextPage %}
        <a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
        {% endif %}
        {# 尾页 #}
        <a class="{% if pages.LastPage.IsCurrent %}active{% endif %}" href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
    {% endpagination %}
</div>

BypagesAn object, you can flexibly build the "home page", "previous page", "next page" and middle page number navigation, and add the corresponding style according to the current page state.

Summary

By following these few simple steps, you can build a fully functional, user-friendly search results page on the Anqi CMS website. From keyword filling during content publishing, to the meticulous design of the search page template, to utilizingarchiveListandpaginationThe tag dynamically displays results, Anqi CMS provides intuitive and powerful tools to help you achieve your goals, making your website content easier for visitors to discover and utilize.


Frequently Asked Questions (FAQ)

1. Why are my search results sometimes inaccurate or unable to find certain documents?The accuracy of search results is closely related to the quality of the content you publish and the keywords you set.Please check the accuracy and relevance of the document's title, abstract, and keywords.If the document content is less, it may also affect the search match accuracy.In addition, please ensure that the relevant content has been correctly indexed by the system when the document is published.If you suspect it is an indexing issue, you can try modifying the document and updating the cache to let the system reprocess.

2. Can the URL structure of the search results page be customized?Yes, Anqi CMS supports flexible pseudo-static rule configuration.You can find the 'Static Rules' settings under the 'Function Management' backend, select or customize the URL structure of the search page.For example, you can set it to/search?q=关键词Or a more friendly form. Custom rules need to be operated with caution to ensure they do not conflict with other page rules.

How to adjust the layout and style of the search results page?The layout and style of the search results page are completely controlled by yoursearch/index.htmltemplate files and associated CSS and JavaScript files. You can modify it like other page templates, insearch/index.htmlAdd HTML structure freely, introduce custom CSS styles, even write JavaScript code to achieve richer interactive effects. Anqi CMS's template system is based on Django template engine syntax, providing a high degree of

Related articles

How does AnQi CMS display or hide specific content based on user group permissions?

In daily website operation, we often encounter such needs: some content is intended for everyone to see, while some is only open to specific members, or shows different information for users of different levels.AnQiCMS (AnQiCMS) provides powerful user group permission management features, allowing us to flexibly control the visibility of website content and achieve the 'thousand faces of content'. ### Why do you need to display or hide content by user group?Imagine you are running a website that offers a variety of services, including free basic articles and paid in-depth reports

2025-11-08

How to dynamically display the current year or a specified date on a website?

In website operation, we often need to display some dynamic time information, such as the copyright year at the bottom of the website (such as “© 2023-Current Year”), the publication or update time of articles, or the deadline for specific events, etc.These dynamic dates not only maintain the timeliness of website information, but also improve user experience, and in some cases, are also beneficial for SEO. The AnQi CMS provides a series of flexible template tags that allow you to easily display the current year or a specified date dynamically at any location on the website.We will discuss in detail how to make use of these features.

2025-11-08

How to use the template inheritance mechanism to unify and display the website page structure?

When building a website, maintaining consistent page structure, improving development efficiency, and reducing maintenance costs are key to website operations.AnQiCMS (AnQiCMS) leverages its powerful functionality based on the Django template engine syntax to provide us with an efficient template inheritance mechanism, making it easy to unify and flexibly display the structure of web pages. ### The core concept of template inheritance: building the skeleton of a website Imagine that your website is like a house made up of different rooms. Each room (page) has its unique functions and content, but they share the same foundation

2025-11-08

How to reference and display common code snippets (such as header, footer) in AnQiCMS templates?

It is crucial to maintain consistency in page structure and code maintainability in website construction and content management.For a content management system like AnQiCMS, effectively referencing and managing common code snippets, such as the website header (Header) and footer (Footer), is the key to achieving this goal.Through AnQiCMS's flexible template mechanism, even users with little understanding of technical details can easily implement these features, thus building a website with clear structure and easy maintenance.###

2025-11-08

How to prevent content collection interference code and watermark display in AnQi CMS?

Today, with the increasing richness of digital content, the value of original content becomes more and more prominent, but the problems of content plagiarism and collection that come with it also make many content creators and operators headache.AnQiCMS (AnQiCMS) fully understands this pain point, and therefore built-in strong content protection mechanisms from the very beginning of the system design, including anti-crawling interference codes and image watermark functions.These features are designed to help users effectively defend original copyright, ensure content exclusivity, and thereby enhance content value.

2025-11-08

How to dynamically display the canonical URL corresponding to the current page in the template?

In website operation, maintaining search engine friendliness is one of the key links to improving website visibility.Among them, the 'Canonical URL' plays a crucial role.It acts like a compass for search engines, telling them which page is the main version of the content, thus effectively avoiding ranking fragmentation due to content duplication or similarity.For content operators, correctly setting and displaying standard links is the foundation for ensuring that website content is efficiently crawled and indexed by search engines

2025-11-08

How to safely display HTML tags in a template without being parsed by the browser?

In website content management, we often encounter the need to display HTML code snippets, such as code examples in tutorials, and language annotations in technical articles.However, if the content containing HTML tags is directly output to the page, the browser will parse and render it, rather than displaying it as plain text.This could lead to layout errors on the page, more seriously, if unprocessed user input contains malicious scripts (such as `<script>alert('XSS')</script>`), it can trigger cross-site scripting (XSS) attacks

2025-11-08

How to display custom site parameters on the front-end page?

When operating a website, we often encounter such needs: we need to display some flexible and variable site information on the front-end page, such as the company's establishment year, customer service hotline, promotional slogans for specific pages, or a brief announcement, etc.This information may need to be updated frequently, and it is inefficient and prone to errors to modify the template file each time.Fortunately, Anqi CMS has provided us with a very convenient way to manage and display customized site parameters on the back-end, making content operation more efficient and flexible.

2025-11-08