etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.2k stars 130 forks source link

Boosting items of particular models in search rankings #201

Closed ursomniac closed 6 years ago

ursomniac commented 7 years ago

I have three models that are indexed by django-watson. My stakeholders want one model to get higher rankings in the returned list of objects than the other two.

Is there a way to do this? I saw the "Tweaking search weighting" section in the docs, but I couldn't tell if that would be relevant (or doable) for this purpose. (I suppose I could split the search into two pieces, one for the special model, and the other for "the rest", but if there are other strategies, it'd be great to know about them.)

(Overall though - this package is FANTASTIC in terms of EASILY getting a useful search engine up and running. I've even been able to get it to work with Django CMS's Placeholder field content with almost NO effort whatsoever by indexing a custom property.)

etianen commented 7 years ago

You can bump something to the top by ordering by two fields:

watson.filter(SomeModel, "some query").order_by("-is_important", "-watson_rank")

This would only work for searching one model at a time, and would require an "is_important" boolean field on that model.

Of course, this would mean that is_important models would ALWAYS appear at the top of the search rankings.

On Fri, 5 May 2017 at 14:55 Bob Donahue notifications@github.com wrote:

I have three models that are indexed by django-watson. My stakeholders want one model to get higher rankings in the returned list of objects than the other two.

Is there a way to do this? I saw the "Tweaking search weighting" section in the docs, but I couldn't tell if that would be relevant (or doable) for this purpose. (I suppose I could split the search into two pieces, one for the special model, and the other for "the rest", but if there are other strategies, it'd be great to know about them.)

(Overall though - this package is FANTASTIC in terms of EASILY getting a useful search engine up and running. I've even been able to get it to work with Django CMS's Placeholder field content with almost NO effort whatsoever by indexing a custom property.)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/201, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJFCAWwW9sAMtvXSL3POROBjfa2lFRKks5r2ypQgaJpZM4NR8yD .

danielsamuels commented 7 years ago

Related to this, is there a way to boost items based on a particular metric? In our case we're looking to make recently added news articles appear more prominently than older articles. Is this possible without completely changing the ordering logic to be -date, -watson_rank?

etianen commented 7 years ago

I guess you could use the extra() method to add a new column called "foo_rank" that is a number calculated from watson_rank and date, somehow, then order by that column. On Wed, 17 May 2017 at 14:06, Daniel Samuels notifications@github.com wrote:

Related to this, is there a way to boost items based on a particular metric? In our case we're looking to make recently added news articles appear more prominently than older articles. Is this possible without completely changing the ordering logic to be -date, -watson_rank?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/etianen/django-watson/issues/201#issuecomment-302084010, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJFCDMp4ZPCvNzfVWLi28laNO3Mjr2dks5r6vDGgaJpZM4NR8yD .

danielsamuels commented 7 years ago

watson_rank * 1 + 1 / ((now() - obj.date).days I guess. I haven't looked into watson_rank as a value though. Seems like that would be a reasonable starting point though, thanks.