Skip to content

Commit

Permalink
Improved and fixed boost exact hit with autocomplete (#16).
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMikita committed Jul 22, 2016
1 parent be9a7f0 commit a7a1e5e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions web/websearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,16 @@ def process_query_mysql(index, query, query_filter, start=0, count=0):
option = "field_weights = (name = 100, display_name = 1)"
option += ", retry_count = 2, retry_delay = 500, max_matches = 200, max_query_time = 10000"
option += ", ranker=expr('sum((10*lcs+5*exact_order+5*exact_hit+5*wlccs)*user_weight)*1000+bm25')"
sql = "SELECT WEIGHT()*importance+IF(name=%s,1000000,0) as weight, * FROM {} WHERE {} ORDER BY {} LIMIT %s, %s OPTION {};".format(
# Prepare query for boost
query_elements = re.compile("\s*,\s*|\s+").split(query)
select_boost = []
argsBoost = []
for qe in query_elements:
qe = re.sub(r"\**", "", qe)
select_boost.append('IF(name=%s,1000000,0)')
argsBoost.append(qe)
sql = "SELECT WEIGHT()*importance+{} as weight, * FROM {} WHERE {} ORDER BY {} LIMIT %s, %s OPTION {};".format(
'+'.join(select_boost),
index,
' AND '.join(whereFilter),
', '.join(sortBy),
Expand All @@ -222,7 +231,7 @@ def process_query_mysql(index, query, query_filter, start=0, count=0):
}

try:
args = [query] + argsFilter + [start, count]
args = argsBoost + argsFilter + [start, count]
q = cursor.execute(sql, args)
pprint([sql, args, cursor._last_executed, q])
desc = cursor.description
Expand Down

0 comments on commit a7a1e5e

Please sign in to comment.