I need to search member's by first name and last name, which I have done successfully. Next thing which I have to do is that member's connection should come first in the list (sorting by connection.), like in Facebook, friends come first in the list and than other users of the community.
I am using grails plugin Searchable. One simple way to do this is to sort the searchListFromSearchable
w.r.t. connection's list.
Following is the domain structure.
class Member extends {
String firstName
String lastName
static searchable = {
analyzer "simple"
only = ['firstName', 'lastName']
firstName boost: 5.0
}
static hasMany = [connections: Connection]
}
And Connection class is as follow
class Connection {
String uuid
Member connectedMember
static belongsTo = [member: Member]
}
Is there any lucene way to do this ?
I think you can add the sort process in the collect step or score step in Lucene. I think you get the relationship first, and when search the member, you can check whether the member is in the relationship or not. If the member is in the relationship, you can add score of this doc, such as write your own collector which extend
TopFieldDocCollector
and addscore *= 10f
beforesuper.collect()
in thecollect
method .