0

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 ?

Denim Datta
  • 3,740
  • 3
  • 27
  • 53
Umair Saleem
  • 1,055
  • 5
  • 19

2 Answers2

0

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 .

lbear
  • 790
  • 1
  • 9
  • 16
  • You mean collect of grails, as far as I know is no collect method in Lucene's API. – Umair Saleem Sep 12 '13 at 07:26
  • I'm not sure which `search()` method in `IndexSearcher` you use. There is a mehtod `public void search(Query query, Filter filter, Collector results)` in `IndexSearcher`, I mean the `collect` method in this `Collector`. If you don't use this method, I think you can write your own `Similary` or `Scorer` class to do the sort. Or you can add a term and give the same value in indexing step, and make your own sort with this term using `relationship`. – lbear Sep 12 '13 at 12:16
  • What I am trying currently is to index the connection domain class which contain both member(connectedMember and member) as mentioned in the above domain class. I think it can solve the problem. But I have noticed that the index file which was previously 6.5 MB is now 12 MB. Any suggestion on this approach ? – Umair Saleem Sep 12 '13 at 14:36
  • I tried following query $/Connection/connectedMember/firstName:a* AND $/Connection/member/id:14) Where 14 is the id of logged in member. Any document returned will be the connection. – Umair Saleem Sep 12 '13 at 14:37
0

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.

Alexander Kuznetsov
  • 3,062
  • 2
  • 25
  • 29