Search criteria component

(by pavel, last update: sep 2013)

Main goal is to provide "rich" search functionality.

Mockups

Criteria JSON example

var criteria =
  {
    'type': 'and',
    'children': [
      {
        'type': 'not',
        'children': [
          {
            'type': 'tags',
            'operator': 'include',
            'operands': ['toy', 'walthers']
          }
        ]
      },
      {
        'type': 'response_code',
        'operator': 'is_equal_to',
        'operands': [200]
      }
    ]
  }

Implementation pieces

  • A criteria graph (in particular a list of individual criteria) to express selected search criteria

  • UI component to represent criteria

    • show an empty criteria list

    • add a new criteria row

    • save a named list

    • show already stored (in previous sessions) lists

    • "polymorphic" criteria row: an ability to show different criteria types and change inputs base on previous selections dynamically. For example if a user selects "response code" criteria, a row will change the next drop-down to show response code specific options.

  • "Criteria to ES" mapper to translate criteria list. If JSON representation of criteria will mimic ElasticSearch, the item will be get for free. The other mappers (at least "criteria to mongo") should also be considered.

Implementation approaches

Plain old ruby objects

  • Criteria list is implemented using plain "conventional" ruby.

  • Requires additional coding to implement serialization/deserialization

  • Requires additional coding to store saved criteria in a database

  • Requires additional coding for validation

  • More flexible and allow for example move from a list to a tree of criteria if it is needed

  • Polymorphic criteria is implemented using ruby inheritance and composition

ActivieRecord

  • Saved search as one-to-many association (search to criterion items)

  • Locked on the list representation of the saved search. Moving to "trees" is harder

  • "Save" functionality for free.

  • "Validation" for free

  • Polymorphic criteria is implemented using ActiveRecord STI

  • "Include/Exlude" functionality is implemented as a boolean flag on Criteria class

Purely JavaScript implementation

Intentionally left blank :)

TBD

How the criteria component coordinates with the "search" input? In particular, if both components (criteria rows and input) are filled, should we use AND or OR?

Should JSON representation of criteria be exactly like ES JSON looks like?

If ActiveRecord implementation is chosen, will we use a single "data" serialized column for different criteria kinds, or dedicated columns for specific attributes of criteria (sparse table)?

Last updated