How to apply the filtering conditions obtained from the `archiveFilters` to the `archiveList` interface for document filtering?

Calendar 👁️ 66

In AnQi CMS, implementing the dynamic filtering function of documents is a key step to improve the user experience of the website. This usually involves close collaboration between two core interfaces:archiveFiltersUsed to obtain the available filtering conditions andarchiveListIt is responsible for retrieving and displaying the corresponding document list based on these conditions.A deep understanding of how they work together can help us build a flexible and user-friendly content filtering mechanism for the website.

Understand the filtering mechanism: from definition to discovery

Imagine, your website has published a large amount of articles, products, or other content, and users may want to search for information of interest based on custom attributes such as 'city', 'education', 'product category', and so on.The design philosophy of AnQi CMS is one that allows you to define various custom fields for different content models (such as article models, product models).Even better, you can set these custom fields to 'filterable', so they can serve as a basis for users to filter content.

So that the front-end application knows what filtering conditions are available, Anqi CMS providesarchiveFiltersInterfaceThis interface plays the role of a "filter condition discoverer".

When you callarchiveFiltersthe interface, you need to provide it with amoduleIdClarify the filter conditions you want to retrieve for which content model. For example, if you have a product model with ID 1, you want to retrieve the filter conditions for all products under this model, you should pass inmoduleId=1.

In the returned data of the interface, you will see a list, where each list item represents a selectable dimension. Among them:

  • nameThis is the Chinese name of the filtering condition, which is convenient for users to understand, such as 'City' or 'Education level'.
  • field_nameThis is the internal field name of this filtering condition in the system (for examplecityorcertificateIt is used as a parameter name in subsequent filtering, very critical.
  • items: It is a list containing specific filtering options, each with onelabelChoose from cities like Beijing and Shanghai.

ByarchiveFiltersYour front-end application can dynamically retrieve all available filter categories and their specific options under the current content model, thereby flexibly rendering filter menus such as dropdowns, checkboxes, or tag clouds.

Apply filter condition: convert discovery to filter

Once your front-end page passesarchiveFiltersThe interface successfully retrieved and displayed all available filtering conditions and options, allowing users to make selections from these options. Next, the user's selection needs to be applied to the document list, which is wherearchiveListInterfaceTook the stage.

archiveListThe interface is a powerful tool used by AnQi CMS to obtain a document list.It supports various parameters to control document retrieval, including by category ID, keywords, sorting methods, etc.And for the custom filtering we are discussing here,archiveListProvided a flexible mechanism named "Custom Filter Parameter".

The core operation here is that you need toarchiveFiltersThe interface returnsfield_namefor examplecity) as the parameter key (key), and select theitemsfrom the selected one.labelThe value (e.g., 'Beijing') as the parameter value (value), added in the form ofkey=valueto thearchiveListrequest.

For example, if the user selects 'City' as 'Beijing' on the front-end page, then when constructingarchiveListyou need to add it to the URL query parameters.city=北京If the user also selects a "degree" of "Bachelor's", then the request parameters will becomecity=北京&certificate=本科.

At the same time, when callingarchiveListIt is recommended to use the interface for filtering,typethe parameter topageThis not only allows you to get the total number of documents needed for pagination, but also ensures that the custom filtering parameters can take effect correctly.

The actual application scenario and operation steps

In actual project development, this process usually operates like this:

  1. Initialization of page loading:When the user first visits the list page, the front-end calls first:archiveFiltersInterface, pass the corresponding current list pagemoduleId.
  2. Dynamic rendering filter:Based onarchiveFiltersThe data returned, the front-end dynamically presents the filtering dimensions such as "city", "education", and their options on the page, which may be a sidebar filter menu or a filter bar at the top of the page.
  3. The user selects a filter condition:The user clicks or selects one or more filter options on the page.
  4. BuildarchiveListRequest:The front-end captures the user's selection, based onfield_nameandlabelConstruct a new URL query parameter. For example, if the user selects "Beijing" and "Bachelor's Degree", the request parameters may become?moduleId=1&type=page&page=1&limit=10&city=北京&certificate=本科.
  5. Send the request and update the list:The front-end uses these parameters to callarchiveListthe interface. After the back-end receives the request, it willmoduleId/type/page/limitas well as the custom filtering parameters we pass in (such ascityandcertificate) to filter documents and return the list of documents that meet the conditions and the total number.
  6. Display the filtered results:After the front-end receives new data, it updates the document list on the page, and may also update the document count next to the filter conditions (if necessary).

In this way, the Anqi CMS'sarchiveFiltersandarchiveListThe interface works collaboratively, providing a powerful and flexible dynamic filtering capability for website content, greatly improving the efficiency of users browsing and searching for information.


Frequently Asked Questions (FAQ)

