@@ -11,7 +11,7 @@ defmodule NouveauTest do
1111 resp = Couch . post ( "/#{ db_name } /_bulk_docs" ,
1212 headers: [ "Content-Type": "application/json" ] ,
1313 body: % { :docs => [
14- % { "_id" => "doc4" , "foo" => "foo" , "bar" => 42 , "baz" => "hello there" } ,
14+ % { "_id" => "doc4" , "foo" => "foo" , "bar" => 42 , "baz" => "hello hello there" } ,
1515 % { "_id" => "doc3" , "foo" => "bar" , "bar" => 12.0 , "baz" => "hello" } ,
1616 % { "_id" => "doc1" , "foo" => "baz" , "bar" => 0 , "baz" => "there" } ,
1717 % { "_id" => "doc2" , "foo" => "foobar" , "bar" => 100 , "baz" => "hi" } ,
@@ -85,6 +85,7 @@ defmodule NouveauTest do
8585 index("string", "foo", doc.foo, {store: true});
8686 index("double", "bar", doc.bar, {store: true});
8787 index("stored", "baz", doc.foo);
88+ if (doc.baz) {index("text", "txt", doc.baz);}
8889 }
8990 """
9091 }
@@ -117,6 +118,11 @@ defmodule NouveauTest do
117118 Enum . map ( hits , fn hit -> hit [ "doc" ] [ "_id" ] end )
118119 end
119120
121+ def get_orders ( resp ) do
122+ % { :body => % { "hits" => hits } } = resp
123+ Enum . map ( hits , fn hit -> hit [ "order" ] end )
124+ end
125+
120126 def get_mango_ids ( resp ) do
121127 % { :body => % { "docs" => docs } } = resp
122128 Enum . map ( docs , fn doc -> doc [ "_id" ] end )
@@ -187,6 +193,22 @@ defmodule NouveauTest do
187193 assert ids == [ "doc1" , "doc2" , "doc3" , "doc4" ]
188194 end
189195
196+ @ tag :with_db
197+ test "search returns all matches for hello by relevance" , context do
198+ db_name = context [ :db_name ]
199+ create_search_docs ( db_name )
200+ create_ddoc ( db_name )
201+
202+ url = "/#{ db_name } /_design/foo/_nouveau/bar"
203+ resp = Couch . get ( url , query: % { q: "txt:hello" , include_docs: true } )
204+ assert_status_code ( resp , 200 )
205+ ids = get_ids ( resp )
206+ orders = get_orders ( resp )
207+ # doc4 scores higher (more hello's)
208+ assert ids == [ "doc4" , "doc3" ]
209+ assert Enum . at ( Enum . at ( orders , 0 ) , 0 ) [ "value" ] > Enum . at ( Enum . at ( orders , 1 ) , 0 ) [ "value" ]
210+ end
211+
190212 @ tag :with_db
191213 test "search returns all items for POST" , context do
192214 db_name = context [ :db_name ]
0 commit comments