Lucene Search Sorting

133 views Asked by At

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 ?

2

There are 2 answers

4
lbear On

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 add score *= 10f before super.collect() in the collect method .

0
Alexander Kuznetsov On

On of the solution to add friends ids to index. In this case, your search query should have followed form +name:firstName +name:lastName friend:userId^10. The friendId has a bigger boost and will cause friends to a high rank in your query.