Q1: Why do I callarchiveFiltersWhen interfacing, it returns thedataThe array is empty or there are very few filtering conditions?A1: This usually has several reasons. First, make sure you pass themoduleIdIt is correct, and the corresponding content model is indeed configured with custom fields in the Anqiy CMS backend.Secondly, most importantly, you need to explicitly check the fields you want to use as filter conditions in the custom field settings of the content model.If the field is not set to filterable,archiveFiltersThe interface will not return them.

Q2: Can I apply multiple filter conditions at the same time? For example, both the document where 'City' is 'Beijing' and the document where 'Education' is 'Bachelor'?A2: Absolutely. Anqi CMS'sarchiveListThe interface supports receiving multiple custom filter parameters. You just need to specify differentfield_name=labelAdd the key-value pair as a separate query parameter to the request URL. For example:/api/archive/list?moduleId=1&type=page&city=北京&certificate=本科.

Q3:archiveFiltersThe interface returnsitemsin the list oftotalWhat is the use of the field? Why is it always 0 in the example?A3:itemsin the list oftotalThe field is designed to indicate how many documents meet the criteria under the current filtering option. However, inarchiveFiltersIn the default implementation of the interface, it is mainly responsible for providing the *available* filter options itself, and does not count the number of documents under each option in real time, so it is usually set to 0 by default.If you need to display the number of documents corresponding to each filter option on the front end (for example, "Beijing (123)", "Shanghai (45)"), you may need to perform statistics separately on the front end or consider custom development on the back end to provide this aggregated data.

Related articles

Why does the `total` field often display as 0 in the `archiveFilters` returned data? What is its real purpose?

When using AnQi CMS for website content management, we often deal with various API interfaces.Among them, the `archiveFilters` interface is an important tool for obtaining document filtering conditions.Many users notice that when using this interface, the `total` field in the `items` list of the returned data always displays as `0` for each filter option (such as `Beijing` and `Shanghai` under `City`).This may be confusing: Since it's a 'quantity', why is it `0`? This

2025-11-09

How to interpret the `items` array in the filtering conditions API, used to build the front-end filter?

In modern web design, the content filtering feature has become an important part of improving user experience and content discoverability.A well-designed filter can help users quickly locate the information they are interested in, whether it is products, articles, or any other form of content.For Anqi CMS, the provided filtering conditions API (/api/archive/filters) is the foundation for building such frontend filtering functions.Especially the `items` array in the response data is the key to understanding and implementing dynamic filtering.

2025-11-09

What do the `name` and `field_name` in the `archiveFilters` interface represent?

During the development and content management process of Anqi CMS, we often need to handle document filtering and display.The `archiveFilters` interface was born for this purpose, it provides the ability to dynamically obtain filtering conditions.Understand the `name` and `field_name` fields in the returned data, which are crucial for building flexible and versatile front-end filtering functions.

2025-11-09

In AnQi CMS, what is the role of the `moduleId` parameter in the `archiveFilters` interface?

When using AnQiCMS to build a website, we often need to provide flexible filtering functions for different types of content so that visitors can quickly find the information they need according to their needs.The `archiveFilters` interface was born for this purpose, it can help us get the document filtering conditions.And in this interface, the `moduleId` parameter plays a crucial role.### `archiveFilters` interface's `moduleId`

2025-11-09

How to configure custom fields in Anqi CMS so that they can be used as filter conditions?

In AnQi CMS, configuring custom fields as filter conditions is a very practical feature to make your website content more dynamic and interactive.It can help users quickly find the content they need based on specific attributes, thereby significantly improving the user experience of the website.Next, let's learn how to implement this feature in AnQi CMS. ### Custom Field: The "Alive" Tag of Content Firstly, we need to understand what a custom field is.

2025-11-09

What is the difference between the interface for getting document parameters (`archiveParams`) and the interface for getting document parameter filtering conditions (`archiveFilters`)?

When using AnQiCMS for website content management, we often need to deal with document-related API interfaces.Among them, the interface names `archiveParams` and `archiveFilters` sound similar at first glance, and they are both related to Understanding the differences between them can help us develop and manage websites more efficiently.

2025-11-09

In what scenario should `archiveFilters` be used instead of `archiveParams`?

During the development and content management of Anqi CMS, we often need to obtain relevant information about documents (Archive).Among them, `archiveFilters` and `archiveParams` are two API interfaces closely related to custom fields, but their design purposes and application scenarios are different.Understanding the difference between them can help us build website features more efficiently and enhance the user experience.First, let's briefly understand the core functions of these two interfaces.

2025-11-09

Does the `archiveFilters` interface support retrieving filtering conditions based on a specified category ID?

When using Anqi CMS for website content management, flexibly obtaining and displaying filter conditions is a key link in improving user experience.Many friends may wonder when using the `archiveFilters` interface whether it supports retrieving filtering conditions based on specified category IDs to provide more accurate filtering options for different categories.Today, let's delve deeply into this issue.

2025-11-09