Sphinx on Rails

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    8 Favorites & 1 Event

    Sphinx on Rails - Presentation Transcript

    1. Sphinx on Rails
    2. Fast and Painless Full-Text Searching
    3. Pat Allan http://freelancing-gods.com http://twitter.com/pat
    4. Searching can be ugly...
    5. SELECT * FROM users WHERE first_name LIKE '%query%' OR last_name LIKE '%query%' OR email LIKE '%query%' OR location LIKE '%query%';
    6. SELECT * FROM users WHERE (first_name LIKE '%one%' OR first_name LIKE '%two%') OR (last_name LIKE '%one%' OR last_name LIKE '%two%') ...
    7. ... very ugly
    8. Sphinx to the rescue!
    9. Indexes Documents
    10. Queries Document Indexes
    11. Similar to: • Lucene • Xapian •Ferret •Solr
    12. MySQL
    13. PostgreSQL
    14. XML
    15. • C • Perl •C++ •PHP •C# •Python •Java •Ruby •Haskell
    16. Ruby
    17. Ruby on Rails
    18. How?
    19. acts as sphinx
    20. Sphincter
    21. Ultrasphinx
    22. Thinking Sphinx
    23. script/plugin install git://github.com/freelancing-god/ thinking-sphinx.git
    24. class User < ActiveRecord::Base # end
    25. class User < ActiveRecord::Base define_index do indexes first_name indexes last_name indexes email indexes location end end
    26. rake thinking_sphinx:index rake thinking_sphinx:start
    27. SELECT * FROM users WHERE first_name LIKE '%query%' OR last_name LIKE '%query%' OR email LIKE '%query%' OR location LIKE '%query%';
    28. User.search \"query\"
    29. SELECT * FROM users WHERE (first_name LIKE '%one%' OR first_name LIKE '%two%') OR (last_name LIKE '%one%' OR last_name LIKE '%two%') ...
    30. User.search \"one two\", :match_mode => :any
    31. Wait! You forgot something...
    32. Pagination
    33. @users = User.search \"query\"
    34. <%= will_paginate @users %>
    35. @users = User.search \"query\", :page => (params[:page] || 0)
    36. Sorting
    37. Attributes != Fields
    38. Fields are for Searching
    39. Attributes are for Filtering and Sorting
    40. class User < ActiveRecord::Base define_index do # ... has created_at end end
    41. User.search \"Melbourne\", :order => :created_at
    42. class User < ActiveRecord::Base define_index do # ... indexes last_name, :sortable => true # ... end end
    43. User.search \"Melbourne\", :order => :last_name
    44. Filtering
    45. class User < ActiveRecord::Base define_index do # ... has active end end
    46. User.search \"Melbourne\", :with => {:active => 1}
    47. User.search \"Melbourne\", :with => { :created_at => ( 1.year.ago..Time.now ) }
    48. User.search :conditions => { :first_name => \"Pat\" }
    49. Weighting
    50. User.search \"Melbourne\", :field_weights => { \"first_name\" => 10, \"last_name\" => 10, \"location\" => 5 }
    51. class User < ActiveRecord::Base define_index do # ... set_property :field_weights => { \"first_name\" => 10, \"last_name\" => 10, \"location\" => 5 } end end
    52. Indexing Everything
    53. Sphinx lets you dig your own grave
    54. class User < ActiveRecord::Base has_many :articles define_index do indexes articles.subject, :as => :subjects # ... end end
    55. Complex SQL = Slower Indexing
    56. Searching Everything
    57. ThinkingSphinx::Search.search( \"query\" )
    58. Geo-location Searching
    59. class User < ActiveRecord::Base define_index do # ... has lat, lng end end
    60. rake thinking_sphinx:stop rake thinking_sphinx:index rake thinking_sphinx:start
    61. User.search :geo => [ -0.591376, 2.638356 ]
    62. What’s the catch?
    63. Sphinx is a bit all-or-nothing
    64. User.create( :first_name => \"Pat\", :last_name => \"Allan\" )
    65. User.search \"Pat\" #=> []
    66. rake thinking_sphinx:index
    67. rake thinking_sphinx:index
    68. δ to the rescue
    69. δelta to the rescue
    70. class User < ActiveRecord::Base define_index do # ... set_property :delta => true end end
    71. rake thinking_sphinx:stop rake thinking_sphinx:index rake thinking_sphinx:start
    72. User.create( :first_name => \"Pat\", :last_name => \"Allan\" )
    73. User.search \"Pat\" # => [#<User ...>]
    74. So err, what just happened?
    75. core
    76. δelta
    77. core δelta
    78. rake thinking_sphinx:index
    79. core
    80. Merb?
    81. ActiveRecord
    82. DataMapper?
    83. Soon!
    84. Well Soon-ish
    85. Okay, I’ll stop talking now...
    86. Questions?

    + freelancing_godfreelancing_god, 11 months ago

    custom

    2203 views, 8 favs, 1 embeds more stats

    Presentation from OSDC 2008 in Sydney, on using Sph more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2203
      • 2202 on SlideShare
      • 1 from embeds
    • Comments 0
    • Favorites 8
    • Downloads 47
    Most viewed embeds
    • 1 views on http://monicabulger.com

    more

    All embeds
    • 1 views on http://monicabulger.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events