Class | Ferret::Search::BooleanQuery
In: | ext/r_search.c
Parent: | Ferret::Search::Query

## Summary

A BooleanQuery is used for combining many queries into one. This is best illustrated with an example.

## Example

Lets say we wanted to find all documents with the term "Ruby" in the +:title+ and the term "Ferret" in the +:content+ field or the +:title+ field written before January 2006. You could build the query like this.

      tq1 = TermQuery.new(:title, "ruby")
      tq21 = TermQuery.new(:title, "ferret")
      tq22 = TermQuery.new(:content, "ferret")
      bq2 = BooleanQuery.new
      bq2 << tq21 << tq22

      rq3 = RangeQuery.new(:written, :< => "200601")

      query = BooleanQuery.new
      query.add_query(tq1, :must).add_query(bq2, :must).add_query(rq3, :must)

### Methods

<< add_query new

### Classes and Modules

Class Ferret::Search::BooleanQuery::BooleanClause

### Public Class methods

BooleanQuery.new(coord_disable = false)

Create a new BooleanQuery. If you don‘t care about the scores of the sub-queries added to the query (as would be the case for many automatically generated queries) you can disable the coord_factor of the score. This will slightly improve performance for the query. Usually you should leave this parameter as is.

### Public Instance methods

boolean_query.add_query(query, occur = :should) → boolean_clause
boolean_query.<<(query, occur = :should) → boolean_clause
boolean_query << boolean_clause → boolean_clause

Us this method to add sub-queries to a BooleanQuery. You can either add a straight Query or a BooleanClause. When adding a Query, the default occurrence requirement is :should. That is the Query‘s match will be scored but it isn‘t essential for a match. If the query should be essential, use :must. For exclusive queries use :must_not.

When adding a Boolean clause to a BooleanQuery there is no need to set the occurrence property because it is already set in the BooleanClause. Therefor the `occur` parameter will be ignored in this case.

query: | Query to add to the BooleanQuery
occur: | occurrence requirement for the query being added. Must be one of [:must, :should, :must_not]
returns: | BooleanClause which was added

boolean_query.add_query(query, occur = :should) → boolean_clause
boolean_query.<<(query, occur = :should) → boolean_clause
boolean_query << boolean_clause → boolean_clause

Us this method to add sub-queries to a BooleanQuery. You can either add a straight Query or a BooleanClause. When adding a Query, the default occurrence requirement is :should. That is the Query‘s match will be scored but it isn‘t essential for a match. If the query should be essential, use :must. For exclusive queries use :must_not.

When adding a Boolean clause to a BooleanQuery there is no need to set the occurrence property because it is already set in the BooleanClause. Therefor the `occur` parameter will be ignored in this case.

query: | Query to add to the BooleanQuery
occur: | occurrence requirement for the query being added. Must be one of [:must, :should, :must_not]
returns: | BooleanClause which was added

[Validate]