Prefer user annotations, errata and rules in search results.

master
Pacman Ghost 3 years ago
parent 5433630a5c
commit 802f2f05c0
  1. 24
      asl_rulebook2/webapp/search.py
  2. 8
      asl_rulebook2/webapp/tests/test_annotations.py
  3. 6
      asl_rulebook2/webapp/tests/test_linkify_ruleids.py
  4. 2
      asl_rulebook2/webapp/tests/test_sr_filters.py

@ -381,15 +381,16 @@ def _adjust_sort_order( results ):
"""Adjust the sort order of the search results.""" """Adjust the sort order of the search results."""
results2 = [] results2 = []
def extract_sr( func ): def extract_sr( func, force=False ):
# move results that pass the filter function to the new list # move results that pass the filter function to the new list
i = 0 i = 0
while True: while True:
if i >= len(results): if i >= len(results):
break break
# NOTE: We never prefer small entries (i.e .have no ruleref's) # NOTE: We don't want to prefer useless entries e.g. those that only contain a "see also".
# e.g. those that only contain a "see also". nruleids = len( results[i].get( "ruleids", [] ) )
if func( results[i] ) and len(results[i].get("rulerefs",[])) > 0: nrulerefs = len( results[i].get( "rulerefs", [] ) )
if func( results[i] ) and ( force or nruleids > 0 or nrulerefs > 0 ):
results2.append( results[i] ) results2.append( results[i] )
del results[i] del results[i]
else: else:
@ -415,6 +416,21 @@ def _adjust_sort_order( results ):
extract_sr( extract_sr(
lambda sr: _BEGIN_HIGHLIGHT in get(sr,"subtitle") lambda sr: _BEGIN_HIGHLIGHT in get(sr,"subtitle")
) )
# prefer user annotations
extract_sr(
lambda sr: get(sr,"sr_type") == "user-anno",
force = True
)
# prefer errata
extract_sr(
lambda sr: get(sr,"sr_type") == "errata",
force = True
)
# prefer rules
extract_sr(
lambda sr: get(sr,"sr_type") == "index",
force = True
)
# include any remaining search results # include any remaining search results
results2.extend( results ) results2.extend( results )

@ -15,20 +15,20 @@ def test_full_errata( webapp, webdriver ):
check_sr_filters( [ "index", "errata" ] ) check_sr_filters( [ "index", "errata" ] )
# bring up the errata and check it in the search results # bring up the errata and check it in the search results
results = do_search( "test" ) results = do_search( "erratum" )
expected = { expected = {
"sr_type": "anno", "sr_type": "anno",
"caption": "E1", "caption": "E1",
"icon": "errata.png", "icon": "errata.png",
"content": "This is a ((test)) erratum.", "content": "This is a test ((erratum)).",
"source": "Test Fixture" "source": "Test Fixture"
} }
assert len(results) == 2 assert len(results) == 1
result = results[0] result = results[0]
assert result == expected assert result == expected
# bring up the errata in the rule info popup and check it there # bring up the errata in the rule info popup and check it there
find_child( "#search-results .ruleid a" ).click() find_child( "#search-results .auto-ruleid" ).click()
anno = _unload_rule_info_anno() anno = _unload_rule_info_anno()
expected = { expected = {
"caption": "E1", "caption": "E1",

@ -85,9 +85,9 @@ def test_errata( webdriver, webapp ):
init_webapp( webapp, webdriver ) init_webapp( webapp, webdriver )
# test ruleid's in an errata's search result # test ruleid's in an errata's search result
results = _do_search( "errata", True ) results = _do_search( "errata", False )
assert len(results) == 2 assert len(results) == 2
sr_elem = find_children( "#search-results .sr" )[ 1 ] sr_elem = find_children( "#search-results .sr" )[ 0 ]
_check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook!","A3.8") ) _check_ruleid( find_child(".caption",sr_elem), ("asl-rulebook!","A3.8") )
_dismiss_rule_info_popup() _dismiss_rule_info_popup()
_check_ruleid( find_child(".content",sr_elem), ("asl-rulebook!","A.2") ) _check_ruleid( find_child(".content",sr_elem), ("asl-rulebook!","A.2") )
@ -98,7 +98,7 @@ def test_errata( webdriver, webapp ):
( ".content", ("asl-rulebook!","A.2") ) ( ".content", ("asl-rulebook!","A.2") )
] ]
for sel, target in expected: for sel, target in expected:
_do_search( "errata", False ) _do_search( "errata attached", False )
sr_elem = find_child( "#rule-info .rule-info" ) sr_elem = find_child( "#rule-info .rule-info" )
_check_ruleid( find_child(sel,sr_elem), target ) _check_ruleid( find_child(sel,sr_elem), target )
_dismiss_rule_info_popup() _dismiss_rule_info_popup()

@ -73,8 +73,8 @@ def test_sr_filtering( webdriver, webapp ):
# test filtering errata search results # test filtering errata search results
do_test( "errata", "errata", [ do_test( "errata", "errata", [
{ "sr_type": "index", "title": "CCPh" },
{ "sr_type": "anno", "caption": "A3.8" }, { "sr_type": "anno", "caption": "A3.8" },
{ "sr_type": "index", "title": "CCPh" },
] ) ] )
# test filtering ASOP search results # test filtering ASOP search results

Loading…
Cancel
Save