When filtering content by custom field, the condition fails and returns all data, which layer to check first
When filtering content by a custom field and the condition fails, it returns all data. Which layer should be checked first? Check if the condition has truly entered the query, not the data itself.The characteristic of this kind of failure is that 'no error is reported but the wrong result is obtained', the page renders normally, and the list just becomes longer, so the data is not **the suspect.The feasible sequence is threefold: whether the field is allowed to participate in filtering, whether the matching method will enlarge the scope, and whether the cache has reused the previous result without conditions.The PbootCMS program fixed three related issues at the same time in the update records of V3.2.20 - the filtering failure of the extended field returning unfiltered full data, the error of the front-end query when using the extended field in sorting and filtering with tag conditions, and the expanded range caused by the short value hitting the long value. These three items basically cover the location where problems may occur at this level.
Why is a failed condition more dangerous than an error
The error will stop the problem in place: request failed, log has direction, page has hints. The condition failure will not, it returns a reasonable-looking result, but this result includes entries that should not have appeared.There are two directions of risk. For content display, filtering failure means that content within a limited range appears in the public list; for interface calls, unfiltered full data means that the volume of response suddenly increases, and the data counted by the caller according to the number of returned items also becomes distorted.The most麻烦 is that it will not naturally expose: the data always returns, there is no abnormality in the monitoring, and often it is found by manual verification. So, this kind of problem should be discovered by active inspection - request once with conditions and once without conditions, and compare whether the result set is really reduced.
**Layer: Field name and the range that can be filtered
The custom field is hung on the content model, and the fields in the model are divided into two categories: those participating in indexing and structural definition, and those stored only as additional information. The second category often cannot directly enter the filtering conditions, and there are two choices when writing into the query - to report an error or to silently ignore the condition;The danger lies in the latter, ignoring it after the query conditions degrade to 'unconditional list retrieval', which exactly corresponds to the phenomenon of returning all data. In that PbootCMS fix, there is also an easily overlooked description: the unified search, filtering, and available field range of the list field.This means that the definition of the same field in three different scenarios originally allowed different sets, which led to the loss of conditions on some paths. When troubleshooting, check in this order: whether the field is defined on the current content model, whether the spelling and case of the name match, whether the field is declared as filterable, and whether the entry point allows this type of field.AnQiCMS (AnQi CMS) supports a flexible content structure with custom content models, fields need to be explicitly set to participate in filtering and sorting; if this step is not set, it is as if the condition is dropped at the entrance.
Second layer: matching method to expand the range
The condition has entered, and it may match wider than expected. The most common two are: short value matches long value and wildcard not escaped. When field values are compared in an inclusive manner, a short value will match all long values containing this text, and the number of items looks normal but the content is incorrect;Directly拼进用户输入到模糊匹配的模式中,输入中的百分号或下划线被视为通配符处理,匹配范围随之扩大,在极端情况下等于筛选了一个空条件。The method of judgment is very direct: take a long string that will not appear in any content as a condition. If data is still returned, it means that the condition has been spliced into the pattern rather than compared by value.The same logic also affects search, which is why that update record included the reasons for the single-column entries such as 'Short value hit in extended field search' and 'Expanding matching range when keyword contains percentage sign or underscore'.
| Symptoms | The first place to check | Fast verification | The conclusion points |
|---|---|---|---|
| The number of returned items is consistent with that without conditions | Whether the field is allowed to participate in filtering | Change to a field that can be filtered for the request | Conditions are silently ignored at the entrance |
| The number of items is reduced but the content is incorrect | Matching method | Request once with the full value and once with the partial value | Inclusive matching widens the range |
| Results increase significantly when special characters are entered | Pattern concatenation | Check the result when entering a percentage sign or underscore | Wildcard characters are not escaped |
| Fail only on some pages | Caching and query assembly | Request directly once, bypassing the cache | Used the result without conditions |
Third level: Caching reuse and document status
The first two layers have passed, and what remains are time and status categories. The problem with caching is that the conditions are not attached to the key: an unconditional list result is written to the cache, and subsequent requests with conditions hit the same key, returning the full data from the last time.This phenomenon has a distinct characteristic - the first request is correct, and then it is sometimes correct and sometimes returns all, and it is related to time. The verification method is to bypass the cache and request once directly, if the result is correct immediately, the problem lies in the composition of the key.Another type is ignored by document status: the content itself is divided into several statuses such as formal documents, drafts, pending publication, and recycle bin, the contents in the recycle bin do not belong to physical deletion, and when there is no status constraint in the conditions, items that should not appear will be returned together.When checking, separate the 'fields to be filtered out' and 'entries that should not appear', the former is a condition issue, and the latter is mostly a status issue. The source of values also needs to be checked together, manage SEO keywords centrally, and align the word list with the actual stored field values when using it as a filter value. Inconsistent writing also manifests as not being able to filter anything out.
Common questions
Question: Why not make it report an error directly?Answer: An error would affect the online display, and implementers tend to be lenient. However, silently ignoring conditions is more dangerous than failure, and a better compromise is to return the result normally while recording a warning that a condition has been discarded.
Question: In what order should the three levels be checked for the fastest?Answer: Start from the lowest cost - first compare the difference in existence (level one), then verify the width of the match (level two), and finally bypass the cache (level three). In most cases, the conclusion can be drawn at **Layer.
Ask: Is it normal that the field just added cannot be filtered out?Answer: It may be that the historical content does not have the value of this field. When filtering using equal conditions, empty value entries will not match. In this case, you should first confirm whether the backfill is completed.