Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Configuration Examples

floere edited this page · 6 revisions

Configuration Examples

Here are some of the many configurations.

Indexing

Default

  indexing removes_characters:                 /[^äöüa-zA-Z0-9\s\/\-\"\&\.]/i,
           stopwords:                          /\b(and|the|or|on|of|in|is|to|from|as|at|an)\b/i,
           splits_text_on:                     /[\s\/\-\"\&\/]/,
           removes_characters_after_splitting: /[\.]/,
           normalizes_words:                   [[/\$(\w+)/i, '\1 dollars']],
           rejects_token_if:                   lambda { |token| token.blank? || token == :hello },
           case_sensitive:                     false,
           substitutes_characters_with:        CharacterSubstituters::WestEuropean.new

For a specific index

  Index::Memory.new(:special_indexing) do
    source   Sources::CSV.new(:title, file: 'data/books.csv')
    indexing removes_characters: /[^äöüd-zD-Z0-9\s\/\-\"\&\.]/i, # a-c, A-C are removed
             splits_text_on:     /[\s\/\-\"\&\/]/
    category :title,
             qualifiers: [:t, :title, :titre],
             partial:    Partial::Substring.new(from: 1),
             similarity: Similarity::DoubleMetaphone.new(2)
  end

Searching

Default

  querying removes_characters:                 /[^ïôåñëäöüa-zA-Z0-9\s\/\-\,\&\.\"\~\*\:]/i,
           stopwords:                          /\b(and|the|or|on|of|in|is|to|from|as|at|an)\b/i,
           splits_text_on:                     /[\s\/\-\,\&\/]/,
           removes_characters_after_splitting: //,
           case_sensitive:                     true,
           maximum_tokens:                     5,
           substitutes_characters_with:        CharacterSubstituters::WestEuropean.new

For a specific Search

  route %r{^/buks}  => Search.new(books_index) do
    searching removes_characters: /[buks]/i,
              stopwords:          /\b(and|the|or|on|of|in|is|to|from|as|at|an)\b/i
  end

Index

  Index::Memory.new(:books, result_identifier: 'Books') do
    source   Sources::CSV.new(:title, :author, :isbn, :year, :publisher, :subjects, file: 'data/books.csv')
    category :title,
             qualifiers: [:t, :title, :titre],
             partial:    Partial::Substring.new(from: 1),
             similarity: Similarity::DoubleMetaphone.new(2)
    category :author,
             qualifiers: [:a, :author, :auteur],
             partial:    Partial::Substring.new(from: -2)
    category :year,
             qualifiers: [:y, :year, :annee],
             partial:    Partial::None.new
    category :publisher, qualifiers: [:p, :publisher]
    category :subjects, qualifiers: [:s, :subject]
  end

Routing & Search

  options = {
    :weights => {
      [:title, :author] => +3,
      [:title, :isbn]   => +1,
      [:isbn, :author]  => -5
    }
  }

  # Access for the picky-live gem.
  #
  route %r{\A/admin\Z} => LiveParameters.new

  # Access for anybody wanting to run searches (e.g. the picky-client gem).
  #
  route %r{\A/books\Z} => Search.new(books_index, isbn_index, options),
        %r{\A/redis\Z} => Search.new(redis_index, options),
        %r{\A/csv\Z}   => Search.new(csv_test_index, options),
        %r{\A/isbn\Z}  => Search.new(isbn_index),
        %r{\A/geo\Z}   => Search.new(mgeo_index),
        %r{\A/all\Z}   => Search.new(books_index, csv_test_index, isbn_index, mgeo_index, options)
Something went wrong with that request. Please try again.