Class: Ferret::Search::PrefixQuery

Inherits:
Object
  • Object
show all
Defined in:
ext/r_search.c

Overview

Summary

A prefix query is like a TermQuery except that it matches any term with a specific prefix. PrefixQuery is expanded into a MultiTermQuery when submitted in a search.

Example

PrefixQuery is very useful for matching a tree structure category hierarchy. For example, let’s say you have the categories;

"cat1/"
"cat1/sub_cat1"
"cat1/sub_cat2"
"cat2"
"cat2/sub_cat1"
"cat2/sub_cat2"

Lets say you want to match everything in category 2. You’d build the query like this;

query = PrefixQuery.new(:category, "cat2")
# matches => "cat2"
# matches => "cat2/sub_cat1"
# matches => "cat2/sub_cat2"