Skip to content

Full-text query filter matches the whole query per field, so a multi-word search across fields finds nothing #135

Description

@jonasnobile

Problem

createFullTextFilterHandler (packages/bindx/src/dataview/filterHandlers.ts, v0.1.53) turns the DataGrid search box into one condition per searchable field, each with the whole query:

const conditions = fieldPaths.map(fieldPath => buildNestedWhere(fieldPath, buildTextCondition(artifact.mode, artifact.query)))
return { or: conditions }

So a query of several words only matches when one field contains all of them, in that order. Typical searches that therefore return nothing:

  • Jan Novák on a contact grid searching firstName and lastName
  • Alza Praha on a company grid searching name and city
  • Novák Instagram where the words sit in the row and in a related record

Users type these all the time (first name plus surname above all) and read the empty result as "the search is broken".

Proposal

In contains mode, split the query on whitespace and require every word to match some field:

const words = artifact.query.trim().split(/\s+/).filter(Boolean)
// { and: words.map(word => ({ or: fieldPaths.map(path => buildNestedWhere(path, { containsCI: word })) })) }
  • one word gives exactly today's { or: [...] }, so single-word searches are unchanged
  • word order does not matter (Novák Jan works too)
  • the other modes (startsWith, endsWith, equals, notContains) keep matching the whole query, since splitting changes their meaning
  • SelectDataView uses the same handler, so select pickers would benefit as well

Context

Found in a CRM on bindx 0.1.52 (list search over contacts and companies). We carry this change as a local bun patch of @contember/bindx until it lands upstream.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions