### Home Classes Methods

### In Files

- ext/r_search.c

### Parent

Ferret::Search::Query

### Methods

- ::default_max_terms
- ::default_max_terms=
- ::new
- #<<
- #add_term

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::Analysis
- Ferret::Analysis::Analyzer
- Ferret::Analysis::AsciiLetterAnalyzer
- Ferret::Analysis::AsciiLetterTokenizer
- Ferret::Analysis::AsciiLowerCaseFilter
- Ferret::Analysis::AsciiStandardAnalyzer
- Ferret::Analysis::AsciiStandardTokenizer
- Ferret::Analysis::AsciiWhiteSpaceAnalyzer
- Ferret::Analysis::AsciiWhiteSpaceTokenizer
- Ferret::Analysis::HyphenFilter
- Ferret::Analysis::LetterAnalyzer
- Ferret::Analysis::LetterTokenizer
- Ferret::Analysis::LowerCaseFilter
- Ferret::Analysis::MappingFilter
- Ferret::Analysis::PerFieldAnalyzer
- Ferret::Analysis::RegExpAnalyzer
- Ferret::Analysis::RegExpTokenizer
- Ferret::Analysis::StandardAnalyzer
- Ferret::Analysis::StandardTokenizer
- Ferret::Analysis::StemFilter
- Ferret::Analysis::StopFilter
- Ferret::Analysis::Token
- Ferret::Analysis::TokenStream
- Ferret::Analysis::WhiteSpaceAnalyzer
- Ferret::Analysis::WhiteSpaceTokenizer
- 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
- Ferret::Utils
- Ferret::Utils::BitVector
- Ferret::Utils::MultiMapper
- Ferret::Utils::PriorityQueue
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Search::MultiTermQuery

## Summary

MultiTermQuery matches documents that contain one of a list of terms in a specific field. This is the basic building block for queries such as;

- PrefixQuery

- WildcardQuery

- FuzzyQuery

MultiTermQuery is very similar to a boolean "Or" query. It is highly optimized though as it focuses on a single field.

## Example

    multi_term_query = MultiTermQuery.new(:content, :max_term => 10)

    multi_term_query << "Ruby" << "Ferret" << "Rails" << "Search"

### Public Class Methods

default_max_terms → number click to toggle source

Get the default value for `:max_terms` in a MultiTermQuery. This value is also used by PrefixQuery, FuzzyQuery and WildcardQuery.

    static VALUE
    frb_mtq_get_dmt(VALUE self)
    {
        return rb_cvar_get(cMultiTermQuery, id_default_max_terms);
    }

default_max_terms = max_terms → max_terms click to toggle source

Set the default value for `:max_terms` in a MultiTermQuery. This value is also used by PrefixQuery, FuzzyQuery and WildcardQuery.

    static VALUE
    frb_mtq_set_dmt(VALUE self, VALUE rnum_terms)
    {
        int max_terms = FIX2INT(rnum_terms);
        if (max_terms <= 0) {
            rb_raise(rb_eArgError,
                     "%d <= 0. @@max_terms must be > 0", max_terms);
        }
    #ifdef FRT_RUBY_VERSION_1_9
        rb_cvar_set(cMultiTermQuery, id_default_max_terms, rnum_terms);
    #else
        rb_cvar_set(cMultiTermQuery, id_default_max_terms, rnum_terms, Qfalse);
    #endif
        return rnum_terms;
    }

new(field, options = {}) → multi_term_query click to toggle source

Create a new MultiTermQuery on field `field`. You will also need to add terms to the query using the MultiTermQuery#add_term method.

There are several options available to you when creating a MultiTermQueries;

### Options

:max_terms | You can specify the maximum number of terms that can be added to the query. This is to prevent memory usage overflow, particularly when don't directly control the addition of terms to the Query object like when you create Wildcard queries. For example, searching for "content:*" would cause problems without this limit.
:min_score | The minimum score a term must have to be added to the query. For example you could implement your own wild-card queries that gives matches a score. To limit the number of terms added to the query you could set a lower limit to this score. FuzzyQuery in particular makes use of this parameter.

    static VALUE
    frb_mtq_init(int argc, VALUE *argv, VALUE self)
    {
        VALUE rfield, roptions;
        float min_score = 0.0;
        int max_terms = FIX2INT(frb_mtq_get_dmt(self));
        Query *q;

        if (rb_scan_args(argc, argv, "11", &rfield, &roptions) == 2) {
            VALUE v;
            if (Qnil != (v = rb_hash_aref(roptions, sym_max_terms))) {
                max_terms = FIX2INT(v);
            }
            if (Qnil != (v = rb_hash_aref(roptions, sym_min_score))) {
                min_score = (float)NUM2DBL(v);
            }
        }
        q = multi_tq_new_conf(frb_field(rfield), max_terms, min_score);
        Frt_Wrap_Struct(self, NULL, &frb_q_free, q);
        object_add(q, self);
        return self;
    }

### Public Instance Methods

add_term(term, score = 1.0) → self click to toggle source
multi_term_query << term1 << term2 << term3 → self

Add a term to the MultiTermQuery with the score 1.0 unless specified otherwise.

    static VALUE
    frb_mtq_add_term(int argc, VALUE *argv, VALUE self)
    {
        GET_Q();
        VALUE rterm, rboost;
        float boost = 1.0;
        char *term = NULL;
        if (rb_scan_args(argc, argv, "11", &rterm, &rboost) == 2) {
            boost = (float)NUM2DBL(rboost);
        }
        term = StringValuePtr(rterm);
        multi_tq_add_term_boost(q, term, boost);

        return self;
    }

add_term(term, score = 1.0) → self click to toggle source
multi_term_query << term1 << term2 << term3 → self

Add a term to the MultiTermQuery with the score 1.0 unless specified otherwise.

    static VALUE
    frb_mtq_add_term(int argc, VALUE *argv, VALUE self)
    {
        GET_Q();
        VALUE rterm, rboost;
        float boost = 1.0;
        char *term = NULL;
        if (rb_scan_args(argc, argv, "11", &rterm, &rboost) == 2) {
            boost = (float)NUM2DBL(rboost);
        }
        term = StringValuePtr(rterm);
        multi_tq_add_term_boost(q, term, boost);

        return self;
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.