Removed the `HRULE` constant from the import Rake task
[FIX] Fix `Item#to_hash` functionality to work with Arrays

I have extended the nested to_hash method by the functionality to cover
arrays containing to_hash'able elements as well. I could not find a way
to integrate it into the existing statement. Instead, I have added an
additional case specifically for arrays.

I have added a failing unit test case to reveal a problem with the
to_hash method. Previously, the method did not cover the case where
a Results::Item contains an array value with Results::Item objects.
In this case the Results::Item objects were not converted to a Hash.

Signed-off-by: Konrad Reiche <konrad.reiche@gmail.com>

Closes #722
Updated the Rails application template to use the new download location and version (0.20.6)
Updated the install instructions to use version 0.20.6
Make sure an Array is returned from `__get_results_with_load`

Fixes the `undefined method `detect'` error when single record is returned from `__get_results_with_load`

If you use load: true when the search would return a single object it raises an error:

    NoMethodError:
    undefined method `detect' for #<--elastic search persistance model-->

This has been fixed before but it must have been lost when the code was refactored.

See also: <http://stackoverflow.com/questions/10592005/tire-gem-undefined-method-detect>

Related: #353

Closes #725
[TEST] Use `dfs_query_then_fetch` to prevent sporadic failures in BoostingQueriesIntegrationTest and ConstantScoreQueriesIntegrationTest

Without this patch, the tests consistently fail couple of times per batch of 15 runs.

    rm -f results.txt
    time for i in {1..15}
      do
        echo "-------------------------------------------------------------------------------"
        echo "TEST $i"
        echo "-------------------------------------------------------------------------------"
        ruby -I lib:test test/integration/boosting_queries_test.rb
      if [ $? == 0 ]; then echo "$i: OK" >> results.txt; else echo "$i: FAIL">> results.txt; fi
    done

    echo; echo; echo "==============================================================================="
    cat results.txt

See <http://www.elasticsearch.org/guide/reference/api/search/search-type/>

Closes #721
[TEST] Delete registered queries to prevent <PercolatorIntegrationTest> failures

Potentially, prepare deleting the whole `_percolator` index on Travis-CI

Verified with:

Download or clone this [gist](https://gist.github.com/4239703):

    git clone git://gist.github.com/4239703.git elasticsearch_vagrant && cd elasticsearch_vagrant

Run bundle install, etc. Then, configure ES:

    echo '
    {
      "elasticsearch" : {
        "cluster_name" : "elasticsearch_test_in_vagrant",
        "index_shards" : 1,
        "index_replicas" : 0
      }
    }' > node.json

Install Ruby 1.9.3, _Tire_, etc:

    echo '
    # Install the Tire Rubygem
    apt-get install make git libcurl3 libcurl3-gnutls libcurl4-openssl-dev libsqlite3-dev -y
    apt-get install redis-server  -y
    apt-get install ruby1.9.3 -y
    update-alternatives --set ruby /usr/bin/ruby1.9.1
    gem install bundler --no-rdoc --no-ri
    test -d "tire" || git clone git://github.com/karmi/tire.git
    chown -R vagrant:staff tire
    cd tire
    bundle install
    ' > install.sh

Build and provision the machine:

    NODE_CONFIG=node.json INSTALL=install.sh time bundle exec vagrant up

Run the Tire tests:

    echo '
    cd tire

    echo "Running Tire tests in '`pwd`'"
    echo "Ruby: `ruby -v`"
    echo "Java: `java -version 2>&1 | head -1`"

    for i in {1..5}
      do
        echo "-------------------------------------------------------------------------------"
        echo "TEST $i"
        echo "-------------------------------------------------------------------------------"
        time bundle exec rake test
      if [ $? == 0 ]; then echo "$i: OK" >> results.txt; else echo "$i: FAIL">> results.txt; fi
    done

    echo; echo; echo "==============================================================================="
    cat results.txt
    ' > run_tire_tests.sh

    cat run_tire_tests.sh | xargs -0 bundle exec vagrant ssh -c

Related: #537

Closes #541
[SETUP] Update Travis-CI configuration (remove REE, restructure)
[SETUP] Use only "shoulda-context", not "shoulda"

The "shoulda" gem brings in the "shoulda-matchers" gem, which is not neccessary,
slows down the require time, and fails on 1.8.7:

    Gem::InstallError: shoulda-matchers requires Ruby version >= 1.9.2.

See <https://travis-ci.org/karmi/tire/jobs/7104954>
[TEST] Delete the whole percolator index on Travis

Still failing... <https://travis-ci.org/karmi/tire/builds/7104949>

Related: #541
[TEST] Clean up percolator for <ActiveRecordSearchableIntegrationTest> and <PersistentModelIntegrationTest>

* Delete the registered queries in setup
* Wipe the whole _percolator index on Travis in setup

Related: #537, #541
Release v0.5.8

Fixes: #688
[FIX] Fixed incorrect filename to class inflection in Rake import task

`bundle exec rake environment tire:import:all` now succeeds for a `Address` model.

Fix provided by @congshuanglong.

Closes #733, closes #744
Added support for `geo_distance` facets

Usage:

Tire.search 'venues' do
  query { string 'pizzeria' }

  facet 'geo' do
    geo_distance :location,
                 {:lat => 53.54507, :lon => 9.95309},
                 [{:to => 1}, {:from => 1, :to => 10}, {:from => 50}],
                 unit: 'km'
  end
end

Closes #701
Added support for the `custom_filters_score` query

Closes #734
[#734] Added DSL versions for `custom_filters_score` and restructured the source code

Allow the DSL version of filters definition:

    s = Tire.search('articles-test') do
      query do
        custom_filters_score do
          query { all }

          # Give documents over 300 words a score of 3
          filter do
            filter :range, words: { gt: 300 }
            boost 3
          end
        end
      end
    end

Related: #734
[#734] Added the `custom_filters_score` query from Tire contrib

As a replacement for the `custom_filters_score` query added
in previous commits, a more feature-complete implementation
by @jerryluk from karmi/tire-contrib has been added.

Fixes: #734
Added a custom strategy option to <Model.import>

Sometimes, when you have a complicated ActiveRecord relationships,
you need tight control on the importing SQL queries and mechanics.

This patch allows you to implement your own custom strategy, by
implementing an `import` method, and passing it to <Model.import>
as the `:strategy` option.

Example:

class MyCustomImportStrategy
  include Base
  def import &block
    klass.
      where(published: true).
      joins(:comments).
      find_in_batches(:batch_size => options[:per_page]) do |batch|
        index.import batch, options, &block
      end
    self
  end
end

Closes #709
[FIX] Make Tire::Results::Collection#to_ary return an Array

Closes #718, closes #432
Allow the `:wrapper` option to be passed to Tire.search consistently

Example:

    s = Tire.search 'articles-test', wrapper: ::MyCustomWrapper do
      query { match :title, 'one' }
    end

    s = Tire.search(
      'articles-test',
      payload: { query: { match: { title: 'one' } } },
      wrapper: ::MyCustomWrapper
    )

Closes #716