Mogę się mylić (bo nie wdrażałem takich rzeczy na poważnie), ale Sphinx czy ElasticSearch pozwolą Tobie stworzyć odpowiednie indeksy i sposoby na odpytywanie.
Do 3 pkt najlepiej zrób sobie counter cache na relacji znajomych i dodaj go do indeksu, wtedy możesz już analogicznie jak wyżej łatwo to filtrować zakresem.
Albo opcja druga, do indeksu dorzuć też id znajomych
indexes :friends, type: 'object' do
indexes :id, type: 'string', index: 'not_analyzed'
end
A potem dodajesz filtr
[code=ruby] Tire.search ‘profiles’ do
query do
custom_filters_score do
query { all }
# If currently available, give a score of 2
filter do
filter :range, available_at: { gte: Date.today }
boost 2
end
# If Profile is a Profile of a Company Member, give this profile a score of 10.
filter do
filter :term, { company_type: 'intern' }
boost 10
end
# If at least personally known by one person, give a score of 3, not more
filter do
filter :range, friends_count: { from: 1 }
boost 3
end
# If blacklisted, show this profile on the end of the result list, not depending on the score.
filter do
filter :term, { blacklisted: true }
boost -100
end
# Foreach Matching "Tag", give a score of 4 if tag has flag focus give a score of 5.
score_mode :total
end
end[/code]
Zastanawiam się jak w tym przypadku wyszukiwać tagi, czy przekać je w indexie ‘profiles’ czy zrobić nowy index ‘tags’ z atrybutem ‘profile_id’(tylko jak potem je połączyć?
def to_indexed_json
{ name: self.name,
company_type: self.company.company_type,
}.to_json(:include=>{:tags=>{:only=>[:id, :name}} )
end
A potem powinno się dać szukać poprzez: