Building a Structured Query Engine

Amanpreet Singh, Karthik Venkatesan, Simranjyot Singh GillarXiv 2017

Abstract

This paper introduces the Structured Query Engine (SQE), a custom-built search and retrieval system designed to handle complex, multi-dimensional queries on structured data. Modeled after enterprise solutions like Elasticsearch, SQE implements a Lucene-like inverted index, a RESTful API, and an Abstract Syntax Tree (AST) based query language. We demonstrate the system's efficacy through a movie recommendation application using the IMDB 5000 dataset, achieving real-time indexing and sophisticated multi-field search capabilities.

Introduction

Standard information retrieval systems often rely on simple keyword matching, which frequently fails to meet the requirements of users searching through multi-dimensional datasets. For instance, a search for "billionaire" within a specific "sports" category requires an engine that understands data structure to avoid irrelevant results from other domains. While enterprise-grade solutions exist, building such an engine from scratch provides critical insights into handling nested data, maintaining synchronization between system components, and optimizing for real-time performance.

System Architecture

The SQE architecture is comprised of three primary pillars designed to facilitate efficient data ingestion and retrieval.

High-level system architecture of the SQE.
  1. RESTful API: Built using the Tornado web framework and Nginx, this layer provides the interface for CRUD operations and search queries.
  2. Real-time Distributed Indexer: This component is responsible for "Flattening Mappings"—converting nested JSON objects into dot-notated strings (e.g., actor.name)—and performing tokenization using various analyzers such as Standard and Ngram.
  3. Information Retriever: This module utilizes a custom Query DSL to parse JSON-based queries into an Abstract Syntax Tree (AST).

Query Processing and Scoring

The Information Retriever supports a hierarchical query structure, allowing for both simple and complex search logic.

Hierarchical structure of the Query DSL.

The engine supports:

  • Leaf Queries: Basic Term and Match queries.
  • Compound Queries: Boolean logic including "Should" and "Filter" clauses.
  • Scoring: Relevance is determined using a vector-space model. Documents are scored based on the inner product of their TF-IDF vectors against the query vector.

To maintain performance, the system employs Debouncing to delay disk writes and Snappy Compression to minimize the storage footprint. Furthermore, shared memory resources between the indexer and retriever ensure that search results reflect the most recent updates without redundant data copying.

Evaluation and Results

The SQE was validated using a Movie Recommendation System built on the IMDB 5000 movie dataset. This allowed for testing complex queries involving various fields such as director names, actor lists, genres, and numerical IMDB scores.

The system successfully handled "union" and "intersection" queries, providing ranked lists of similar movies based on user preferences. Key technical achievements included:

  • Real-time Performance: Low latency for indexing and retrieval was maintained through architectural optimizations.
  • Functional Recommender: The application effectively utilized "Should" clauses and "Range Filters" to deliver relevant recommendations.
  • Efficient Nesting: The flattening approach allowed the inverted index to treat nested fields like actor.name as distinct searchable keys while preserving document context.

Limitations and Future Work

While functional, the current implementation of SQE has several areas for improvement. Memory management lacks robust garbage collection, which may limit scalability for datasets exceeding millions of documents. The Query DSL is currently limited to one level of nesting for compound nodes, and the system lacks built-in aggregation capabilities (e.g., calculating averages across categories). Future work will focus on internal query result caching and expanding the depth of the query language.

Summary updated

Abstract

Finding patterns in data and being able to retrieve information from those patterns is an important task in Information retrieval. Complex search requirements which are not fulfilled by simple string matching and require exploring certain patterns in data demand a better query engine that can support searching via structured queries. In this article, we built a structured query engine which supports searching data through structured queries on the lines of ElasticSearch. We will show how we achieved real time indexing and retrieving of data through a RESTful API and how complex queries can be created and processed using efficient data structures we created for storing the data in structured way. Finally, we will conclude with an example of movie recommendation system built on top of this query engine.
BibTeX
@misc{singh2017building,
  author = {Amanpreet Singh and Karthik Venkatesan and Simranjyot Singh Gill},
  title = {{Building a Structured Query Engine}},
  year = {2017},
  eprint = {1710.00454},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1710.00454},
}
Figure