Skip to content

Commit

Permalink
Recherches ok
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaltrine committed Mar 7, 2016
1 parent daa0ae2 commit eea37ea
Show file tree
Hide file tree
Showing 166 changed files with 70 additions and 70 deletions.
21 changes: 10 additions & 11 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
class UsersController < ApplicationController
def show
@user = User.find(params[:id]);
end
def show
@user = User.find(params[:id]);
end

def index
@search = Sunspot.search(Advert) do
# utilisation de sunspot pour les recherches, Kaminari pour la pagination
def index
@search = Sunspot.search(Advert) do
fulltext params[:q]
order_by(:topic_id, "desc")
#paginate :page => params[:page], :per_page => 5
#paginate(:page => params[:page] || 1, :per_page => 2)
#group :user_email do
# limit 100
#group_field
#end
with(:user_age).greater_than_or_equal_to(params[:age_min]) unless params[:age_min].blank?
with(:user_age).less_than_or_equal_to(params[:age_max]) unless params[:age_max].blank?
with(:advert_prices_truc).greater_than(params[:min_price]) unless params[:min_price].blank?
with(:advert_prices_truc).less_than(params[:max_price]) unless params[:max_price].blank?
end
#@users = @search.results
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def initialize(user)
can :destroy, AdvertPrice, :advert => {:user_id => user.id}
can :update, Advert, :user_id => user.id
can :update, AdvertPrice, :advert => {:user_id => user.id}
can :create, Degree, :teacher => {:type => 'Teacher'}
can :create, Degree if user.is_a? Teacher
can :read, Degree, :user_id => user.id
can :update, Degree, :user_id => user.id
can :destroy, Degree, :user_id => user.id
Expand Down
21 changes: 21 additions & 0 deletions app/models/advert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ class Advert < ActiveRecord::Base
:reject_if => :all_blank
#after_create :create_price

def min_price
self.advert_prices.order('price DESC').map{|p| p.price}.last
end
def max_price
self.advert_prices.order('price DESC').map{|p| p.price}.first
end
def find_topic_group
self.topic.topic_group.title
end
def create_price
AdvertPrice.create(:advert_id => self.id)
end

# Pour Sunspot, définition des champs sur lesquels les recherches sont faites et des champs sur lesquels les filtres sont réalisés
searchable do
text :other_name
text :user do
Expand All @@ -19,10 +30,20 @@ def create_price
text :topic do
topic.title
end
text :topic_group do
self.find_topic_group
end
integer :topic_id, :references => Topic
string :user_email do
user.email
end
string :user_age do
Time.now.year - user.birthdate.year
end

string :advert_prices_truc , :multiple => true do
advert_prices.map{|p| p.price}
end

end
end
6 changes: 0 additions & 6 deletions app/models/advert_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,4 @@ class AdvertPrice < ActiveRecord::Base
belongs_to :level
belongs_to :advert

searchable do
text :level do
level(&:be)
end
end

end
4 changes: 0 additions & 4 deletions app/models/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ class Level < ActiveRecord::Base
has_many :users
has_many :advert_prices
has_one :degree
searchable do
text :be
text :fr
end
end
2 changes: 1 addition & 1 deletion app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Teacher < Student
scope :teacher, -> { where(type: 'Teacher') }

has_one :postulation
has_many :degrees
has_many :degrees, foreign_key: "user_id"

# Methode override de User bloquant le type de User à Teacher au maximum
public
Expand Down
8 changes: 0 additions & 8 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,4 @@ class Topic < ActiveRecord::Base
belongs_to :topic_group
has_many :adverts

searchable do
text :title
text :topic_group do
topic_group.title
end
#integer :topic_group_id, :references => TopicGroup
end

end
3 changes: 0 additions & 3 deletions app/models/topic_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ class TopicGroup < ActiveRecord::Base

has_many :topics

searchable do
text :title
end
end
39 changes: 10 additions & 29 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class User < ActiveRecord::Base
validates_date :birthdate, :on_or_before => lambda { Date.current }
# Update de l'avatar pour le crop
after_update :reprocess_avatar, :if => :cropping?

