In Anqi CMS, the flexibility of document content management is a highly valued feature, especially its support for custom fields (reflected in the interface return data)extraSupport for fields (within the brackets) greatly facilitates website operators. When we need to filter and query a large number of documents based on these custom attributes, we naturally think of a key issue: the document list interface of Anqi CMS (/api/archive/listDoes it support complex queries on the returned dataextraCan the field be queried more complexly?
To answer this question, we need to understandextrathe essence of the field and the query mechanism provided by Anqi CMS.
UnderstandingextraField and custom content
In the document details and document list interfaces of AnQi CMS (such as/api/archive/detailand/api/archive/listin the returned data of the})extraA field is a very important component. It is not a fixed data structure, but rather a dynamic one generated based on the custom fields you define in the backend for a specific document model (such as an article model, product model, etc.).
In simple terms, when you add a field named "author" (called by the nameauthor), and a field named "city" (called by the namecityAfter the custom field is added, these fields will appear when the document data is retrieved through the APIextraThe structure is usually{ "field_name": { "name": "字段名称", "value": "字段值", "default": "默认值" } }. This meansextraThe field is an important carrier of personalized content on your website
The query capability of the document list interface
Document list interface of AnQi CMS/api/archive/listIt provides various parameters to filter and sort documents, such asmoduleId(Model ID),categoryId(Category ID),order(Sorting method) as well asqKeyword search) and the like. These are general query methods that can meet most routine needs.
While forextraField query, Anqi CMS adopts a clever and practical method, namely throughCustom Filter Parameterto achieve. The document clearly states:
“Filter parameters are only in list type
type="page"生效 at time, if there are additional automatic configurations in the document, such as configurable fields that can be filtered through these parameters, you can complete parameter-based filtering of the document. For example, if your document has automatic filtering set to gender, with default values of Male, Female, and Confidential, you can filter through the query parameters in the URLgender=男Search the documentgenderThe field is male document content.”
This is the core answer to the problem. This means that you cannot directlyextraThis complete JSON object performs complex queries similar to database statements (such as, queryingextrainvalueall fields containing a specific substring), but you can also handle those that are inThe field is set to "Filterable" in the backgroundPerform an accurate key-value pair matching query. When you add these custom field names as query parameters in the URL, Anqi CMS will filter documents based on these parameters and return a list of matching documents.
How to use custom filter parameters?
- Backend configuration:First, you need to set the custom field that needs to be used for filtering to 'filterable' in the field management of the corresponding document model in the Anqi CMS backend.
- Found filterable fields:If you are unsure which fields are filterable or want to know their
field_name(name of the call) and possible options, you can use/api/archive/filtersInterface. This interface can return all the field information configured as filterable under a specified model, including the field name (name), the calling name (field_name), and the selectable items (itemsThis is very helpful for building dynamic filters on the front-end page. - Initiate a query:After mastering the call names of custom fields, you can use them in
/api/archive/listinterface requests, withfield_name=valueThe form is used as a URL query parameter. For example, if you have a call namedcitycustom field, and you want to query all documents for cities named 'Beijing', you can construct the request parameters ascity=北京.
Summary
Document list interface of AnQi CMSSupportYesextraThe query is performed on the custom fields contained in the field, but this query is not direct operationextraThe complex structure within the field is achieved by using the name of the custom field configured as 'filterable' in the background as a URL query parameter to achieve precise matching.This design ensures the performance and security of the API while also providing sufficient flexibility, allowing website operators to carry out refined content filtering and display based on custom content.
By fully utilizing this mechanism, you can build a rich-featured and user-friendly filtering function on the front-end, which helps users quickly find the specific content they are interested in.
Frequently Asked Questions (FAQ)
Ask: Does the custom field support default filtering in
/api/archive/listthe interface?Answer: No, custom fields do not support filtering automatically by default.You need to clearly check the 'Filterable' option for each custom field that you want to be filterable in the document model management on the AnQi CMS backend.Only after this setting, these fields can be used as custom filter parameters in/api/archive/listused in the interface.Ask: Can I filter
extraThe numeric type in the field performs range queries such as "greater than", "less than", for example, querying documents with a price higher than 1000?Answer: According to the current document description, Anqi CMS's/api/archive/listinterface mainly supports precise matching queries for custom fields (i.e.),field_name=value). It does not directly provide forextraA built-in parameter for querying numeric field types with 'greater than', 'less than', or range queries.If you have this requirement, you may need to consider secondary filtering of data on the front end, or contact the Anqi CMS official for custom development support.Ask: If my custom field is a multi-select type, for example, a document can be associated with multiple tags (in
extraHow can I query documents containing any of the tags, which exist in comma-separated or other forms?Answer: For multi-select custom fields, you can view them through/api/archive/filtersthe interface.items(Filter parameter list) to understand the specific query support methods. In most cases, if a multi-select field is set to be filterable, it may support an exact match of one option, or in some implementations, it allows multiple values to be separated by commas to represent an "OR" relationship (for example, `tags=标签')