<commit_before>Index Tanked
============

Index Tanked helps you index and search your data on IndexTank. Index Tanked works with any Ruby class but has additional helpful default behavior when used with Active Record.

***

Install
--------

If you're using Bundler toss a `gem 'index-tanked'` in your GEMFILE. Otherwise `gem install 'index-tanked'`

Example
-------

    require 'rubygems'
    require 'index-tanked'

    class Dog
      include IndexTanked

      attr_accessor :breed, :flea_count, :name, :behavior_score, :description

      index_tank :index => 'dogs', :url => 'http://example@index<EMAIL>' do
        doc_id, :doc_id
        field :breed
        field :behavior_score, :text => nil
        field :fleas, :flea_count, :text => lambda { |dog| 'infested' if dog.flea_count > 5 }
        field :name
        var 0, 15
        text :description
      end

      def doc_id
        ...
      end
    end


ActiveRecord Example
--------------------

Configuration<commit_msg>more readme<commit_after>Index Tanked
============

Index Tanked helps you index and search your data on IndexTank. Index Tanked works with any Ruby class but has additional helpful default behavior when used with Active Record.

***

Install
--------

If you're using Bundler toss a `gem 'index-tanked'` in your GEMFILE. Otherwise `gem install 'index-tanked'`

Example
-------

    require 'rubygems'
    require 'index-tanked'

    class Dog
      include IndexTanked

      attr_accessor :breed, :flea_count, :name, :behavior_score, :description

      index_tank :index => 'dogs', :url => 'http://example@index<EMAIL>' do
        doc_id, :doc_id
        field :breed
        field :behavior_score, :text => nil
        field :fleas, :flea_count, :text => lambda { |dog| 'infested' if dog.flea_count > 5 }
        field :name
        text :description
        var 0, 15
      end

      def doc_id
        ...
      end
    end


### What did we just do?

First thing's first. Include IndexTanked in your class. Next up is the index_tank block where we determine what we're going to index. The first thing we define is the doc_id. The doc_id is the ID of your record in IndexTank and you need to be able to generate a unique one for each instance that you'll be indexing. If you're using ActiveRecord you can skip this as it's defined by default, if you're using anything else you'll need to come come up with your own. You could base it on the url that points to the document, or the id used by your data store, etc.

Next up are the fields. When you do a search in IndexTank you can specify which field you are searching like this: `breed:pug`. If you don't specify a field you end up searching a special field called text. By default when you add a field in IndexTanked the value of that field *also* goes into the text field.

Sometimes you don't want that to occur, for instance, assuming that :behavior_score, above, is just a number, it may not make sense to have its value go into the text field since you may have multiple numerical fields and it may not make sense for a search of '5' to return dogs with 5 fleas and dogs with a behavior score of 5. If that is the case then `:text => nil` will prevent the fields value from being added to the text field.

The field method takes three arguments. The first argument is what the field should be called in IndexTank. The second argument is the optional method to retrieve the value for the field. If it's not provided then it is assumed that the first argument is also the method to retrieve its value. This can be a symbol (the name of the method to call), a Proc which will be executed, or just a String / Integer etc which will then be indexed identically for all instances.

If you want something other than the value of the field to be added to the text field you can specify it with :text, in the example above any dog with more than 5 fleas will have the word 'infested' in their text field, allowing them to be found by searching for 'infested'.

The text method takes one argument, which is a value to be *added* to the text field. This does not replace the text field, just adds to it. As above this may be a proc, symbol etc.

The var method adds a variable. See the IndexTank documentation for why you might want to do such a thing.

### What can we do now that we've done that?



ActiveRecord Example
--------------------

Configuration
{'fraction_non_alphanumeric': 0.07632894139027714, 'fraction_numerical': 0.0027260336210813267, 'mean_word_length': 3.092007434944238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1250818', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1151, 'n_words': 658}