Commit 74320328 authored by sim's avatar sim Committed by delanoe

query_list: Get rid of subquery

parent 4f473a22
...@@ -95,30 +95,19 @@ def query_list(list_id, ...@@ -95,30 +95,19 @@ def query_list(list_id,
else: else:
# NB: score can be undefined (eg ex-subform that now became free) # NB: score can be undefined (eg ex-subform that now became free)
# ==> we need outerjoin # ==> we need outerjoin
# and the filter needs to have scoring_metric_id so we do it before
ScoresTable = (session NNN = NodeNodeNgram
.query(NodeNodeNgram.score, NodeNodeNgram.ngram_id)
.filter(NodeNodeNgram.node1_id == scoring_metric_id)
.subquery()
)
query = (session query = (session
.query( .query(Ngram.id, Ngram.terms, NNN.score)
NodeNgram.ngram_id, # Ngrams must be related to our list <Node(id=list_id)>
Ngram.terms, .join(NodeNgram, (NodeNgram.ngram_id == Ngram.id) &
ScoresTable.c.score (NodeNgram.node_id == list_id))
) # Select by metric <Node(id=scoring_metric_id)>
.join(Ngram, NodeNgram.ngram_id == Ngram.id) .outerjoin(NNN, (NNN.ngram_id == Ngram.id) &
(NNN.node1_id == scoring_metric_id))
# main filter ---------------------- # Sort by descending score
.filter(NodeNgram.node_id == list_id) .order_by(NNN.score.desc())
# scores if possible
.outerjoin(ScoresTable,
ScoresTable.c.ngram_id == NodeNgram.ngram_id)
.order_by(desc(ScoresTable.c.score))
) )
if pagination_limit: if pagination_limit:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment