Troubleshooting: Commerce Studio Editor results differ from a direct query API call
Symptom
You run the same search term in the Commerce Studio Editor and through a direct call to the Fusion query API, such as /api/apps/APP_NAME/query/QUERY_PROFILE?q=..., which is the URL your storefront or client application sends. The two return different result counts or different documents.
This doesn't necessarily mean your rules or rewrites failed to publish. In most cases the two requests aren't identical: the Editor and your application send different parameters to the same query profile.
Environment
- Lucidworks Platform with Commerce Studio integrated with Fusion 5.x / Managed Fusion
- Query profiles and pipelines that apply business rules (the Apply Rules stage)
Common causes
1. The Editor includes draft rules and rewrites
The Commerce Studio Editor previews changes before you publish them. To do this, it adds this parameter to each query:
lw.rules.simulate=APP_NAME_query_rewrite_staging_em
This parameter runs the query against the staging rules collection, which contains all rules and rewrites, including ones still in Draft state. A direct API call without this parameter applies only Published rules and rewrites, so live/API traffic reflects a draft rule's effect only after you publish it.
To confirm: Add the same lw.rules.simulate parameter to your API call. If the API then returns the same results as the Editor, draft rules account for the difference.
https://FUSION_HOST/api/apps/APP_NAME/query/QUERY_PROFILE?q=SEARCH_TERMS&lw.rules.debug=true&lw.rules.simulate=APP_NAME_query_rewrite_staging_em
In the Editor, you can also use a rule's Preview toggle in the Execute panel to leave that rule out of the preview.
2. Your application sends parameters the Editor doesn't
Client applications often add parameters before sending the query to the API. The most common example is a filter query (fq), such as a status, availability, or catalog filter. The Editor doesn't send these application-specific parameters unless you set up rules that produce them, and extra fq filters can reduce the result set, so the Editor and the application may return different counts for the same query.
To confirm:
- Capture the exact URL your application sends, including every parameter.
- Remove the parameters the Editor doesn't send, such as the
fqfilters, and compare result counts against the Editor. - If removing those parameters makes the counts match, they account for the difference.
To align the two: Create rules in the Editor that reproduce the same filters your application sends, such as filter rules that produce the same fq values. Keeping these as draft rules makes the Editor preview match the application's result set without changing live rules. Alternatively, compare the Editor against an API call that leaves out the application-specific parameters.
Use lw.rules.debug to compare what fired
Add lw.rules.debug=true (or 1) to both requests and compare the applicable_rules list in each response. This shows which rules fired for each request, which lets you confirm whether a draft rule fires only when lw.rules.simulate is present.
If the same rules fire in both requests but the counts still differ, compare the remaining parameters (starting with fq) between the two requests.
For details on reading the output, see Identify which business rules fired on a query using lw.rules.debug.