When using AnQi CMS for website content management, we often deal with various API interfaces. Among them,archiveFiltersThe interface is an important tool for obtaining document filtering conditions. Many users notice that in the returned data of this interface,itemsThe value of each filtering parameter option (such as "Beijing", "Shanghai" under totalalways displayed as0This may be confusing: why is it called "quantity" when0what? What istotalthe actual use of this field?

To understandarchiveFiltersin the interfacetotalwhy is this field often displayed as0And its actual meaning, we need to analyze from the design purpose and actual application scenario of the interface.

first, archiveFiltersThe core purpose of the interface is to provide filterable parameters under a specific module.Parameter definitionandOptions list. It is like a 'filter menu' that tells the front-end page which filtering dimensions (such as 'city', 'education') are available, as well as the specific options under each dimension (such as 'city' includes 'Beijing', 'Shanghai', etc.).Its main function is to help developers build dynamic filtering interfaces, such as generating dropdown boxes, radio buttons, or checkboxes on the page.

Check carefullyarchiveFiltersThe returned data example, as we can see:

{
  "name": "城市",
  "field_name": "city",
  "items": [
    {
      "label": "全部",
      "total": 0
    },
    {
      "label": "北京",
      "total": 0
    },
    // ...
  ]
}

HeretotalThe field is indeed constant0This is becausearchiveFiltersThe design初衷 is to provide a lightweight, rapid-response filtering metadata.If this interface calculates the number of documents under each filtering option (such as the city of 'Beijing') in real-time every time it is called, then in the case of large data volumes or complex filtering conditions, each request will put a huge pressure on the database, causing the interface response to slow down, which seriously affects the user experience.Taking into account that a front-end page may need to load multiple filters, this real-time counting is unnecessary overhead in most cases.

Therefore,archiveFiltersoftotalThe field in this context is not used to indicate the actual number of the current filtering option, but rather as areserve fieldor in other wordsplaceholderIts real purpose is to inform the interface consumer, here in the futurePossibleIt is used to convey quantity information, or it may have a non-zero value under certain specific configurations, but in the default and general case, it is set to0To ensure the performance and response speed of the interface. It merely defines the data structure without providing dynamic business statistics.

So, if we need to know how many documents are under a certain filter condition, what should we do? At this point, we need to combinearchiveListthe interface to use.archiveListThe interface is used to retrieve a list of documents, it supports passing various filtering parameters, including fromarchiveFilterscustom filtering fields obtained (such ascity/certificate). What's more, when you callarchiveListWhen interfacing, if you settypethe parameter topageit will include atotalfield, thistotalfield indicatesunder the current filtering conditionsThe total number of documents matched.

For example, if you want to know how many documents a city like 'Beijing' has, you should do this:

  1. Firstly, go througharchiveFiltersGet the 'City' filter.field_name(i.e.),cityAnd optionslabel(i.e.),北京)
  2. Then, callarchiveListInterface, pass inmoduleIdAnd bring alongcity=北京Parameters, while settingtype=page. For example:{域名地址}/api/archive/list?moduleId=1&city=北京&type=page
  3. archiveListIn the returned result of the interface, the top-leveltotalfield will display the number of documents found under the condition of "Beijing".

This design pattern effectively separates the function of 'getting the definition of filtering conditions' and 'getting the content and quantity under specific conditions', ensuring the single responsibility and efficient operation of each interface.archiveFiltersFocuses on providing filtering rules, andarchiveListthen responsible for providing the actual content and its total.

In summary,archiveFiltersThe interface returns data intotalthe field often displayed as0It is not because there is no content, but because it does not undertake the task of real-time statistics, its real purpose is as part of the data structure, reserved for future possible expansion, and maintains the interface's simplicity and efficiency in the current version. We need to utilizearchiveFiltersBuild a filter interface and combinearchiveListInterface to get the actual number of documents under specific filter conditions.


Frequently Asked Questions (FAQ)

Q1:archiveFiltersthe interface intotalThe field is always0Is it because my website doesn't have content or there is a problem with the configuration?A1: No.archiveFiltersthe interface intotalthe field often displayed as0Is an Anqi CMS design option, aimed at providing the basic definition of filtering conditions, rather than counting the number of documents under each option in real time, this is done to ensure the response speed of the interface.This has nothing to do with the correctness of your website content or configuration.

Q2: How can I display the current number of documents for each filter option (such as 'Beijing') in the filter interface?A2:archiveFiltersThe interface itself does not provide the real-time count of each option. If you need to display such a count on the front end, you need to combinearchiveListInterface. You can call it once for each filtering option (such as “Beijing”, “Shanghai”) separatelyarchiveListInterface, pass the corresponding filtering parameters (such ascity=北京Set it uptype=page, then obtainarchiveListreturnedtotalField to get the number of documents under this option. But please note that this may increase the server request pressure.

Q3:archiveFiltersThe interface returnsfield_nameWhat is the use?A3:field_nameIt is a very critical field that indicatesarchiveListwhich parameter name should be used when calling the interface to apply filtering. For example, ifarchiveFiltersit returned afield_nameWithcityThe filter, then when the user selects "Beijing", you shouldarchiveListadd to the request parameterscity=北京To get the corresponding data. It is the bridge connecting the selection interface with the actual data query.