Return the list of restricted collection names to which recid belongs.
"""
restricted_collections=run_sql("""SELECT c.name, c.reclist FROM accROLE_accACTION_accARGUMENT raa JOIN accARGUMENT ar ON raa.id_accARGUMENT = ar.id JOIN collection c ON ar.value=c.name WHERE ar.keyword = 'collection' AND raa.id_accACTION = %s""",(VIEWRESTRCOLL_ID,))
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))
# combine the current hitset with resulting hitset using the current operator
ifcurrent_operator=='+':
result_hitset=result_hitset¤t_hitset
elifcurrent_operator=='-':
result_hitset=result_hitset-current_hitset
elifcurrent_operator=='|':
result_hitset=result_hitset|current_hitset
else:
assertFalse,"Unknown operator in search_pattern_parenthesised()"
returnresult_hitset
# If searching with parenteses fails, perform search ignoring parentheses
exceptSyntaxError:
print_warning(req,_("Search syntax misunderstood. Ignoring all parentheses in the query. If this doesn't help, please check your search and try again."))
# remove the parentheses in the query. Current implementation removes all the parentheses,
# but it could be improved to romove only these that are not inside quotes
"""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"))