Method: Scrivito::BasicObj.where

Defined in:
app/cms/scrivito/basic_obj.rb

.where(field, operator, value, boost = nil) ⇒ Scrivito::ObjSearchEnumerator

Note:

If invoked on a subclass of Obj, the result will be restricted to instances of this

Returns an ObjSearchEnumerator with the given initial subquery consisting of the four arguments.

Note that field and value can also be arrays for searching several fields or searching for several values.

subclass.

ObjSearchEnumerators can be chained using one of the chainable methods (e.g. ObjSearchEnumerator#and and ObjSearchEnumerator#and_not).

Examples:

Look for objects containing “Lorem”, boosting headline matches:

Obj.where(:*, :contains, 'Lorem', headline: 2).to_a

Look for the first 10 objects whose object class is “Pressrelease” and whose title contains “quarterly”:

Obj.where(:_obj_class, :equals, 'Pressrelease').and(:title, :contains, 'quarterly').take(10)

Look for all objects whose class is “Item”. The path should start with a defined location. Furthermore, select only items of a particular category:

Obj.where(:_obj_class, :equals, 'Item').and(:_path, :starts_with, '/en/items/').select do |item|
  item.categories.include?(category)
end

Find CMS objects linking to my_image through any link or reference:

Obj.where(:*, :links_to, my_image)

Find BlogPostPage objects linking to my_image1 or my_image2 through any link or reference:

BlogPostPage.where(:*, :links_to, [my_img1, my_img2])

Find all objects of the BlogPost class that reference author_obj via the authors referencelist attribute.

BlogPost.where(:authors, :refers_to, author_obj)

Parameters:

Returns:

Raises:



265
266
267
268
269
270
271
272
273
# File 'app/cms/scrivito/basic_obj.rb', line 265

def self.where(field, operator, value, boost = nil)
  assert_not_basic_obj('.where')
  if type_computer.special_class?(self)
    Workspace.current.objs.where(field, operator, value, boost)
  else
    Workspace.current.objs.where(:_obj_class, :equals, name)
        .and(field, operator, value, boost)
  end
end