Skip to content

Commit

Permalink
Make search_sorting3.py more consistent with other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwb committed Nov 15, 2016
1 parent fe73a23 commit d5df28a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 50 deletions.
11 changes: 6 additions & 5 deletions code/python/search_sorting3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import sys
import xapian
from support import distance_between_coords, log_matches
import support

def search(dbpath, querystring, offset=0, pagesize=10):
# offset - defines starting point within result set
Expand Down Expand Up @@ -35,7 +35,7 @@ def __call__(self, doc):
coords = map(float, doc.get_value(4).split(','))
washington = (38.012, -77.037)
return xapian.sortable_serialise(
distance_between_coords(coords, washington)
support.distance_between_coords(coords, washington)
)
enquire.set_sort_by_key_then_relevance(DistanceKeyMaker(), False)
# End of example code.
Expand All @@ -48,14 +48,15 @@ def __call__(self, doc):
'rank': match.rank + 1,
'docid': match.docid,
'name': fields.get('name', u''),
'date': fields.get('admitted', u''),
'pop': fields.get('population', u''),
'date': support.format_date(fields.get('admitted', u'')),
'pop': support.format_numeral(int(fields.get('population', 0))),
'lat': fields.get('latitude', u''),
'lon': fields.get('longitude', u''),
})
matches.append(match.docid)

# Finally, make sure we log the query and displayed results
log_matches(querystring, offset, pagesize, matches)
support.log_matches(querystring, offset, pagesize, matches)

if len(sys.argv) < 3:
print("Usage: %s DBPATH QUERYTERM..." % sys.argv[0])
Expand Down
40 changes: 20 additions & 20 deletions code/python/search_sorting3.py.out
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
1: #050 State of Maryland 17880428
Population 5773552
2: #049 State of Delaware 17871207
Population 897934
3: #040 Commonwealth of Pennsylvania 17871212
Population 12702379
4: #043 State of New Jersey 17871218
Population 8791894
5: #039 State of West Virginia 18630620
Population 1859815
6: #037 State of North Carolina 17891121
Population 9535483
7: #041 State of New York 17880726
Population 19378102
8: #038 Commonwealth of Virginia 17880625
Population 8001024
9: #048 State of Connecticut 17880109
Population 3574097
10: #036 State of South Carolina 17880523
Population 4625384
1: #050 State of Maryland April 28, 1788
Population 5,773,552
2: #049 State of Delaware December 7, 1787
Population 897,934
3: #040 Commonwealth of Pennsylvania December 12, 1787
Population 12,702,379
4: #043 State of New Jersey December 18, 1787
Population 8,791,894
5: #039 State of West Virginia June 20, 1863
Population 1,859,815
6: #037 State of North Carolina November 21, 1789
Population 9,535,483
7: #041 State of New York July 26, 1788
Population 19,378,102
8: #038 Commonwealth of Virginia June 25, 1788
Population 8,001,024
9: #048 State of Connecticut January 9, 1788
Population 3,574,097
10: #036 State of South Carolina May 23, 1788
Population 4,625,384
INFO:xapian.search:'State'[0:10] = 50 49 40 43 39 37 41 38 48 36
11 changes: 6 additions & 5 deletions code/python3/search_sorting3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import sys
import xapian
from support import distance_between_coords, log_matches
import support

def search(dbpath, querystring, offset=0, pagesize=10):
# offset - defines starting point within result set
Expand Down Expand Up @@ -36,7 +36,7 @@ def __call__(self, doc):
x, y = map(float, value.split(','))
washington = (38.012, -77.037)
return xapian.sortable_serialise(
distance_between_coords((x, y), washington)
support.distance_between_coords((x, y), washington)
)
enquire.set_sort_by_key_then_relevance(DistanceKeyMaker(), False)
# End of example code.
Expand All @@ -49,14 +49,15 @@ def __call__(self, doc):
'rank': match.rank + 1,
'docid': match.docid,
'name': fields.get('name', u''),
'date': fields.get('admitted', u''),
'pop': fields.get('population', u''),
'date': support.format_date(fields.get('admitted', u'')),
'pop': support.format_numeral(int(fields.get('population', 0))),
'lat': fields.get('latitude', u''),
'lon': fields.get('longitude', u''),
})
matches.append(match.docid)

# Finally, make sure we log the query and displayed results
log_matches(querystring, offset, pagesize, matches)
support.log_matches(querystring, offset, pagesize, matches)

if len(sys.argv) < 3:
print("Usage: %s DBPATH QUERYTERM..." % sys.argv[0])
Expand Down
40 changes: 20 additions & 20 deletions code/python3/search_sorting3.py.out
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
1: #050 State of Maryland 17880428
Population 5773552
2: #049 State of Delaware 17871207
Population 897934
3: #040 Commonwealth of Pennsylvania 17871212
Population 12702379
4: #043 State of New Jersey 17871218
Population 8791894
5: #039 State of West Virginia 18630620
Population 1859815
6: #037 State of North Carolina 17891121
Population 9535483
7: #041 State of New York 17880726
Population 19378102
8: #038 Commonwealth of Virginia 17880625
Population 8001024
9: #048 State of Connecticut 17880109
Population 3574097
10: #036 State of South Carolina 17880523
Population 4625384
1: #050 State of Maryland April 28, 1788
Population 5,773,552
2: #049 State of Delaware December 7, 1787
Population 897,934
3: #040 Commonwealth of Pennsylvania December 12, 1787
Population 12,702,379
4: #043 State of New Jersey December 18, 1787
Population 8,791,894
5: #039 State of West Virginia June 20, 1863
Population 1,859,815
6: #037 State of North Carolina November 21, 1789
Population 9,535,483
7: #041 State of New York July 26, 1788
Population 19,378,102
8: #038 Commonwealth of Virginia June 25, 1788
Population 8,001,024
9: #048 State of Connecticut January 9, 1788
Population 3,574,097
10: #036 State of South Carolina May 23, 1788
Population 4,625,384
INFO:xapian.search:'State'[0:10] = 50 49 40 43 39 37 41 38 48 36

0 comments on commit d5df28a

Please sign in to comment.