Evaluate Boolean Search Queries with Field Filters and Phrases

Last updated: November 29, 2026

Quick Overview

Build an in-memory index over documents with text and metadata fields, then evaluate queries such as author:alice (roadmap OR "q3 plan") -draft supporting implicit AND, OR, NOT or a leading minus, parentheses, quoted phrases and field:value filters.

Glean
Coding & Algorithms
Software Engineer
Glean
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Build an in-memory index over documents with text and metadata fields, then evaluate queries such as author:alice (roadmap OR "q3 plan") -draft supporting implicit AND, OR, NOT or a leading minus, parentheses, quoted phrases and field:value filters.

Glean users type operator queries like app:jira or from:someone alongside free text, so query parsing over an inverted index sits close to the product. This onsite question tests building a positional index, writing a small recursive-descent parser with correct precedence, and evaluating set operations efficiently.

What the Interviewer Expects
  • Builds an inverted index with positions so phrases can be verified
  • Defines precedence: NOT binds tightest, then implicit or explicit AND, then OR
  • Writes a recursive-descent parser instead of ad hoc string splitting
  • Implements NOT as a complement against the document universe and notes its cost
  • Reports clear errors for unbalanced parentheses or dangling operators
  • Discusses ordering intersections smallest posting list first
Key Topics to Cover
inverted index
recursive descent parsing
operator precedence
phrase queries
set algebra
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you return results ranked by BM25 instead of an unordered set?
  • NOT over a 50 million document index is expensive. How would you rewrite queries to avoid materializing the complement?
  • How would you support date ranges such as updated:>2024-01-01?
  • How would you enforce per-user permissions inside this evaluator?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Docs are {id: {"text": ..., field: value}}. Query grammar:

or_expr := and_expr ("OR" and_expr)* and_expr := unary (("AND")? unary)* unary := ("-" | "NOT") unary | "(" or_expr ")" | PHRASE |...
High-Level Design

Index: postings[term][doc] = [positions] and fields[(field, value)] = {docs}. A tokenizer regex yields parens, minus, quoted strings and bare words. The parser returns Python sets so AND is &, O...


Submit Your Answer
Markdown supported

Related Questions