|
|
|
@ -22,7 +22,7 @@ import lxml.html |
|
|
|
|
from asl_rulebook2.utils import plural |
|
|
|
|
from asl_rulebook2.webapp import app |
|
|
|
|
from asl_rulebook2.webapp import startup as webapp_startup |
|
|
|
|
from asl_rulebook2.webapp.content import tag_ruleids |
|
|
|
|
from asl_rulebook2.webapp.content import tag_ruleids, is_main_ruleid |
|
|
|
|
from asl_rulebook2.webapp.utils import make_config_path, make_data_path, split_strip |
|
|
|
|
|
|
|
|
|
_searchdb_fname = None |
|
|
|
@ -168,7 +168,7 @@ def _do_search( args ): |
|
|
|
|
for result in results: |
|
|
|
|
title = result.get( "title", result.get("caption","???") ) |
|
|
|
|
_logger.debug( "- %s: %s (%.3f)", |
|
|
|
|
result["_fts_rowid"], |
|
|
|
|
result.get( "_fts_rowid" ), |
|
|
|
|
title.replace( _BEGIN_HIGHLIGHT, "" ).replace( _END_HIGHLIGHT, "" ), |
|
|
|
|
result["_score"] |
|
|
|
|
) |
|
|
|
@ -381,7 +381,18 @@ def _adjust_sort_order( results ): |
|
|
|
|
"""Adjust the sort order of the search results.""" |
|
|
|
|
|
|
|
|
|
results2 = [] |
|
|
|
|
def extract_sr( func, force=False ): |
|
|
|
|
def extract_sr( func, check_main_rb=False, force=False ): |
|
|
|
|
if check_main_rb: |
|
|
|
|
# extract search results from the main rulebook first |
|
|
|
|
def is_main_rb( sr ): |
|
|
|
|
ruleids = sr.get( "ruleids", [] ) |
|
|
|
|
return ruleids and is_main_ruleid( ruleids[0] ) |
|
|
|
|
do_extract_sr( |
|
|
|
|
lambda sr: func( sr ) and is_main_rb( sr ), |
|
|
|
|
force = force |
|
|
|
|
) |
|
|
|
|
do_extract_sr( func, force=force ) |
|
|
|
|
def do_extract_sr( func, force ): |
|
|
|
|
# move results that pass the filter function to the new list |
|
|
|
|
i = 0 |
|
|
|
|
while True: |
|
|
|
@ -402,19 +413,23 @@ def _adjust_sort_order( results ): |
|
|
|
|
|
|
|
|
|
# prefer search results whose title is an exact match |
|
|
|
|
extract_sr( |
|
|
|
|
lambda sr: get(sr,"title").startswith( _BEGIN_HIGHLIGHT ) and get(sr,"title").endswith( _END_HIGHLIGHT ) |
|
|
|
|
lambda sr: get(sr,"title").startswith( _BEGIN_HIGHLIGHT ) and get(sr,"title").endswith( _END_HIGHLIGHT ), |
|
|
|
|
check_main_rb = True |
|
|
|
|
) |
|
|
|
|
# prefer search results whose title starts with a match |
|
|
|
|
extract_sr( |
|
|
|
|
lambda sr: get(sr,"title").startswith( _BEGIN_HIGHLIGHT ) |
|
|
|
|
lambda sr: get(sr,"title").startswith( _BEGIN_HIGHLIGHT ), |
|
|
|
|
check_main_rb = True |
|
|
|
|
) |
|
|
|
|
# prefer search results that have a match in the title |
|
|
|
|
extract_sr( |
|
|
|
|
lambda sr: _BEGIN_HIGHLIGHT in get(sr,"title") |
|
|
|
|
lambda sr: _BEGIN_HIGHLIGHT in get(sr,"title"), |
|
|
|
|
check_main_rb = True |
|
|
|
|
) |
|
|
|
|
# prefer search results that have a match in the subtitle |
|
|
|
|
extract_sr( |
|
|
|
|
lambda sr: _BEGIN_HIGHLIGHT in get(sr,"subtitle") |
|
|
|
|
lambda sr: _BEGIN_HIGHLIGHT in get(sr,"subtitle"), |
|
|
|
|
check_main_rb = True |
|
|
|
|
) |
|
|
|
|
# prefer user annotations |
|
|
|
|
extract_sr( |
|
|
|
|