Increase Solr request time (Sunspot) when searching without keywords

Given that I want to find 20 relevant results, how would I start raising the first criteria inside any_of (with (: id) .any_of (co_author_ids)), so if there are 20 results that match the specified criteria, they will return as opposed to matching attempts based on the second criteria?

@solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email, true) any_of do with(:id).any_of(co_author_ids) with(:hospitals_id).any_of(hopital_ids) end end 

Initially, I did not think that raising was necessary, since I thought that any_of would have a cascading effect, but it does not seem to work like that. I know who should do query time by increasing keywords and full-text search, but could not get it to work with methods ().

+4
source share
1 answer

since co_author_ids is a multi-valued key, I have good reason to believe that this does not exist. although with keys with a single value, you can achieve this cascading effect using sorting solr, using a function request. http://wiki.apache.org/solr/FunctionQuery#Sort_By_Function with adjust_solr options http://sunspot.imtqy.com/docs/Sunspot/DSL/Adjustable.html

Example: suppose you have a query like this:

 @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email, true) any_of do with(:id,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end end 

and now in this case you want to have a cascading effect and want to give more preference to exact matches with author_id, you can do this.

 @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email, true) any_of do with(:id,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end adjust_solr_params do |p| p["sort"] = "if(author_id_i = #{id},1,0) desc" #note author_id_i solr eq of author_id end end 

therefore, it will be sorted based on the value of if (author_id_i = # {id}, 1,0) and in return will put all records with auhtor_id as the same from the user on top.

i somehow had problems using the IF function, so instead I used (practically, both of them are the same):

 @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email, true) any_of do with(:id,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end adjust_solr_params do |p| p[:sort] = "min(abs(sub(author_id_i,#{id})),1) asc" end end 

I came across this also http://wiki.apache.org/solr/SpatialSearch looking for a solution for this, and if you want to sort by distance, you can do something like:

 @solr_search = User.solr_search do paginate(:per_page => 20) with(:has_email, true) any_of do with(:id,author_id) #assuming author id is a solr index with(:hospitals_id).any_of(hopital_ids) end adjust_solr_params do |p| p[:pt] = "#{latitude_of_your_interest},#{longitude_of_your_interest}" p[:sfield] = :author_location #your solr index which stores location of the author p[:sort] = "geodist() asc" end end 

In general, I would say that you can do many cool things with p ["sort"], but in this particular case it is impossible to do (imho), because it is a multi-valued field for example: Using a multi-valued field in a map function Request a function Solr that works with multi-valued field counting

I would like them to simply provide an include function for a multi-valued field, and we can simply write p["sort"] ="if(include(co_authors_ids,#{id}), 1, 0) desc"

but at the moment it’s not possible (again imho).

+5
source

All Articles