/
models.rb
138 lines (103 loc) · 2.79 KB
/
models.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
class Tag < ActiveRecord::Base
belongs_to :person
belongs_to :football_team
belongs_to :cricket_team
end
class FootballTeam < ActiveRecord::Base
has_many :tags
end
class CricketTeam < ActiveRecord::Base
define_index do
indexes :name
has "SELECT cricket_team_id, id FROM tags", :source => :query, :as => :tags
end
end
class Contact < ActiveRecord::Base
belongs_to :person
end
class Friendship < ActiveRecord::Base
belongs_to :person
belongs_to :friend, :class_name => "Person", :foreign_key => :friend_id
define_index do
indexes "'something'", :as => :something
has person_id, friend_id
set_property :latitude_attr => :person_id
set_property :longitude_attr => :person_id
end
end
class Link < ActiveRecord::Base
has_and_belongs_to_many :people
end
class Person < ActiveRecord::Base
belongs_to :team, :polymorphic => :true
has_many :contacts
has_many :friendships
has_many :friends, :through => :friendships
has_many :tags
has_many :football_teams, :through => :tags
has_and_belongs_to_many :links
define_index do
indexes [first_name, middle_initial, last_name], :as => :name
indexes team.name, :as => :team_name
indexes contacts.phone_number, :as => :phone_numbers
indexes city, :prefixes => true, :facet => true
indexes state, :infixes => true, :facet => true
has [first_name, middle_initial, last_name], :as => :name_sort
has team.name, :as => :team_name_sort
has [:id, :team_id], :as => :ids
has team(:id), :as => :team_id
has contacts.phone_number, :as => :phone_number_sort
has contacts(:id), :as => :contact_ids
has birthday, :facet => true
has friendships.person_id, :as => :friendly_ids
has :id, :as => :latitude
has :id, :as => :longitude
set_property :delta => true
end
end
class Parent < Person
end
module Admin
class Person < ::Person
end
end
class Child < Person
belongs_to :parent
define_index do
indexes [parent.first_name, parent.middle_initial, parent.last_name], :as => :parent_name
end
end
class Alpha < ActiveRecord::Base
has_many :betas
define_index do
indexes :name, :sortable => true
has :id, :as => :lat
has :id, :as => :lng
set_property :field_weights => {"name" => 10}
end
sphinx_scope(:by_name) { |name|
{:conditions => {:name => name}}
}
sphinx_scope(:ids_only) { {:ids_only => true} }
def big_name
name.upcase
end
end
class Beta < ActiveRecord::Base
has_many :gammas
define_index do
indexes :name, :sortable => true
has :id, :as => :lat
has :id, :as => :lon
set_property :delta => true
end
def excerpts
false
end
end
class Gamma < ActiveRecord::Base
#
end
class Search < ActiveRecord::Base
#
end