Skip to content

Commit

Permalink
! spec for when no weights option is given
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Nov 2, 2010
1 parent 6b6330c commit 90318c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/lib/picky/query/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize *index_types
@index_types = index_types
@weigher = options[:weigher] || Weigher.new(index_types)
@tokenizer = options[:tokenizer] || Tokenizers::Query.default
weights = options[:weights]
weights = options[:weights] || Weights.new
@weights = Hash === weights ? Weights.new(weights) : weights
end

Expand Down
5 changes: 5 additions & 0 deletions server/spec/lib/query/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
describe 'Query::Base' do

describe "weights handling" do
it "creates a default weight when no weights are given" do
query = Query::Base.new

query.weights.should be_kind_of(Query::Weights)
end
it "handles :weights options when not yet wrapped" do
query = Query::Base.new :weights => { [:a, :b] => +3 }

Expand Down
8 changes: 5 additions & 3 deletions server/test_project/app/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class BookSearch < Application
stopwords: /\b(und|and|the|or|on|of|in|is|to|from|as|at|an)\b/,
splits_text_on: /[\s\/\-\"\&\.]/,
removes_characters_after_splitting: /[\.]/,
normalizes_words: [[/\$(\w+)/i, '\1 dollars']]
normalizes_words: [[/\$(\w+)/i, '\1 dollars']],

substitutes_characters_with: CharacterSubstitution::European.new

default_querying removes_characters: /[\(\)\']/,
contracts_expressions: [/mr\.\s*|mister\s*/i, 'mr '],
Expand Down Expand Up @@ -69,8 +71,8 @@ class BookSearch < Application
%r{^/csv/full} => full_csv,
%r{^/csv/live} => live_csv,
%r{^/isbn/full} => full_isbn,
%r{^/all/full} => Query::Full.new(main_index, csv_test_index, isbn_index),
%r{^/all/live} => Query::Live.new(main_index, csv_test_index, isbn_index)
%r{^/all/full} => Query::Full.new(main_index, csv_test_index, isbn_index, options),
%r{^/all/live} => Query::Live.new(main_index, csv_test_index, isbn_index, options)

root 200

Expand Down

0 comments on commit 90318c5

Please sign in to comment.