colls_out_for_display=colls# nope, we need to display all 'colls' successively
# remove duplicates:
#colls_out_for_display_nondups=filter(lambda x, colls_out_for_display=colls_out_for_display: colls_out_for_display[x-1] not in colls_out_for_display[x:], range(1, len(colls_out_for_display)+1))
"""Sort records in 'recIDs' list according sort field 'sort_field' in order 'sort_order'.
If more than one instance of 'sort_field' is found for a given record, try to choose that that is given by
'sort pattern', for example "sort by report number that starts by CERN-PS".
Note that 'sort_field' can be field code like 'author' or MARC tag like '100__a' directly."""
_=gettext_set_language(ln)
## check arguments:
ifnotsort_field:
returnrecIDs
iflen(recIDs)>CFG_WEBSEARCH_NB_RECORDS_TO_SORT:
ifof.startswith('h'):
print_warning(req,_("Sorry, sorting is allowed on sets of up to %d records only. Using default sort order.")%CFG_WEBSEARCH_NB_RECORDS_TO_SORT,"Warning")
returnrecIDs
sort_fields=string.split(sort_field,",")
recIDs_dict={}
recIDs_out=[]
## first deduce sorting MARC tag out of the 'sort_field' argument:
tags=[]
forsort_fieldinsort_fields:
ifsort_fieldandstr(sort_field[0:2]).isdigit():
# sort_field starts by two digits, so this is probably a MARC tag already
tags.append(sort_field)
else:
# let us check the 'field' table
query="""SELECT DISTINCT(t.value) FROM tag AS t, field_tag AS ft, field AS f
WHERE f.code=%s AND ft.id_field=f.id AND t.id=ft.id_tag
ORDER BY ft.score DESC"""
res=run_sql(query,(sort_field,))
ifres:
forrowinres:
tags.append(row[0])
else:
ifof.startswith('h'):
print_warning(req,_("Sorry, %s does not seem to be a valid sort option. Choosing title sort instead.")%cgi.escape(sort_field),"Error")
tags.append("245__a")
ifverbose>=3:
print_warning(req,"Sorting by tags %s."%cgi.escape(repr(tags)))
ifsort_pattern:
print_warning(req,"Sorting preferentially by %s."%cgi.escape(sort_pattern))
## check if we have sorting tag defined:
iftags:
# fetch the necessary field values:
forrecIDinrecIDs:
val=""# will hold value for recID according to which sort
vals=[]# will hold all values found in sorting tag for recID
fortagintags:
vals.extend(get_fieldvalues(recID,tag))
ifsort_pattern:
# try to pick that tag value that corresponds to sort pattern
req.write("<tr><td><strong>%s</strong></td><td><strong>%s</strong></td><td><strong>%s</strong></td><td><strong>%s</strong></td><td><strong>%s</strong></td><td><strong>%s</strong></td></tr>"%("No.","Time","Pattern","Field","Collection","Number of Hits"))