dotCMS / dotCMS/core

[SDK]: Fix Incorrect Lucene Query Conditionals in Query Builder

Open
#33,151 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OKR : Technical User Experience Priority : 2 High Team : Scout
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Problem Statement

When using the @dotcms/client query builder with logical operators (OR, AND), the generated Lucene query is invalid or misleading.

Example

Code:

qb.field('conhost')
  .equals(currentSiteValue?.identifier)
  .or()
  .equals(SYSTEM_HOST.identifier);

Current Output:

+conhost:ef0c8c29-9114-44f7-8c74-6e30b922d5c9 OR SYSTEM_HOST

Issues:

  1. Missing Parentheses – The conditional clause isn’t grouped, which may cause unexpected evaluation order.
  2. Missing Field Qualifier – The second condition (SYSTEM_HOST) is not scoped to the conhost field, making it a bare term.

Expected Output:

+(conhost:ef0c8c29-9114-44f7-8c74-6e30b922d5c9 OR conhost:SYSTEM_HOST)

This ensures both conditions apply correctly to the conhost field and preserves proper grouping.

Steps to Reproduce
  1. Use the query builder in @dotcms/client.
  2. Build a query with .or() or .and().
  3. Inspect the generated Lucene query string.
  4. See the malformed conditional output.
Acceptance Criteria
  • Queries generated with .or() and .and() are properly wrapped in parentheses.
  • Field names are repeated for all clauses to ensure correct scoping.
  • Unit tests added to verify conditional query generation with multiple fields and operators.
QA Notes
  • Test queries with nested conditionals, e.g.:

    (A OR B) AND (C OR D)
    

    to confirm grouping and field scoping is correct.

  • Verify that queries mixing multiple fields still apply field qualifiers correctly.

  • Confirm no regressions in existing single-field queries.

dotCMS Version

main / trunk

Proposed Objective

Technical User Experience / Developer Experience

Proposed Priority

Priority 2 – Important

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the @dotcms/client query builder entry point and locate the logic that renders .or() and .and() clauses into Lucene query strings. Add unit tests for single-field, mixed-field, and nested conditionals, then verify that parentheses and field qualifiers match the expected output without changing existing single-field behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.