### Home Classes Methods

### In Files

- ext/r_search.c

### Parent

Object

### Methods

- #==
- #boost
- #boost=
- #eql?
- #hash
- #terms
- #to_s

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::BlankSlate
- Ferret::BoostMixin
- Ferret::Browser
- Ferret::Browser::Controller
- Ferret::Browser::Delegator
- Ferret::Browser::DocumentController
- Ferret::Browser::ErrorController
- Ferret::Browser::HelpController
- Ferret::Browser::HomeController
- Ferret::Browser::TermController
- Ferret::Browser::TermVectorController
- Ferret::Browser::ViewHelper
- Ferret::Document
- Ferret::Field
- Ferret::FieldSymbol
- Ferret::FieldSymbolMethods
- Ferret::FileNotFoundError
- Ferret::Index
- Ferret::Index::FieldInfo
- Ferret::Index::FieldInfos
- Ferret::Index::Index
- Ferret::Index::IndexReader
- Ferret::Index::IndexWriter
- Ferret::Index::LazyDoc
- Ferret::Index::LazyDoc::LazyDocData
- Ferret::Index::TermDocEnum
- Ferret::Index::TermEnum
- Ferret::Index::TermVector
- Ferret::Index::TermVector::TVOffsets
- Ferret::Index::TermVector::TVTerm
- Ferret::ParseError
- Ferret::QueryParser
- Ferret::QueryParser::QueryParseException
- Ferret::Search
- Ferret::Search::BooleanQuery
- Ferret::Search::BooleanQuery::BooleanClause
- Ferret::Search::ConstantScoreQuery
- Ferret::Search::Explanation
- Ferret::Search::Filter
- Ferret::Search::FilteredQuery
- Ferret::Search::FuzzyQuery
- Ferret::Search::Hit
- Ferret::Search::MatchAllQuery
- Ferret::Search::MultiSearcher
- Ferret::Search::MultiTermQuery
- Ferret::Search::PhraseQuery
- Ferret::Search::PrefixQuery
- Ferret::Search::Query
- Ferret::Search::QueryFilter
- Ferret::Search::RangeFilter
- Ferret::Search::RangeQuery
- Ferret::Search::Searcher
- Ferret::Search::Sort
- Ferret::Search::SortField
- Ferret::Search::Spans
- Ferret::Search::Spans::SpanFirstQuery
- Ferret::Search::Spans::SpanMultiTermQuery
- Ferret::Search::Spans::SpanNearQuery
- Ferret::Search::Spans::SpanNotQuery
- Ferret::Search::Spans::SpanOrQuery
- Ferret::Search::Spans::SpanPrefixQuery
- Ferret::Search::Spans::SpanTermQuery
- Ferret::Search::TermQuery
- Ferret::Search::TopDocs
- Ferret::Search::TypedRangeFilter
- Ferret::Search::TypedRangeQuery
- Ferret::Search::WildcardQuery
- Ferret::StateError
- Ferret::Store
- Ferret::Store::Directory
- Ferret::Store::FSDirectory
- Ferret::Store::Lock
- Ferret::Store::Lock::LockError
- Ferret::Store::RAMDirectory
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Search::Query

## Summary

Abstract class representing a query to the index. There are a number of concrete Query implementations;

- TermQuery

- MultiTermQuery

- BooleanQuery

- PhraseQuery

- ConstantScoreQuery

- FilteredQuery

- MatchAllQuery

- RangeQuery

- WildcardQuery

- FuzzyQuery

- PrefixQuery

- Spans::SpanTermQuery

- Spans::SpanFirstQuery

- Spans::SpanOrQuery

- Spans::SpanNotQuery

- Spans::SpanNearQuery

Explore these classes for the query right for you. The queries are passed to the Searcher#search* methods.

### Query Boosts