has_one :gallery
has_many :conversations, :foreign_key => :sender_id
has_many :adverts
Expand All @@ -38,6 +37,16 @@ class User < ActiveRecord::Base
has_many :sent_comment, :class_name => 'Comment', :foreign_key => 'sender_id'
has_many :received_comment, :class_name => 'Comment', :foreign_key => 'subject_id'

def level_max
if Degree.where(:user_id=>self).map{|t| t.level}.max.blank?
nil
else
Degree.where(:user_id=>self).map{|t| t.level}.max.id
end
#self.degrees.map{|t| t.level}.max.id

end

# Méthode permettant de créer une gallery
def create_gallery
Gallery.create(:user_id => self.id)
Expand Down Expand Up @@ -109,32 +118,4 @@ def become_admin
self.save
end

searchable do
/ text :email
text :firstname
text :adverts do
# works
adverts.map { |adv| adv.other_name }
# Doesn't work
adverts.map { |adv| adv.topic(&:title) }
self.adverts.map { |e| e.advert_prices.map { |k| k.level_id } }.each do |s|
s.each do |t|
Level.find(t).be
end
end
#adverts.map { |adv| adv.other_name }
#adverts.map{|e| e.advert_prices.map {|k| k.level(&:be)}}
end/
end

def user_levels
self.adverts.map { |e| e.advert_prices.map { |k| k.level_id } }.each do |s|

end
end

end
6 changes: 3 additions & 3 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>
<div class="field">
<%= f.label :description %><br/>
<%= f.text_field :description %>
<%= f.text_area :description %>
</div>

