Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A minimalist realtime full-text search index
Failed to load latest commit information.
build initial checkin
integration-tests ignore unknown output in integration eval script
ruby bump version
www bump version
.gitignore update .gitignore
Makefile wire through snippeting to ruby Query#snippetize
README bump version
batch-run-queries.c initial checkin
benchmark-queries.c add benchmark-queries binary
defaults.h initial checkin
dump.c wire in postings list headers
entry.c ignore tokens larger than 50 characters
entry.h move posarray into a generic resizable array
error.c distinguish between different error types
error.h distinguish between different error types
file-indexer.c initial checkin
index.c dump more index info in dump.c
index.h add indexinfo mmap_obj
khash.h make everything compile under os x
lock.c allow multiple concurrent writers
lock.h minor fixup in lock.h
mbox-indexer.c improve mbox parsing
mmap-obj.c fix up some debug macro type specifiers (sigh)
mmap-obj.h check mmap_objs for size changes before all reads
query-parser.c initial checkin
query-parser.h initial checkin
query-parser.y implement EVERY selector, specified as '*' in queries
query.c bugfix: don't produce invalid substitutions for labels
query.h add query_substitute, and rewrite clone in terms of that
rarray.h move posarray into a generic resizable array
search.c wire in postings list headers
search.h initial checkin
segment.c dump segment version in dump.c
segment.h use postings header counts for single-term count operations
snippeter.c wire in postings list headers
snippeter.h add snippeting
stringmap.c breaking change to stringmap
stringmap.h breaking change to stringmap
stringpool.c make everything compile under os x
stringpool.h initial checkin
termhash.c wire in postings list headers
termhash.h wire in postings list headers
test-labels.c change TEST_ macros to be more verbose
test-queries.c change TEST_ macros to be more verbose
test-search.c change TEST_ macros to be more verbose
test-segment.c change TEST_ macros to be more verbose
test-snippets.c change TEST_ macros to be more verbose
test-stringmap.c change TEST_ macros to be more verbose
test-stringpool.c change TEST_ macros to be more verbose
test-tokenizer.c change TEST_ macros to be more verbose
test.h change TEST_ macros to be more verbose
timer.h initial checkin
tokenizer.lex bugfix in tokenization: newlines in the middle of words
whistlepig.h add snippeting


= Whistlepig

Whistlepig is a minimalist realtime full-text search index. Its goal is
to be as small and maintainable as possible, while still remaining
useful, performant and scalable to large corpora. If you want realtime
full-text search without the frills, Whistlepig may be for you.

Whistlepig is written in ANSI C99. It currently provides a C API and Ruby

Latest version: 0.12, released 2012-06-09.
        Status: beta
   Bug reports:

= Getting it

       Rubygem:  gem install whistlepig
           Git:  git clone git://

= Realtime search

Roughly speaking, realtime search means:
- documents are available to to queries immediately after indexing, without any
  reindexing or index merging;
- later documents are more important than earlier documents.

Whistlepig takes these principles at face value.
- It only returns documents in the reverse (LIFO) order to which they were
  added, and performs no ranking, reordering, or scoring.
- It only supports incremental indexing. There is no notion of batch indexing
  or index merging.
- It does not support document deletion or modification (except in the
  special case of labels; see below).
- It only supports in-memory indexes.

Features that Whistlepig does provide:
- Incremental indexing. Updates to the index are immediately available to
- Fielded terms with arbitrary fields.
- A full query language and parser with conjunctions, disjunctions, phrases,
  negations, grouping, and nesting.
- Labels: arbitrary tokens which can be added to and removed from documents
  at any point, and incorporated into search queries.
- Early query termination and resumable queries.
- A tiny, < 3 KLOC ANSI C99 implementation.

== Benchmarks

On my not-particularly-new Linux desktop, I can index 8.5 MB/s of text
data per process, including some minor parsing.

Index sizes are roughly 50% of the original corpus size, e.g. the 1.4gb
Enron email corpus ( is 753mb in the index.

Query performance is entirely dependent on the queries and the index
size. Run the benchmark-queries to see some examples.

== Synopsis (using Ruby bindings)

  require 'rubygems'
  require 'whistlepig'

  include Whistlepig

  index = "index"

  entry1 =
  entry1.add_string "body", "hello there bob"
  docid1 = index.add_entry entry1              # => 1

  entry2 =
  entry2.add_string "body", "goodbye bob"
  docid2 = index.add_entry entry2              # => 2

  q1 = "body", "bob"
  results1 = q1                   # => [2, 1]

  q2 = q1.and"body", "hello")
  results2 = q2                   # => [1]

  index.add_label docid2, "funny"

  q3 = "body", "bob ~funny"
  results3 = q3                   # => [2]

  entry3 =
  entry3.add_string "body", "hello joe"
  entry3.add_string "subject", "what do you know?"
  docid3 = index.add_entry entry3              # => 3

  q4 = "body", "subject:know hello"
  results4 = q4                   # => [3]

== Concurrency

Whistlepig supports multi-process concurrency. Multiple reader and
writer processes can access the same index without mangling data.

Internally, Whistlepig uses pthread read-write locks to synchronize
readers and writers. This allows multiple concurrent readers but only a
single writer.

While this locking approach guarantees index correctness, it decreases
read and write performance when one or more writers exist. Systems with
high write loads may benefit from sharding documents across independent
indexes rather than sending everything to the same index.

== Design tradeoffs

I have generally erred on the side of maintainable code at the expense
of speed. Simpler implementations have been preferred over more complex,
faster versions. If you ever have to modify Whistlepig to suit your
needs, you will appreciate this.

== Bug reports

Please file bugs here:
Please send comments to:
Something went wrong with that request. Please try again.