Queries have a boost value so that you can make the results of one query more important than the results of another query when combining them in a BooleanQuery. For example, documents on Rails. To avoid getting results for train rails you might also add the tern Ruby but Rails is the more important term so you'd give it a boost.

### Public Instance Methods

==(p1) click to toggle source

call-seq;

    query.eql?(other_query) -> bool
    query == other_query -> bool

Return true if `query` equals `other_query`. Theoretically, two queries are equal if the always return the same results, no matter what the contents of the index. Practically, however, this is difficult to implement efficiently for queries like BooleanQuery since the ordering of clauses unspecified. "Ruby AND Rails" will not match "Rails AND Ruby" for example, although their result sets will be identical. Most queries should match as expected however.

    static VALUE
    frb_q_eql(VALUE self, VALUE other)
    {
        GET_Q();
        Query *oq;
        Data_Get_Struct(other, Query, oq);
        return q->eq(q, oq) ? Qtrue : Qfalse;
    }

boost click to toggle source

Returns the queries boost value. See the Query description for more information on Query boosts.

    static VALUE
    frb_q_get_boost(VALUE self)
    {
        GET_Q();
        return rb_float_new((double)q->boost);
    }

boost = boost → boost click to toggle source

Set the boost for a query. See the Query description for more information on Query boosts.

    static VALUE
    frb_q_set_boost(VALUE self, VALUE rboost)
    {
        GET_Q();
        q->boost = (float)NUM2DBL(rboost);
        return rboost;
    }

eql?(p1) click to toggle source

call-seq;

    query.eql?(other_query) -> bool
    query == other_query -> bool

Return true if `query` equals `other_query`. Theoretically, two queries are equal if the always return the same results, no matter what the contents of the index. Practically, however, this is difficult to implement efficiently for queries like BooleanQuery since the ordering of clauses unspecified. "Ruby AND Rails" will not match "Rails AND Ruby" for example, although their result sets will be identical. Most queries should match as expected however.

    static VALUE
    frb_q_eql(VALUE self, VALUE other)
    {
        GET_Q();
        Query *oq;
        Data_Get_Struct(other, Query, oq);
        return q->eq(q, oq) ? Qtrue : Qfalse;
    }

hash → number click to toggle source

Return a hash value for the query. This is used for caching query results in a hash object.

    static VALUE
    frb_q_hash(VALUE self)
    {
        GET_Q();
        return INT2FIX(q->hash(q));
    }

terms(searcher) → term_array click to toggle source

Returns an array of terms searched for by this query. This can be used for implementing an external query highlighter for example. You must supply a searcher so that the query can be rewritten and optimized like it would be in a real search.

    static VALUE
    frb_q_get_terms(VALUE self, VALUE searcher)
    {
        VALUE rterms = rb_ary_new();
        HashSet *terms = hs_new((hash_ft)&term_hash,
                                (eq_ft)&term_eq,
                                (free_ft)term_destroy);
        HashSetEntry *hse;
        GET_Q();
        Searcher *sea = (Searcher *)DATA_PTR(searcher);
        Query *rq = sea->rewrite(sea, q);
        rq->extract_terms(rq, terms);
        q_deref(rq);

        for (hse = terms->first; hse; hse = hse->next) {
            Term *term = (Term *)hse->elem;
            rb_ary_push(rterms, frb_get_term(term->field, term->text));
        }
        hs_destroy(terms);
        return rterms;
    }

to_s → string click to toggle source

Return a string representation of the query. Most of the time, passing this string through the Query parser will give you the exact Query you began with. This can be a good way to explore how the QueryParser works.

    static VALUE
    frb_q_to_s(int argc, VALUE *argv, VALUE self)
    {
        GET_Q();
        VALUE rstr, rfield;
        char *str;
        Symbol field = NULL;
        if (rb_scan_args(argc, argv, "01", &rfield)) {
            field = frb_field(rfield);
        }
        str = q->to_s(q, field);
        rstr = rb_str_new2(str);
        free(str);
        return rstr;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.