mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
Ditch Solr for pg_search
This commit is contained in:
5
Gemfile
5
Gemfile
@@ -26,10 +26,7 @@ gem 'newrelic_rpm'
|
||||
gem 'pg'
|
||||
gem 'activerecord-import', '~> 0.2.11'
|
||||
gem 'composite_primary_keys'
|
||||
|
||||
# for solr (indexing, searching)
|
||||
gem 'sunspot_rails'#, '2.0.0'
|
||||
gem 'sunspot_solr'#, '2.0.0'
|
||||
gem 'pg_search'
|
||||
|
||||
# so we can create zip-files for genotypes
|
||||
gem 'rubyzip', :git => 'git://github.com/rubyzip/rubyzip.git'
|
||||
|
||||
@@ -225,6 +225,10 @@ GEM
|
||||
cocaine (~> 0.5.3)
|
||||
mime-types
|
||||
pg (0.17.0)
|
||||
pg_search (0.7.8)
|
||||
activerecord (>= 3.1)
|
||||
activesupport (>= 3.1)
|
||||
arel
|
||||
plos (0.0.7)
|
||||
nokogiri
|
||||
rest-client
|
||||
@@ -348,7 +352,6 @@ GEM
|
||||
nokogiri
|
||||
rails (>= 3)
|
||||
sunspot (= 2.1.1)
|
||||
sunspot_solr (2.0.0)
|
||||
temple (0.6.7)
|
||||
therubyracer (0.12.0)
|
||||
libv8 (~> 3.16.14.0)
|
||||
@@ -419,6 +422,7 @@ DEPENDENCIES
|
||||
newrelic_rpm
|
||||
paperclip (~> 4.0)
|
||||
pg
|
||||
pg_search
|
||||
plos
|
||||
pry-rails
|
||||
rails (~> 3.2.18)
|
||||
@@ -438,8 +442,6 @@ DEPENDENCIES
|
||||
slim (~> 1.3.8)
|
||||
spring
|
||||
spring-commands-rspec
|
||||
sunspot_rails
|
||||
sunspot_solr
|
||||
sunspot_test!
|
||||
therubyracer
|
||||
twitter-bootstrap-rails
|
||||
|
||||
@@ -1,24 +1,14 @@
|
||||
class SearchResultsController < ApplicationController
|
||||
|
||||
def search_type(type)
|
||||
return type.solr_search { |p| p.keywords params[:search] }
|
||||
end
|
||||
|
||||
def search
|
||||
@title = "Search results"
|
||||
@snps = search_type Snp
|
||||
@phenotypes = search_type Phenotype
|
||||
@users = search_type User
|
||||
@user_phenotypes = search_type UserPhenotype
|
||||
@snp_comments = search_type SnpComment
|
||||
@phenotype_comments = search_type PhenotypeComment
|
||||
@mendeley_papers = search_type MendeleyPaper
|
||||
@plos_papers = search_type PlosPaper
|
||||
@snpedia_papers = search_type SnpediaPaper
|
||||
@all_len = @snps.results.length + @phenotypes.results.length + @users.results.length +
|
||||
@user_phenotypes.results.length + @snp_comments.results.length + @phenotype_comments.results.length +
|
||||
@mendeley_papers.results.length + @plos_papers.results.length + @snpedia_papers.results.length
|
||||
@title = "Search results"
|
||||
@all_len = 0
|
||||
[
|
||||
:snps, :phenotypes, :users, :user_phenotypes, :snp_comments,
|
||||
:phenotype_comments, :mendeley_papers, :plos_papers, :snpedia_papers,
|
||||
].each do |type|
|
||||
instance_variable_set(:"@#{type}", type.to_s.singularize.camelize.constantize.search(params[:search]))
|
||||
@all_len += instance_variable_get(:"@#{type}").length
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class Achievement < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
attr_accessible :award,:short_name
|
||||
has_many :user_achievements
|
||||
|
||||
searchable do
|
||||
text :award
|
||||
end
|
||||
pg_search_scope :search, against: :award
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class GenomeGovPaper < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :snp_references, as: :paper
|
||||
has_many :snps, through: :snp_references
|
||||
|
||||
searchable do
|
||||
text :title
|
||||
end
|
||||
pg_search_scope :search, against: :title
|
||||
end
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
class MendeleyPaper < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :snp_references, as: :paper
|
||||
has_many :snps, through: :snp_references
|
||||
validates_presence_of :title, :uuid
|
||||
validates_uniqueness_of :uuid
|
||||
|
||||
searchable do
|
||||
text :title
|
||||
end
|
||||
pg_search_scope :search, against: :title
|
||||
|
||||
def first_author
|
||||
read_attribute(:first_author).presence || "Unknown"
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
class PgpAnnotation < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
belongs_to :snp
|
||||
|
||||
searchable do
|
||||
text :gene
|
||||
text :summary
|
||||
text :trait
|
||||
end
|
||||
pg_search_scope :search, against: [:search, :summary, :trait]
|
||||
end
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
class Phenotype < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :user_phenotypes, dependent: :destroy
|
||||
has_many :phenotype_comments, dependent: :destroy
|
||||
has_and_belongs_to_many :phenotype_sets
|
||||
|
||||
validates_presence_of :characteristic
|
||||
|
||||
searchable do
|
||||
text :characteristic
|
||||
end
|
||||
|
||||
pg_search_scope :search, against: :characteristic
|
||||
|
||||
def known_phenotypes
|
||||
if @known_phenotypes.nil?
|
||||
@known_phenotypes =
|
||||
user_phenotypes.select('variation').all.
|
||||
map!(&:variation).
|
||||
map!(&:capitalize)
|
||||
@known_phenotypes = user_phenotypes.pluck(:variation).map(&:capitalize)
|
||||
@known_phenotypes.uniq!
|
||||
@known_phenotypes.compact
|
||||
end
|
||||
@known_phenotypes
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class PhenotypeComment < ActiveRecord::Base
|
||||
belongs_to :phenotype
|
||||
belongs_to :user
|
||||
|
||||
searchable do
|
||||
text :comment_text, :subject
|
||||
end
|
||||
include PgSearch
|
||||
|
||||
belongs_to :phenotype
|
||||
belongs_to :user
|
||||
|
||||
pg_search_scope :search, against: [:comment_text, :subject]
|
||||
end
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
class PhenotypeSet < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_and_belongs_to_many :phenotypes
|
||||
|
||||
validates_presence_of :title,:description
|
||||
|
||||
searchable do
|
||||
text :title
|
||||
end
|
||||
|
||||
|
||||
pg_search_scope :search, against: :title
|
||||
end
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
class PicturePhenotype < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :user_picture_phenotypes, dependent: :destroy
|
||||
has_many :picture_phenotype_comments, dependent: :destroy
|
||||
#has_and_belongs_to_many :phenotype_sets
|
||||
|
||||
validates_presence_of :characteristic
|
||||
|
||||
searchable do
|
||||
text :characteristic
|
||||
end
|
||||
|
||||
end
|
||||
pg_search_scope :search, against: :characteristic
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class PicturePhenotypeComment < ActiveRecord::Base
|
||||
belongs_to :picture_phenotype
|
||||
belongs_to :user
|
||||
|
||||
searchable do
|
||||
text :comment_text, :subject
|
||||
end
|
||||
include PgSearch
|
||||
|
||||
belongs_to :picture_phenotype
|
||||
belongs_to :user
|
||||
|
||||
pg_search_scope :search, against: [:comment_text, :subject]
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class PlosPaper < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :snp_references, as: :paper
|
||||
has_many :snps, through: :snp_references
|
||||
|
||||
searchable do
|
||||
text :title
|
||||
end
|
||||
pg_search_scope :search, against: :title
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class Snp < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :user_snps, foreign_key: :snp_name, primary_key: :name
|
||||
has_many :users, through: :user_snps
|
||||
has_many :pgp_annotations
|
||||
@@ -13,9 +15,7 @@ class Snp < ActiveRecord::Base
|
||||
|
||||
validates_uniqueness_of :name
|
||||
|
||||
searchable :ignore_attribute_changes_of => [:genotype_frequency, :allele_frequency, :ranking, :number_of_users, :mendeley_updated, :plos_updated, :snpedia_updated, :user_snps_count, :updated_at] do
|
||||
text :name
|
||||
end
|
||||
pg_search_scope :search, against: :name
|
||||
|
||||
after_create :default_frequencies
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
class SnpComment < ActiveRecord::Base
|
||||
belongs_to :snp
|
||||
belongs_to :user
|
||||
|
||||
searchable do
|
||||
text :comment_text, :subject
|
||||
end
|
||||
include PgSearch
|
||||
|
||||
belongs_to :snp
|
||||
belongs_to :user
|
||||
|
||||
pg_search_scope :search, against: :subject
|
||||
end
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class SnpediaPaper < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_many :snp_references, as: :paper
|
||||
has_many :snps, through: :snp_references
|
||||
|
||||
searchable do
|
||||
text :summary
|
||||
end
|
||||
pg_search_scope :search, against: :summary
|
||||
|
||||
def summary
|
||||
read_attribute(:summary).presence || "No summary provided."
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class User < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
has_attached_file :avatar,
|
||||
styles: { medium: "300x300>", thumb: "100x100>#", head: "32x32#" },
|
||||
default_url: 'standard_:style.png'
|
||||
@@ -45,10 +47,7 @@ class User < ActiveRecord::Base
|
||||
accepts_nested_attributes_for :homepages, allow_destroy: true
|
||||
accepts_nested_attributes_for :user_phenotypes, allow_destroy: true
|
||||
|
||||
# The following should turn off auto-reindex of user on login
|
||||
searchable :ignore_attribute_changes_of => [:persistence_token, :perishable_token, :updated_at] do
|
||||
text :description, :name
|
||||
end
|
||||
pg_search_scope :search, against: [:description, :name]
|
||||
|
||||
def deliver_password_reset_instructions!
|
||||
reset_perishable_token!
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
class UserPhenotype < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
belongs_to :phenotype
|
||||
belongs_to :user
|
||||
validates_presence_of :variation
|
||||
|
||||
attr_accessible :variation,:phenotype_id,:js_modal
|
||||
|
||||
searchable do
|
||||
text :variation
|
||||
integer :phenotype_id
|
||||
end
|
||||
pg_search_scope :search, against: [:variation, :phenotype_id]
|
||||
|
||||
def give_me_user_phenotype(phenotype_id, user_id)
|
||||
# needed for the phenotype_set_forms
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class UserPicturePhenotype < ActiveRecord::Base
|
||||
include PgSearch
|
||||
|
||||
belongs_to :picture_phenotype
|
||||
belongs_to :user
|
||||
|
||||
@@ -11,9 +13,7 @@ class UserPicturePhenotype < ActiveRecord::Base
|
||||
validates_attachment_content_type :phenotype_picture ,
|
||||
:content_type => ['image/jpeg', 'image/png', 'image/gif']
|
||||
|
||||
searchable do
|
||||
integer :picture_phenotype_id
|
||||
end
|
||||
pg_search_scope :search, against: :picture_phenotype_id
|
||||
|
||||
def give_me_user_phenotype(phenotype_id, user_id)
|
||||
# needed for the phenotype_set_forms
|
||||
|
||||
@@ -2,24 +2,24 @@
|
||||
<%if @all_len != 0 %>
|
||||
<div id="tab-container">
|
||||
<ul class="nav nav-tabs">
|
||||
<%if not @users.results == [] %>
|
||||
<li><a href="#users">Users (<%=@users.results.length%>)</a></li>
|
||||
<%if not @users == [] %>
|
||||
<li><a href="#users">Users (<%=@users.length%>)</a></li>
|
||||
<%end%>
|
||||
<%if not @phenotypes.results == []%>
|
||||
<li><a href="#phenotypes">Phenotypes (<%=@phenotypes.results.length%>)</a></li>
|
||||
<%if not @phenotypes == []%>
|
||||
<li><a href="#phenotypes">Phenotypes (<%=@phenotypes.length%>)</a></li>
|
||||
<%end%>
|
||||
<%if not @snps.results == []%>
|
||||
<li><a href="#snps">SNPs (<%=@snps.results.length%>)</a></li>
|
||||
<%if not @snps == []%>
|
||||
<li><a href="#snps">SNPs (<%=@snps.length%>)</a></li>
|
||||
<%end%>
|
||||
<% if not (@mendeley_papers.results == [] and @plos_papers.results == [])%>
|
||||
<li><a href="#papers">Papers (<%=@plos_papers.results.length + @mendeley_papers.results.length%>)</a></li>
|
||||
<% if not (@mendeley_papers == [] and @plos_papers == [])%>
|
||||
<li><a href="#papers">Papers (<%=@plos_papers.length + @mendeley_papers.length%>)</a></li>
|
||||
<%end%>
|
||||
<%if not (@snp_comments.results == [] and @phenotype_comments.results == [])%>
|
||||
<li><a href="#comments">Comments (<%=@snp_comments.results.length + @phenotype_comments.results.length%>)</a></li>
|
||||
<%if not (@snp_comments == [] and @phenotype_comments == [])%>
|
||||
<li><a href="#comments">Comments (<%=@snp_comments.length + @phenotype_comments.length%>)</a></li>
|
||||
<%end%>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% if not @phenotypes.results == [] %>
|
||||
<% if not @phenotypes == [] %>
|
||||
<div id="phenotypes">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@@ -27,7 +27,7 @@
|
||||
<th># of Users</th>
|
||||
<th>Known Variation</th>
|
||||
</tr>
|
||||
<% for p in @phenotypes.results %>
|
||||
<% for p in @phenotypes %>
|
||||
<tr>
|
||||
<td><%= link_to p.characteristic, p %></td>
|
||||
<td><%= p.number_of_users%></td>
|
||||
@@ -42,7 +42,7 @@
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if not @snps.results == [] %>
|
||||
<% if not @snps == [] %>
|
||||
<div id="snps">
|
||||
<h5>SNPs</h5>
|
||||
<table class="table table-striped">
|
||||
@@ -51,7 +51,7 @@
|
||||
<th>Chromosome</th>
|
||||
<th>Position</th>
|
||||
</tr>
|
||||
<% for p in @snps.results %>
|
||||
<% for p in @snps %>
|
||||
<tr>
|
||||
<td><%= link_to p.name, p %></td>
|
||||
<td><%= p.chromosome %></td>
|
||||
@@ -62,7 +62,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if not @users.results == [] %>
|
||||
<% if not @users == [] %>
|
||||
<div id="users">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@@ -71,7 +71,7 @@
|
||||
<th># of Phenotypes</th>
|
||||
<th># of Achievements</th>
|
||||
</tr>
|
||||
<% for u in @users.results %>
|
||||
<% for u in @users %>
|
||||
<tr>
|
||||
<td><%= image_tag u.avatar.url(:head),:style => "vertical-align:middle"%> <%= link_to u.name, u %></td>
|
||||
<%if u.has_sequence%>
|
||||
@@ -86,9 +86,9 @@
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
<%if not (@snp_comments.results == [] and @phenotype_comments.results == [])%>
|
||||
<%if not (@snp_comments == [] and @phenotype_comments == [])%>
|
||||
<div id="comments">
|
||||
<% if not @snp_comments.results == [] %>
|
||||
<% if not @snp_comments == [] %>
|
||||
<h5>On SNPs</h5>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@@ -97,7 +97,7 @@
|
||||
<th>Subject</th>
|
||||
<th>Text</th>
|
||||
</tr>
|
||||
<% for p in @snp_comments.results %>
|
||||
<% for p in @snp_comments %>
|
||||
<tr>
|
||||
<td><%if p.snp != nil%><%=link_to(p.snp.name,"/snps/"+p.snp.id.to_s+"#comments")%><%else%>SNP was deleted<%end%></td>
|
||||
<% if p.user %>
|
||||
@@ -111,7 +111,7 @@
|
||||
<% end %>
|
||||
</table>
|
||||
<% end %>
|
||||
<% if not @phenotype_comments.results == [] %>
|
||||
<% if not @phenotype_comments == [] %>
|
||||
<h5>On Phenotypes</h5>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@@ -120,7 +120,7 @@
|
||||
<th>Subject</th>
|
||||
<th>Text</th>
|
||||
</tr>
|
||||
<% for p in @phenotype_comments.results %>
|
||||
<% for p in @phenotype_comments %>
|
||||
<tr>
|
||||
<td><%if p.phenotype != nil%><%=link_to(p.phenotype.characteristic,"/snps/"+p.phenotype.id.to_s+"#comments")%><%else%>Phenotype was deleted<%end%></td>
|
||||
<% if p.user %>
|
||||
@@ -136,9 +136,9 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if not (@mendeley_papers.results == [] and @plos_papers.results == [] and @snpedia_papers.results == [])%>
|
||||
<% if not (@mendeley_papers == [] and @plos_papers == [] and @snpedia_papers == [])%>
|
||||
<div id="papers">
|
||||
<% if not @mendeley_papers.results == [] %>
|
||||
<% if not @mendeley_papers == [] %>
|
||||
<h5>Papers on Mendeley</h5>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@@ -149,7 +149,7 @@
|
||||
<th># of Readers</th>
|
||||
<th>DOI</th>
|
||||
</tr>
|
||||
<% for p in @mendeley_papers.results %>
|
||||
<% for p in @mendeley_papers %>
|
||||
<tr>
|
||||
<td><%= p.first_author%></td>
|
||||
<td><%=link_to( p.title, p.mendeley_url)%></td>
|
||||
@@ -169,7 +169,7 @@
|
||||
<% end %>
|
||||
</table>
|
||||
<% end %>
|
||||
<% if not @plos_papers.results == [] %>
|
||||
<% if not @plos_papers == [] %>
|
||||
<h5>Papers at the Public Library of Science</h5>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@@ -179,7 +179,7 @@
|
||||
<th>Year of Publication</th>
|
||||
<th># of Readers</th>
|
||||
</tr>
|
||||
<% for p in @plos_papers.results %>
|
||||
<% for p in @plos_papers %>
|
||||
<tr>
|
||||
<td><%= p.first_author%></td>
|
||||
<td><%= link_to( p.title.html_safe, "http://dx.doi.org/"+p.doi)%></td>
|
||||
@@ -190,14 +190,14 @@
|
||||
<% end %>
|
||||
</table>
|
||||
<% end %>
|
||||
<% if not @snpedia_papers.results == [] %>
|
||||
<% if not @snpedia_papers == [] %>
|
||||
<h5>Entries in the SNPedia</h5>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
<% for p in @snpedia_papers.results %>
|
||||
<% for p in @snpedia_papers %>
|
||||
<tr>
|
||||
<td><% p.snps.each do |m| %> <%=link_to m.name+" "+p.url[-4]+"/"+p.url[-2], p.url%> <% end %></td>
|
||||
<td><%=p.summary%></td>
|
||||
|
||||
10
spec/features/search_spec.rb
Normal file
10
spec/features/search_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'search' do
|
||||
let!(:snp) { create(:snp, name: 'rs123') }
|
||||
|
||||
scenario 'searching' do
|
||||
visit '/search?search=rs123'
|
||||
expect(page).to have_content('rs123')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user