Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use xapian to implement searching questions

Signed-off-by: Jorge H. Cuadrado <kuadrosxx@gmail.com>
  • Loading branch information...
commit ebf017058b6f6e7cadf92d701c3e6a19ac196f2e 1 parent 58bf535
@kuadrosx kuadrosx authored
View
3  Gemfile
@@ -73,6 +73,9 @@ gem 'rack-ssl', :require => false
gem 'state_machine', "0.10.4"
+gem "xapian-ruby"
+gem "xapit", :git => "git://github.com/dcu/xapit.git"
+
group :deploy do
gem 'capistrano', :require => false
gem 'ricodigo-capistrano-recipes', "~> 0.1.3", :require => false
View
22 Gemfile.lock
@@ -20,6 +20,13 @@ GIT
net-ssh (>= 2.0.15)
GIT
+ remote: git://github.com/dcu/xapit.git
+ revision: 6f44a9432a460fa7efc85e0fb2dd82414bedfa57
+ specs:
+ xapit (0.3.0)
+ rack (~> 1.2.2)
+
+GIT
remote: git://github.com/jdpace/PDFKit.git
revision: f468adae4bc4e991614a0d0e0a29efeef3e817c9
specs:
@@ -127,7 +134,7 @@ GEM
bson (1.3.0)
bson_ext (1.3.0)
builder (2.1.2)
- capistrano (2.8.0)
+ capistrano (2.9.0)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
@@ -136,7 +143,7 @@ GEM
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
chronic (0.6.4)
- chunky_png (1.2.4)
+ chunky_png (1.2.5)
columnize (0.3.4)
compass (0.11.1)
chunky_png (~> 1.1)
@@ -147,7 +154,7 @@ GEM
configuration (1.3.1)
daemons (1.0.10)
database_cleaner (0.6.7)
- devise (1.4.5)
+ devise (1.4.7)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
@@ -358,13 +365,13 @@ GEM
ruby-stemmer (0.8.5)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
- ruby_parser (2.3.0)
+ ruby_parser (2.3.1)
sexp_processor (~> 3.0)
rubyntlm (0.1.1)
sanitize (1.2.1)
nokogiri (~> 1.4.1)
sass (3.1.7)
- sexp_processor (3.0.6)
+ sexp_processor (3.0.7)
simple_oauth (0.1.5)
simplecov (0.5.3)
multi_json (~> 1.0.3)
@@ -402,12 +409,13 @@ GEM
uuidtools (2.1.2)
warden (1.0.5)
rack (>= 1.0)
- webrobots (0.0.11)
+ webrobots (0.0.12)
nokogiri (>= 1.4.4)
whatlanguage (1.0.0)
whenever (0.7.0)
activesupport (>= 2.3.4)
chronic (~> 0.6.3)
+ xapian-ruby (1.2.7)
yui-compressor (0.9.6)
POpen4 (>= 0.1.4)
@@ -480,3 +488,5 @@ DEPENDENCIES
uuidtools (~> 2.1.1)
whatlanguage (= 1.0.0)
whenever
+ xapian-ruby
+ xapit!
View
10 app/controllers/searches_controller.rb
@@ -9,9 +9,9 @@ def index
options = {}
unless params[:q].blank?
pharse = params[:q]
- @search_tags = pharse.scan(/\[(\w+)\]/).flatten
+# @search_tags = pharse.scan(/\[(\w+)\]/).flatten
@search_text = pharse.gsub(/\[(\w+)\]/, "")
- options[:tags] = {:$all => @search_tags} unless @search_tags.empty?
+# options[:tags] = {:$all => @search_tags} unless @search_tags.empty?
options[:group_id] = current_group.id
options[:banned] = false
@@ -31,9 +31,13 @@ def index
if !@search_text.blank?
# FIXME:filter is blocking mongodb
+# @questions = Question.(@search_text, options)
+
+ @questions = Question.search(@search_text).where(options).page(params["page"])
+
# @questions = Question.filter(@search_text, options)
# @highlight = @questions.parsed_query[:tokens].to_a
- @questions = Question.where(options).page(params["page"])
+# @questions = Question.where(options).page(params["page"])
@highlight = ""
else
@questions = Question.where(options).page(params["page"])
View
6 app/models/question.rb
@@ -131,6 +131,12 @@ class Question
validate :disallow_spam
validate :check_useful
+ xapit do
+ text :title, :body
+ field :group_id, :banned
+ facet :user_id, "author"
+ end
+
def self.minimal
without(:_keywords, :close_requests, :open_requests, :versions)
end
View
2  app/views/searches/index.html.haml
@@ -2,7 +2,7 @@
%section
%h1
-unless @questions.blank?
- = t('.found_results', :quantity => @questions.total_count)
+ = t('.found_results', :quantity => @questions.total_entries)
-else
= t('.advanced_search')
View
13 config/xapit.yml
@@ -0,0 +1,13 @@
+# See https://github.com/ryanb/xapit/wiki/Configuration
+development:
+ database_path: "db/xapit"
+ enabled: true
+ spelling: true
+
+test:
+ enabled: false
+ spelling: false
+
+production:
+ database_path: "db/xapit"
+ server: "http://localhost:9292"
View
6 xapit.ru
@@ -0,0 +1,6 @@
+require "rubygems"
+require "xapit"
+
+Xapit.load_config(File.expand_path('../config/xapit.yml', __FILE__), "production")
+
+run Xapit::Server::App.new
Please sign in to comment.
Something went wrong with that request. Please try again.