Skip to content

Commit

Permalink
Enable searching for wildcard url's on activity pages (#5299)
Browse files Browse the repository at this point in the history
* Add UriCombinedWildcardFilter to activity pages

Replace the UriFilter with the UriCombinedWildcardFilter on activity
pages so that the url facet now accepts and searches for wildcard urls.

Add a test.

* Add wildcard desc to url facet on activity pages

* Switch on wildcard activity page feature flag

* fixup: change wording of url facet
  • Loading branch information
Hannah Stepanek committed Sep 22, 2018
1 parent 91997c5 commit c96a9d2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
8 changes: 6 additions & 2 deletions h/activity/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
AuthorityFilter,
TagsAggregation,
UsersAggregation,
UriFilter)
UriFilter,
UriCombinedWildcardFilter)


class ActivityResults(namedtuple('ActivityResults', [
Expand Down Expand Up @@ -168,7 +169,10 @@ def _execute_search(request, query, page_size):
search = Search(request, stats=request.stats)
search.append_modifier(AuthorityFilter(authority=request.default_authority))
search.append_modifier(TopLevelAnnotationsFilter())
search.append_modifier(UriFilter(request=request))
if request.feature("wildcard_search_on_activity_pages"):
search.append_modifier(UriCombinedWildcardFilter(request=request))
else:
search.append_modifier(UriFilter(request=request))
for agg in aggregations_for(query):
search.append_aggregation(agg)

Expand Down
1 change: 1 addition & 0 deletions h/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'overlay_highlighter': "Use the new overlay highlighter?",
'api_render_user_info': "Return users' extended info in API responses?",
'client_display_names': "Render display names instead of user names in the client",
'wildcard_search_on_activity_pages': "Enable wildcard search via url facet on activity pages.",
}

# Once a feature has been fully deployed, we remove the flag from the codebase.
Expand Down
3 changes: 2 additions & 1 deletion h/static/scripts/controllers/search-bar-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class SearchBarController extends Controller {
{
matchOn: 'url',
title: 'url:',
explanation: 'see all annotations on a page',
explanation: `see all annotations on a document URL. * matches any number
of characters and ? matches any single character`,
},
{
matchOn: 'group',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ describe('AutosuggestDropdownController', () => {
},
{
title: 'url:',
explanation: 'see all annotations on a page',
explanation: `see all annotations on a document URL. * matches any number
of characters and ? matches any single character`,
},
{
title: 'group:',
Expand Down
28 changes: 28 additions & 0 deletions tests/h/activity/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def unparse(self):
'bucketing',
'presenters',
'AuthorityFilter',
'UriCombinedWildcardFilter',
'Search',
'TagsAggregation',
'TopLevelAnnotationsFilter',
Expand Down Expand Up @@ -251,6 +252,25 @@ def test_it_only_shows_annotations_from_default_authority(self,
AuthorityFilter.assert_called_once_with(pyramid_request.default_authority)
search.append_modifier.assert_any_call(AuthorityFilter.return_value)

@pytest.mark.parametrize('enable_flag', (True, False))
def test_it_recognizes_wildcards_in_uri_url(self,
pyramid_request,
search,
UriFilter,
UriCombinedWildcardFilter,
enable_flag):

pyramid_request.feature.flags['wildcard_search_on_activity_pages'] = enable_flag

execute(pyramid_request, MultiDict(), self.PAGE_SIZE)

if enable_flag:
UriCombinedWildcardFilter.assert_called_once_with(pyramid_request)
search.append_modifier.assert_any_call(UriCombinedWildcardFilter.return_value)
else:
UriFilter.assert_called_once_with(pyramid_request)
search.append_modifier.assert_any_call(UriFilter.return_value)

def test_it_adds_a_tags_aggregation_to_the_search_query(self,
pyramid_request,
search,
Expand Down Expand Up @@ -620,6 +640,14 @@ def TagsAggregation(self, patch):
def AuthorityFilter(self, patch):
return patch('h.activity.query.AuthorityFilter')

@pytest.fixture
def UriFilter(self, patch):
return patch('h.activity.query.UriFilter')

@pytest.fixture
def UriCombinedWildcardFilter(self, patch):
return patch('h.activity.query.UriCombinedWildcardFilter')

@pytest.fixture
def TopLevelAnnotationsFilter(self, patch):
return patch('h.activity.query.TopLevelAnnotationsFilter')
Expand Down

0 comments on commit c96a9d2

Please sign in to comment.