Skip to content

Commit

Permalink
Merge pull request #48 from golnazads/master
Browse files Browse the repository at this point in the history
switch the author OR to an AND by default and issue a warning to the …
  • Loading branch information
golnazads committed May 21, 2018
2 parents 42845c4 + 3d1961f commit e71aad0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
20 changes: 11 additions & 9 deletions tugboat/tests/tests_unit/test_search_redirect.py
Expand Up @@ -83,12 +83,14 @@ def test_authors(self):
'&sort=' + urllib.quote('date desc, bibcode desc'),
author_search) # author with exact match

# changing OR to AND and issuing a warning
req.args = MultiDict([('author', urllib.quote('Huchra, John;Macri, Lucas M.')), ('aut_logic', 'OR')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
author_search = view.translate(req)
self.assertEqual('q=' + urllib.quote('author:') + '(' + urllib.quote('"Huchra, John" OR "Macri, Lucas M."') + ')' +
'&sort=' + urllib.quote('date desc, bibcode desc'),
self.assertEqual('q=' + urllib.quote('author:') + '(' + urllib.quote('"Huchra, John" AND "Macri, Lucas M."') + ')' +
'&sort=' + urllib.quote('date desc, bibcode desc') +
'&warning_message=' + urllib.quote('author search terms combined with AND rather than OR'),
author_search) # authors with or

def test_object(self):
Expand Down Expand Up @@ -308,49 +310,49 @@ def test_classic_parameters_entry_date(self):
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["1990-01-01T00:00:00.000Z" TO "1991-12-31T00:00:00.000Z"]') +
self.assertEqual('q=' + urllib.quote('entdate:["1990-01-01" TO "1991-12-31"]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # both years only

req.args = MultiDict([('start_entry_year', 1990), ('start_entry_mon', 5), ('end_entry_year', 1991), ('end_entry_mon', 9)])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["1990-05-01T00:00:00.000Z" TO "1991-09-30T00:00:00.000Z"]') +
self.assertEqual('q=' + urllib.quote('entdate:["1990-05-01" TO "1991-09-30"]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # years and months

req.args = MultiDict([('start_entry_year', 1990), ('end_entry_year', 1991), ('end_entry_mon', 10)])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["1990-01-01T00:00:00.000Z" TO "1991-10-31T00:00:00.000Z"]') +
self.assertEqual('q=' + urllib.quote('entdate:["1990-01-01" TO "1991-10-31"]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # no start mon

req.args = MultiDict([('start_entry_year', 1990), ('start_entry_mon', 5), ('end_entry_year', 1991)])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["1990-05-01T00:00:00.000Z" TO "1991-12-31T00:00:00.000Z"]') +
self.assertEqual('q=' + urllib.quote('entdate:["1990-05-01" TO "1991-12-31"]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # no end mon

req.args = MultiDict([('start_entry_year', 1990), ('start_entry_mon', 5)])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["1990-05-01T00:00:00.000Z" TO *]') +
self.assertEqual('q=' + urllib.quote('entdate:["1990-05-01" TO *]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # no end
req.args = MultiDict([('end_entry_year', 1991), ('end_entry_mon', 10)])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["0000-00-00T00:00:00.000Z" TO "1991-10-31T00:00:00.000Z"]') +
self.assertEqual('q=' + urllib.quote('entdate:[* TO "1991-10-31"]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # no start

req.args = MultiDict([('start_entry_year', 1990), ('start_entry_mon', 5), ('start_entry_day', 6),
('end_entry_year', 1991), ('end_entry_mon', 9), ('end_entry_day', 10)])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('entry_date:["1990-05-06T00:00:00.000Z" TO "1991-09-10T00:00:00.000Z"]') +
self.assertEqual('q=' + urllib.quote('entdate:["1990-05-06" TO "1991-09-10"]') +
'&sort=' + urllib.quote('date desc, bibcode desc'), search) # years, months, days

def test_classic_results_subset(self):
Expand Down
15 changes: 9 additions & 6 deletions tugboat/views.py
Expand Up @@ -325,8 +325,9 @@ def translate_authors(self, args):
search = ''
logic = self.get_logic('author', args)
exact = self.author_exact(args)
if logic == 'OR':
connector = ' OR '
# 5/21 from Alberto: let's switch the author "OR" to an "AND" by default and issue a warning to the user.
# if logic == 'OR':
# connector = ' OR '
author_field = 'author:'
if exact:
author_field = '=author:'
Expand All @@ -339,10 +340,12 @@ def translate_authors(self, args):
search += urllib.quote(author + connector)
search = search[:-len(urllib.quote(connector))] # remove final
search += ')'
# fields in search are ANDed as of 5/9
# fields in search are ANDed as of 5/9 and issue a warning
if len(self.translation.search) > 0:
self.translation.search.append('AND')
self.translation.search.append(search)
if len(authors) > 1 and logic == 'OR':
self.translation.warning_message.append(urllib.quote('author search terms combined with AND rather than OR'))

def translate_simple(self, args, classic_param, bbb_param):
"""process easy to translate fields like title
Expand Down Expand Up @@ -470,13 +473,13 @@ def translate_entry_date(self, args):
# we can use * for solr query if either start_year or end_year are not set
# did not change the code above that actually set the values if either is missing
if start_year == 0:
search = 'entry_date' + urllib.quote(':["0000-00-00T00:00:00.000Z" TO "{:04d}-{:02}-{:02d}T00:00:00.000Z"]'.format(
search = 'entdate' + urllib.quote(':[* TO "{:04d}-{:02}-{:02d}"]'.format(
end_year, end_month, end_day))
elif end_year == 2222:
search = 'entry_date' + urllib.quote(':["{:04d}-{:02d}-{:02d}T00:00:00.000Z" TO *]'.format(
search = 'entdate' + urllib.quote(':["{:04d}-{:02d}-{:02d}" TO *]'.format(
start_year, start_month, start_day))
else:
search = 'entry_date' + urllib.quote(':["{:04d}-{:02d}-{:02d}T00:00:00.000Z" TO "{:04d}-{:02}-{:02d}T00:00:00.000Z"]'.format(
search = 'entdate' + urllib.quote(':["{:04d}-{:02d}-{:02d}" TO "{:04d}-{:02}-{:02d}"]'.format(
start_year, start_month, start_day, end_year, end_month, end_day))
# fields in search are ANDed as of 5/9
if len(self.translation.search) > 0:
Expand Down

0 comments on commit e71aad0

Please sign in to comment.