Module: Metasploit::Model::Search

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Association, Attribute, With
Defined in:


DSL to define associations and attributes that can be searched. Making an association searchable, will expose the attributes that association's class defined as searchable.


Search operators define how to search against a given Class.


Boolean, Date, Integer, and String attributes can be searched with search_attribute. Integer and String attributes can be further restricted to a defined Set of values.

class Part
  include Metasploit::Model::Search

  search_attribute :part,

The above defines the :part operator on Part.

Custom search operators

If a search operator does not directly correspond to an attribute or a the attribute needs custom validation, then a custom operator class can be setup as the search operator

class Search::Operator::UUID
  def name

class Part
  include Metasploit::Model::Search

  search_with Search::Operator::UUID

The above defines the :uuid operator on Part.


Search operators registered with search_attribute or search_with on an associated Class can be searched with Association::ClassMethods#search_association:

class Widget
  include Metasploit::Model::Search

  # declare parts association

  search_association :parts

The above will define the :'parts.number' and :'parts.uuid' operator on Widget.


Once search operators are defined, a formatted query, composed of space separated formatted operation, <>:<formatted_value>, can be parsed to produce a validatable query.

query =
  formatted: 'parts.number:1 parts.number:2 parts.uuid:EX,QR'

Operations using the same operator are unioned together, while operations with different operator are intersected together, so the above formatted query can be thought of as (parts.number:1 || parts.number:2) && parts.uuid:EX,QR.


Once a Query is defined, it needs to be converted to a data store specific visitor.

Visitors for ActiveRecord are defined in MetasploitDataModels::Search::Visitor.

If you want to define your own visitors, you can subclass Visitation::Visitor.

Defined Under Namespace

Modules: Association, Attribute, ClassMethods, Group, Operation, Operator, With Classes: Query