This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[#289] Added the "fuzzy" query type

See <http://www.elasticsearch.org/guide/reference/query-dsl/fuzzy-query.html>

This is a combination of 4 commits:

* initial implementation of fuzzy api
* just a bit improvement to the docs to make fuzzy example easier to read
* unit tests for fuzzy query
* integration test for fuzzy query
  • Loading branch information...
plentz authored and karmi committed Mar 25, 2012
1 parent 2797fbf commit c1e10d6fcb00f9913f064230fc9b4aa30bc921d6
Showing with 50 additions and 0 deletions.
  1. +12 −0 README.markdown
  2. +1 −0 examples/tire-dsl.rb
  3. +5 −0 lib/tire/search/query.rb
  4. +20 −0 test/integration/fuzzy_queries_test.rb
  5. +12 −0 test/unit/search_query_test.rb
View
@@ -298,6 +298,18 @@ a plain old Ruby `Hash` (or JSON string) with the query declaration to the `sear
Tire.search 'articles', :query => { :fuzzy => { :title => 'Sour' } }
```
... but you can also do fuzzy querys using our API:
```ruby
Tire.search('articles') { query { fuzzy :title, 'Sour' } }
```
Tire also allow you to customize the fuzzy call by passsing an options hash:
```ruby
Tire.search('articles') { query { fuzzy :title, 'Sour', boost: 2, min_similarity: 0.5 } }
```
If this sounds like a great idea to you, you are probably able to write your application
using just `curl`, `sed` and `awk`.
View
@@ -483,6 +483,7 @@ def self.search
# * [custom_score](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html)
# * [all](http://www.elasticsearch.org/guide/reference/query-dsl/match-all-query.html)
# * [ids](http://www.elasticsearch.org/guide/reference/query-dsl/ids-query.html)
# * [fuzzy](http://www.elasticsearch.org/guide/reference/query-dsl/fuzzy-query.html)
#### Faceted Search
View
@@ -9,6 +9,11 @@ def initialize(&block)
def term(field, value)
@value = { :term => { field => value } }
def fuzzy(field, value, options={})
query = { field => { :term => value } }
query[field].update(options)
@value = { :fuzzy => query }
end
def terms(field, value, options={})
@@ -0,0 +1,20 @@
require 'test_helper'
module Tire
class FuzzyQueryIntegrationTest < Test::Unit::TestCase
include Test::Integration
context "Fuzzy query" do
should "fuzzily find article by tag" do
results = Tire.search('articles-test') { query { fuzzy :tags, 'irlang' } }.results
assert_equal 1, results.count
assert_equal ["erlang"], results.first[:tags]
end
end
end
end
@@ -95,6 +95,18 @@ class QueryTest < Test::Unit::TestCase
end
end
context "FuzzyQuery" do
should "allow a fuzzy search" do
assert_equal( { :fuzzy => { :foo => { :term => 'bar' } } }, Query.new.fuzzy(:foo, 'bar') )
end
should "allow a fuzzy search with an options hash" do
assert_equal( { :term => { :foo => { :term => 'bar', :boost => 1.0, :min_similarity => 0.5 } } }, Query.new.term(:foo, 'bar', :boost => 1.0, :min_similarity => 0.5 ) )
end
end
context "BooleanQuery" do

0 comments on commit c1e10d6

Please sign in to comment.