Repository navigation
Description
Goal (Spike — investigation only)
When exactly one content type is selected in the Content Drive, let the user
filter the listing by that content type's searchable fields — the per-field
inputs from the legacy Search portlet.
Endpoint in scope: POST /api/v1/drive/search (extend DriveRequestForm).
This is a DB-first filter: it must run inside the drive's existing SQL path
(BrowserAPIImpl.selectQuery) and must not force the request onto Elasticsearch.
This is a spike: it produces a design, not an implementation. Two outputs:
- The request contract — the new field(s) on
drive/search. - A DB-first feasibility note — sample SQL, per-field-type match matrix,
and the Postgres indexing/extension needs.
What "searchable field" means
A field the editor flagged as searchable: Field.searchable() (modern) /
Field.isSearchable() (legacy). Enumerate them with
com.dotcms.util.filtering.contenttype.field.UserSearchableSpecification.
Confirm whether an endpoint already returns a content type's searchable fields so
the FE can render the inputs; if not, that's a follow-up ticket.
How it works DB-first
Field values live in the contentlet c table that buildSelectBaseQuery already
joins, stored as JSON in the contentlet_as_json column. Extract a field value with:
c.contentlet_as_json -> 'fields' -> '<fieldVar>' ->> 'value'
The new filter adds one AND clause per submitted field, binding values with ?
the same way appendFilterQuery / appendMIMETypeQuery already do. Per-field-type
match semantics:
| Field type | SQL match |
|---|---|
| text / textArea / custom | ... ->> 'value' ILIKE ? (%value%) |
| select / radio / boolean | ... ->> 'value' = ? (stored value, not label) |
| date / time / number | range: >= ? / <= ? (encode as from TO to) |
| multiSelect / checkbox | CSV containment on ->> 'value' |
| tag | subselect on tag / tag_inode |
| category | subselect on tree / inode |
Suggested v1: text family + select/radio/boolean + date/number ranges.
Defer tag, category and relationships to a follow-up.
Behavior must be regression-safe: when no field filter is sent, the query is
byte-for-byte unchanged (same guarantee as the workflow filter). The field filter
must not flip isUseElasticSearchForTextFiltering on.
Example of the generated query
For a request filtering the blog content type by title (text, contains
"spike") and category field topic = news, the appended clauses look like:
-- ... existing buildSelectBaseQuery() base + joins on contentlet c ...
AND c.contentlet_as_json -> 'fields' -> 'title' ->> 'value' ILIKE ? -- '%spike%'
AND c.contentlet_as_json -> 'fields' -> 'topic' ->> 'value' = ? -- 'news'
-- ... existing ORDER BY / LIMIT / OFFSET ...Bound parameters (in order): ['%spike%', 'news'].
A date range (publishDate = 2026-01-01 TO 2026-06-30) becomes two clauses on
the same expression:
AND (c.contentlet_as_json -> 'fields' -> 'publishDate' ->> 'value')::timestamp >= ? -- 2026-01-01
AND (c.contentlet_as_json -> 'fields' -> 'publishDate' ->> 'value')::timestamp <= ? -- 2026-06-30Multiple field inputs are joined with AND (each input narrows the result).
When NOT to offer field search
Some searchable fields are a poor fit for a DB-first per-field filter — the spike
should exclude them from the rendered inputs (or document them as unsupported):
- Binary / image / file fields — the JSON holds a path/metadata, not searchable
user text. - WYSIWYG and Story Block (block editor) — values are large HTML/JSON blobs;
substringILIKEover them is noisy and slow. Leave these to the free-text /
Elasticsearch path. - Layout-only fields (line/tab dividers, columns, rows) and constant /
hidden fields — no user-entered value to match. - Relationship fields — child-id matching needs joins; deferred past v1.
- Tag / category — supported eventually via subselects, but heavier; keep out
of v1.
Postgres extensions & indexing
Extracting a JSON value is cheap; matching it at drive scale is not, unless indexed.
-
Equality / range (
=,<,>) onselect/radio/bool/date/number:
a plain B-tree functional index on the extracted expression is enough — no
extension required.CREATE INDEX idx_ct_myfield ON contentlet ((contentlet_as_json -> 'fields' -> 'myField' ->> 'value'));
-
Substring / case-insensitive (
ILIKE '%x%') on text fields: a B-tree index
can't accelerate a leading-wildcardILIKE. Use thepg_trgmextension,
which adds trigram GIN indexes that Postgres can use forILIKE/LIKE/~*.CREATE EXTENSION IF NOT EXISTS pg_trgm; -- one-time, per database CREATE INDEX idx_ct_myfield_trgm ON contentlet USING GIN ((contentlet_as_json -> 'fields' -> 'myField' ->> 'value') gin_trgm_ops);
Version support: pg_trgm ships with Postgres since 9.1 and JSONB/GIN
since 9.4, so both are available on every Postgres version dotCMS supports —
no upgrade needed. pg_trgm is a contrib module bundled with the standard
Postgres distribution (and enabled by default on the dotCMS image / RDS / Cloud
SQL / Azure), so CREATE EXTENSION is the only step.
The spike should note: who creates these indexes (per-field, on demand vs. a fixed
set), and whether v1 ships without trgm indexes (correct but slower) and adds them
as a tuning follow-up.
Contract to define on drive/search
- Request shape on
DriveRequestForm. A map keyed by field variable is the
natural fit, e.g.:{ "contentTypes": ["blog"], "searchableFields": { "title": "spike", "topic": "news", "publishDate": "2026-01-01 TO 2026-06-30" } } - How a field is identified (velocity variable name), and how multi-value
(multiSelect/checkbox) and ranges (from TO to) are encoded. - AND vs OR across multiple field inputs, and how this composes with the
existing free-textfilters.text. - Where the single-content-type rule is enforced — FE only, or BE validation?
Deliverable
A short write-up (comment on this issue or a linked doc) with:
- the proposed
drive/searchrequest contract (with the JSON example), and - the DB-first note: a sample SQL clause, the per-field-type matrix, the v1 type
scope, the "not recommended" list, and the indexing/extension plan above.
Plus a recommendation on the contract shape and the follow-up implementation
tickets to open. No code changes in this spike.
Out of scope
- Multi-content-type field search (single-CT only).
- The implementation, the FE input UI, and tests (separate tickets once the
spike lands).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fabrizzio-dotCMS commentedon Jun 11, 2026
Spike conclusion — searchable-field search in Content Drive: DB-first is viable and scalable on Postgres for the bounded 1-CT case; ES/OS remains the default for everything else
1. Current index state on
contentlet_as_jsonidx_contentlet_template_value— a btree functional index, fieldtemplateonly, serves=and prefix (LIKE 'x%'). Created byTask241014AddTemplateValueOnContentletIndex(postgres.sql:2370). The functional-index-over-a-JSON-field pattern is already in production.contentlet— neither containment (jsonb_ops/jsonb_path_ops) nor trigram (gin_trgm_ops).containson any field other thantemplate= seq scan. Any "doesn't scale" numbers reflect this un-indexed baseline, not the ceiling.2. Indexing strategy (all native Postgres, with precedent in the repo)
What trigram (
pg_trgm) buys us: a trigram is a 3-character group;pg_trgmprecomputes every value's trigrams into a GIN index, soILIKE '%term%'becomes an indexed lookup instead of a seq scan. It's case-insensitive (soILIKEworks directly), at the cost that terms shorter than 3 chars can't use it.pg_trgmships with Postgres since 9.1 (andjsonb_path_opsGIN since 9.4), so both are available on every Postgres version dotCMS supports —CREATE EXTENSIONis the only step.3. Is it scalable? — yes, under these premises
It is scalable only if all hold (it is not automatic):
%ab%degrades).save/bulk reindex — measure it).4. What to implement
USING GIN ((contentlet_as_json->'fields') jsonb_path_ops)— covers equality/containment for all fields at oncepg_trgm+gin_trgm_opson the field expression — enables scalablecontains, only on frequently-searched fieldsdrive/searchcontract{ctVar: {fieldVar: value}}, validate single-CT in the backend, enforce minimum search length (≥3) for substringBrowserAPIImpl.selectQuerycontentlet_as_jsonwith bound params; joincontentlet_version_info(variant + language +deleted=false);LIMIT+ keyset pagination; selectc.inodeonlyPer-field-type SQL shapes (DB-first, scoped to one CT;
?= bound param):Non-scalar types (Tag → side-table JOIN, Category → tree JOIN, Relationship → version re-resolution, StoryBlock → recursive ProseMirror extraction) are not in the DB-first scope — route to ES/OS.
5. Verdict
Non-functionals if DB-first is adopted: always join
contentlet_version_info(variant + language +deleted=false);LIMIT+ keyset pagination; selectc.inodeonly;statement_timeout+ slow-query logging; create GIN/functional indexesCONCURRENTLY, on-demand, only for hot fields; enforce a minimum search length (≥3 chars) for substring; measure GIN write amplification on bulk reindex before rollout.Follow-up tickets: (1) define the
drive/searchcontract ({ctVar:{fieldVar:value}}, single-CT validated in BE, min-length rule); (2) design the index lifecycle for searchable fields (who declares hot fields, when indexes are created — the core work); (3) wire DB-first field clauses intoBrowserAPIImpl.selectQuery; (4) route multi-CT / non-scalar / relevance to the existing ES/OSSearchAPIpath.zJaaal commentedon Jun 17, 2026
Ref: https://dotcms.slack.com/docs/T028R2630/F0BB6EP52AZ