<div class="field">
Expand All @@ -28,12 +28,12 @@
<%= f.label :type %><br/>
<%= f.select :type, User::ACCOUNT_TYPES %>
</div>
<div class="field">
<% end %>
<div class="field">
<% levels = Level.select('distinct(' + I18n.locale[0..3] + '), id,' + I18n.locale[0..3] + '').where(:code => "scolaire").group(I18n.locale[0..3]).order(:id) %>
<%= f.label :level_id %><br/>
<%= f.select :level_id, levels.all.collect { |p| [p[I18n.locale[0..3]], p.id] } %>
</div>
<% end %>
<!-- if teacher, cannot change account type anymore -->
<% if resource.type == "Teacher" %>
<div class="field">
Expand Down
26 changes: 23 additions & 3 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<%= form_tag users_path, :method => :get do %>
<p>
<%= text_field_tag :q, params[:search] %>
<%= label_tag "Mot-clé" %>
<%= text_field_tag :q, params[:search] %><br>
<%= label_tag "Age : " %>
<%= label_tag "De" %>
<%= number_field_tag :age_min, params[:age_min] %>
<%= label_tag "A" %>
<%= number_field_tag :age_max, params[:age_max] %><br>
<%= label_tag "Diplome" %>
<% levels = Level.select('distinct(' + I18n.locale[0..3] + '), id,' + I18n.locale[0..3] + '').where(:code => "scolaire").group(I18n.locale[0..3]).order(:id) %>
<%= select_tag :degree_id, options_for_select(levels.all.collect { |p| [p[I18n.locale[0..3]], p.id] }), :include_blank => true %>
<br>
<%= label_tag "Prix : " %>
<%= label_tag "De" %>
<%= number_field_tag :min_price, params[:min_price] %>
<%= label_tag "A" %>
<%= number_field_tag :max_price, params[:max_price] %><br>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
Expand All @@ -14,8 +29,13 @@
<% end %>
<% h[x.user_id].push(x) %>
<% end %>
<% @pagin = User.where(:id => h.keys, :postulance_accepted => true).page(params[:page]).per(15) %>
<% #@pagin = Kaminari.paginate_array(@table).page(params[:page]).per(1) %>
<% @pagin %>
<% if params[:degree_id].blank? %>
<% @pagin = User.where(:id => h.keys, :postulance_accepted => true).order(:level_id).page(params[:page]).per(15) %>
<% else %>
<% @pagin = User.where(:id => h.keys, :postulance_accepted => true).where('level_id >= ?', params[:degree_id]).order(:level_id).page(params[:page]).per(15) %>
<% end %>
<% #@pagin = Kaminari.paginate_array(@table).page(params[:page]).per(1) %>
<% @pagin.each do |u| %>
<li>
<p><%= image_tag(u.avatar.url(:small)) %><%= link_to u.email, user_path(u) %></p>
Expand Down
Binary file removed solr/development/data/index/_5l.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5l.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5l.si
Binary file not shown.
Binary file removed solr/development/data/index/_5l_2.liv
Binary file not shown.
Binary file removed solr/development/data/index/_5l_Lucene50_0.doc
Binary file not shown.
Binary file removed solr/development/data/index/_5l_Lucene50_0.pos
Binary file not shown.
Binary file removed solr/development/data/index/_5l_Lucene50_0.tim
Binary file not shown.
Binary file removed solr/development/data/index/_5l_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/_5m.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5m.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5m.fnm
Binary file not shown.
Binary file removed solr/development/data/index/_5m.nvd
Binary file not shown.
Binary file removed solr/development/data/index/_5m.nvm
Binary file not shown.
Binary file removed solr/development/data/index/_5m.si
Binary file not shown.
Binary file removed solr/development/data/index/_5m_Lucene50_0.doc
Binary file not shown.
Binary file removed solr/development/data/index/_5m_Lucene50_0.pos
Binary file not shown.
Binary file removed solr/development/data/index/_5m_Lucene50_0.tim
Binary file not shown.
Binary file removed solr/development/data/index/_5m_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/_5n.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5n.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5n.nvd
Binary file not shown.
Binary file removed solr/development/data/index/_5n.nvm
Binary file not shown.
Binary file removed solr/development/data/index/_5n.si
Binary file not shown.
Binary file removed solr/development/data/index/_5n_Lucene50_0.doc
Binary file not shown.
Binary file removed solr/development/data/index/_5n_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/_5o.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5o.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5o.nvd
Binary file not shown.
Binary file removed solr/development/data/index/_5o.nvm
Binary file not shown.
Binary file removed solr/development/data/index/_5o.si
Binary file not shown.
Binary file removed solr/development/data/index/_5o_Lucene50_0.doc
Binary file not shown.
Binary file removed solr/development/data/index/_5o_Lucene50_0.pos
Binary file not shown.
Binary file removed solr/development/data/index/_5o_Lucene50_0.tim
Binary file not shown.
Binary file removed solr/development/data/index/_5o_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/_5p.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5p.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5p.nvd
Binary file not shown.
Binary file removed solr/development/data/index/_5p.nvm
Binary file not shown.
Binary file removed solr/development/data/index/_5p.si
Binary file not shown.
Binary file removed solr/development/data/index/_5p_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/_5q.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5q.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5q.nvd
Binary file not shown.
Binary file removed solr/development/data/index/_5q.nvm
Binary file not shown.
Binary file removed solr/development/data/index/_5q.si
Binary file not shown.
Binary file removed solr/development/data/index/_5q_Lucene50_0.pos
Binary file not shown.
Binary file removed solr/development/data/index/_5r.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5r.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5r.si
Binary file not shown.
Binary file removed solr/development/data/index/_5r_Lucene50_0.doc
Binary file not shown.
Binary file removed solr/development/data/index/_5r_Lucene50_0.pos
Binary file not shown.
Binary file removed solr/development/data/index/_5r_Lucene50_0.tim
Binary file not shown.
Binary file removed solr/development/data/index/_5r_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/_5s.fdt
Binary file not shown.
Binary file removed solr/development/data/index/_5s.fdx
Binary file not shown.
Binary file removed solr/development/data/index/_5s.si
Binary file not shown.
Binary file removed solr/development/data/index/_5s_Lucene50_0.doc
Binary file not shown.
Binary file removed solr/development/data/index/_5s_Lucene50_0.pos
Binary file not shown.
Binary file removed solr/development/data/index/_5s_Lucene50_0.tim
Binary file not shown.
Binary file removed solr/development/data/index/_5s_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9o.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9o.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9o.si
Binary file not shown.
Binary file added solr/development/data/index/_9o_1.liv
Binary file not shown.
Binary file added solr/development/data/index/_9o_Lucene50_0.doc
Binary file not shown.
Binary file added solr/development/data/index/_9o_Lucene50_0.pos
Binary file not shown.
Binary file added solr/development/data/index/_9o_Lucene50_0.tim
Binary file not shown.
Binary file added solr/development/data/index/_9o_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9q.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9q.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9q.nvd
Binary file not shown.
Binary file added solr/development/data/index/_9q.nvm
Binary file not shown.
Binary file added solr/development/data/index/_9q.si
Binary file not shown.
Binary file added solr/development/data/index/_9q_Lucene50_0.doc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9q_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9r.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9r.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9r.nvd
Binary file not shown.
Binary file added solr/development/data/index/_9r.nvm
Binary file not shown.
Binary file added solr/development/data/index/_9r.si
Binary file not shown.
Binary file added solr/development/data/index/_9r_Lucene50_0.doc
Binary file not shown.
Binary file added solr/development/data/index/_9r_Lucene50_0.pos
Binary file not shown.
Binary file added solr/development/data/index/_9r_Lucene50_0.tim
Binary file not shown.
Binary file added solr/development/data/index/_9r_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9s.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9s.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9s.nvd
Binary file not shown.
Binary file added solr/development/data/index/_9s.nvm
Binary file not shown.
Binary file added solr/development/data/index/_9s.si
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9s_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9t.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9t.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9t.nvd
Binary file not shown.
Binary file added solr/development/data/index/_9t.nvm
Binary file not shown.
Binary file added solr/development/data/index/_9t.si
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9t_Lucene50_0.pos
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9w.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9w.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9w.si
Binary file not shown.
Binary file added solr/development/data/index/_9w_Lucene50_0.doc
Binary file not shown.
Binary file added solr/development/data/index/_9w_Lucene50_0.pos
Binary file not shown.
Binary file added solr/development/data/index/_9w_Lucene50_0.tim
Binary file not shown.
Binary file added solr/development/data/index/_9w_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9x.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9x.fdx
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/index/_9x.si
Binary file not shown.
Binary file added solr/development/data/index/_9x_Lucene50_0.doc
Binary file not shown.
Binary file added solr/development/data/index/_9x_Lucene50_0.pos
Binary file not shown.
Binary file added solr/development/data/index/_9x_Lucene50_0.tim
Binary file not shown.
Binary file added solr/development/data/index/_9x_Lucene50_0.tip
Binary file not shown.
Binary file added solr/development/data/index/_9z.fdt
Binary file not shown.
Binary file added solr/development/data/index/_9z.fdx
Binary file not shown.
Binary file added solr/development/data/index/_9z.fnm
Binary file not shown.
Binary file added solr/development/data/index/_9z.nvd
Binary file not shown.
Binary file added solr/development/data/index/_9z.nvm
Binary file not shown.
Binary file added solr/development/data/index/_9z.si
Binary file not shown.
Binary file added solr/development/data/index/_9z_Lucene50_0.doc
Binary file not shown.
Binary file added solr/development/data/index/_9z_Lucene50_0.pos
Binary file not shown.
Binary file added solr/development/data/index/_9z_Lucene50_0.tim
Binary file not shown.
Binary file added solr/development/data/index/_9z_Lucene50_0.tip
Binary file not shown.
Binary file removed solr/development/data/index/segments_5y
Binary file not shown.
Binary file added solr/development/data/index/segments_ad
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000211
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000212
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000213
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000214
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000215
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000216
Binary file not shown.
Binary file removed solr/development/data/tlog/tlog.0000000000000000217
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000379
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000381
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000382
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000383
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000384
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000385
Binary file not shown.
Binary file added solr/development/data/tlog/tlog.0000000000000000386
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion solr/pids/development/sunspot-solr-development.pid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1125
792

0 comments on commit eea37ea

Please sign in to comment.