texticle 2.0.pre2 → 2.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +16 -0
 - data/lib/texticle.rb +9 -3
 - data/spec/texticle_spec.rb +13 -0
 - metadata +2 -2
 
    
        data/CHANGELOG.rdoc
    CHANGED
    
    | 
         @@ -1,3 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            == 2.0.pre3
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            * 1 new feature
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              * #select calls now limit the columns that are searched
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            * 1 bugfix
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              * #search calls without an argument assume an empty string as a search term (it errored out previously)
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            == 2.0.pre2
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            * 1 bugfix
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              * #respond_to? wasn't overwritten correctly
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
       1 
17 
     | 
    
         
             
            === 2.0.pre
         
     | 
| 
       2 
18 
     | 
    
         | 
| 
       3 
19 
     | 
    
         
             
            * Complete refactoring of Texticle
         
     | 
    
        data/lib/texticle.rb
    CHANGED
    
    | 
         @@ -2,14 +2,15 @@ require 'active_record' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Texticle
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
              def search(query =  
     | 
| 
      
 5 
     | 
    
         
            +
              def search(query = "")
         
     | 
| 
       6 
6 
     | 
    
         
             
                language = connection.quote('english')
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                exclusive = true
         
     | 
| 
      
 9 
     | 
    
         
            +
                string_columns = columns.select {|column| column.type == :string }.map(&:name)
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
                unless query.is_a?(Hash)
         
     | 
| 
       11 
12 
     | 
    
         
             
                  exclusive = false
         
     | 
| 
       12 
     | 
    
         
            -
                  query =  
     | 
| 
      
 13 
     | 
    
         
            +
                  query = string_columns.inject({}) do |terms, column|
         
     | 
| 
       13 
14 
     | 
    
         
             
                    terms.merge column => query.to_s
         
     | 
| 
       14 
15 
     | 
    
         
             
                  end
         
     | 
| 
       15 
16 
     | 
    
         
             
                end
         
     | 
| 
         @@ -17,6 +18,11 @@ module Texticle 
     | 
|
| 
       17 
18 
     | 
    
         
             
                similarities = []
         
     | 
| 
       18 
19 
     | 
    
         
             
                conditions = []
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
      
 21 
     | 
    
         
            +
                select_values = scoped.select_values.map(&:to_s) & string_columns
         
     | 
| 
      
 22 
     | 
    
         
            +
                query.select! do |column, search_term|
         
     | 
| 
      
 23 
     | 
    
         
            +
                  select_values.include? column
         
     | 
| 
      
 24 
     | 
    
         
            +
                end unless select_values.empty?
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       20 
26 
     | 
    
         
             
                query.each do |column, search_term|
         
     | 
| 
       21 
27 
     | 
    
         
             
                  column = connection.quote_column_name(column)
         
     | 
| 
       22 
28 
     | 
    
         
             
                  search_term = connection.quote normalize(Helper.normalize(search_term))
         
     | 
| 
         @@ -26,7 +32,7 @@ module Texticle 
     | 
|
| 
       26 
32 
     | 
    
         | 
| 
       27 
33 
     | 
    
         
             
                rank = connection.quote_column_name('rank' + rand.to_s)
         
     | 
| 
       28 
34 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
                select("#{quoted_table_name 
     | 
| 
      
 35 
     | 
    
         
            +
                select("#{quoted_table_name + '.*,' if select_values.empty?} #{similarities.join(" + ")} AS #{rank}").
         
     | 
| 
       30 
36 
     | 
    
         
             
                  where(conditions.join(exclusive ? " AND " : " OR ")).
         
     | 
| 
       31 
37 
     | 
    
         
             
                  order("#{rank} DESC")
         
     | 
| 
       32 
38 
     | 
    
         
             
              end
         
     | 
    
        data/spec/texticle_spec.rb
    CHANGED
    
    | 
         @@ -118,6 +118,19 @@ class TexticleTest < Test::Unit::TestCase 
     | 
|
| 
       118 
118 
     | 
    
         
             
                    assert Game.respond_to?(:normalize, true)
         
     | 
| 
       119 
119 
     | 
    
         
             
                  end
         
     | 
| 
       120 
120 
     | 
    
         
             
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                context "when searching after selecting columns to return" do
         
     | 
| 
      
 123 
     | 
    
         
            +
                  should "limit the search to the selected columns" do
         
     | 
| 
      
 124 
     | 
    
         
            +
                    assert_empty Game.select(:system).search("Mario")
         
     | 
| 
      
 125 
     | 
    
         
            +
                    assert_equal @mario.title, Game.select(:title).search("Mario").first.title
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                  should "not fetch extra columns" do
         
     | 
| 
      
 129 
     | 
    
         
            +
                    assert_raise(ActiveModel::MissingAttributeError) do
         
     | 
| 
      
 130 
     | 
    
         
            +
                      Game.select(:title).search("Mario").first.system
         
     | 
| 
      
 131 
     | 
    
         
            +
                    end
         
     | 
| 
      
 132 
     | 
    
         
            +
                  end
         
     | 
| 
      
 133 
     | 
    
         
            +
                end
         
     | 
| 
       121 
134 
     | 
    
         
             
              end
         
     | 
| 
       122 
135 
     | 
    
         | 
| 
       123 
136 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: texticle
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 4
         
     | 
| 
       5 
     | 
    
         
            -
              version: 2.0. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 2.0.pre3
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - ecin
         
     | 
| 
         @@ -11,7 +11,7 @@ autorequire: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            date: 2011- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2011-07-03 00:00:00 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: pg
         
     |