Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Searching

ryanb edited this page Aug 17, 2011 · 1 revision

Search Methods

Whenever you call search on a model it will return a Xapit Collection instance. You can also call Xapit.search to do a global search across all indexed models. Here are the various search methods you can call which all return another Collection instance so they can be chained.

  • search Pass a text string to query text attributes.
  • where Pass a hash of conditions to query field attributes.
  • not_where Inverse of where.
  • or_where Perform an OR search on where clauses.
  • order Pass in a sortable attribute to sort by followed by an optional direction (:asc or :desc)
  • page The page number of records to return.
  • per The number of records per page.
  • with_facets Pass in a list of facets to limit the search by.
  • similar_to Pass in a model instance to find similar records.
  • in_classes Pass in any number of classes to use in Xapit.search.
  • not_in_classes Pass in any number of classes to exclude from Xapit.search.

Other Methods

The collection instance behaves like an array, so you can easily fetch all of the records by iterating through it. Here are some of the other methods it supports.

  • records The array of records, all array methods are delegated to this so it is usually not necessary to call directly.
  • total_entries The number of records found in the search across all pages.
  • total_pages The total number of pages, also aliased as num_pages
  • current_page The current page you're on.
  • limit_value The number of records per page.
  • applied_facet_options An array of FacetOption instances which have been applied to the search.
  • facets An array of Facet instances to search by.
  • spelling_suggestion A suggested term instead of the one queried on.

Search Query

The string passed to the search method can include AND, OR or NOT to do boolean searches. It can also include * to perform partial matches.

Clone this wiki locally