From 42a869793ab278da9246c337bfb6b35f43d4469a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Mon, 14 Jul 2014 18:30:52 +0200 Subject: [PATCH] [Search] fix Elasticsearch podcast query --- mygpo/search/index.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/mygpo/search/index.py b/mygpo/search/index.py index ec5b0ed1..1a91a777 100644 --- a/mygpo/search/index.py +++ b/mygpo/search/index.py @@ -50,25 +50,16 @@ def create_index(): def search_podcasts(query): """ Search for podcasts according to 'query' """ - conn = ES(settings.ELASTICSEARCH_SERVER) - - # we have some "optimal" number of subscribers (eg the max) - # the farther we get from there, the lower the score - decay = FunctionScoreQuery.DecayFunction( - decay_function='gauss', - field='subscribers', - origin=2000, - scale=1000, - decay=.3, - ) - # workaround for https://github.com/aparo/pyes/pull/418 - decay._internal_name = 'gauss' - - q = FunctionScoreQuery( - query=QueryStringQuery(query), - functions=[decay], - boost_mode=FunctionScoreQuery.BoostModes.MULTIPLY, - ) + conn = get_connection() + + q = { + "custom_score" : { + "query" : { + 'query_string': {'query': query} + }, + "script" : "_score * (doc.subscribers.doubleValue / 4000)" + } + } results = conn.search(query=q, indices=settings.ELASTICSEARCH_INDEX, doc_types='podcast', model=lambda conn, doc: PodcastResult.from_doc(doc)) -- 2.11.4.GIT