write_message("......Processing records #%s-%s"%(recids,recide))
recs=run_sql("SELECT id_bibrec, value FROM bib%sx, bibrec_bib%sx WHERE tag=%%s AND id_bibxxx=id and id_bibrec >=%%s and id_bibrec<=%%s"%(tag[0:2],tag[0:2]),(tag,recids,recide))
valid=intbitset(trailing_bits=1)
valid.discard(0)
forkeyintags:
newset=intbitset()
newset+=[recid[0]forrecidin(run_sql("SELECT id_bibrec FROM bib%sx, bibrec_bib%sx WHERE id_bibxxx=id AND tag=%%s AND id_bibxxx=id and id_bibrec >=%%s and id_bibrec<=%%s"%(tag[0:2],tag[0:2]),(key,recids,recide)))]
valid.intersection_update(newset)
iftags:
recs=filter(lambdax:x[0]invalid,recs)
records=records+list(recs)
write_message("Number of records found with the necessary tags: %s"%len(records))
write_message("No records specified, updating all",verbose=2)
min_id=run_sql("SELECT min(id) from bibrec")[0][0]
max_id=run_sql("SELECT max(id) from bibrec")[0][0]
options["recid_range"]=[[min_id,max_id]]
iftask_get_option("quick")=="no":
write_message("Recalculate parameter not used, parameter ignored.",verbose=9)
iftask_get_option("cmd")=="del":
del_recids(cfg_short,options["recid_range"])
eliftask_get_option("cmd")=="add":
func_object=globals().get(cfg_function)
func_object(rank_method_code,cfg_name,config)
eliftask_get_option("cmd")=="stat":
rank_method_code_statistics(rank_method_code)
eliftask_get_option("cmd")=="check":
check_method(rank_method_code)
eliftask_get_option("cmd")=="print-missing":
func_object=globals().get(cfg_function)
func_object(rank_method_code,cfg_name,config)
eliftask_get_option("cmd")=="repair":
func_object=globals().get(cfg_repair_function)
func_object()
else:
write_message("Invalid command found processing %s"%rank_method_code,sys.stderr)
raiseStandardError
iftask_get_option("verbose"):
showtime((time.time()-startCreate))
return1
defget_valid_range(rank_method_code):
"""Return a range of records"""
write_message("Getting records from collections enabled for rank method.",verbose=9)
res=run_sql("SELECT collection.name FROM collection, collection_rnkMETHOD, rnkMETHOD WHERE collection.id=id_collection and id_rnkMETHOD=rnkMETHOD.id and rnkMETHOD.name=%s",(rank_method_code,))
l_of_colls=[]
forcollinres:
l_of_colls.append(coll[0])
iflen(l_of_colls)>0:
recIDs=perform_request_search(c=l_of_colls)
else:
recIDs=[]
valid=intbitset()
valid+=recIDs
returnvalid
defadd_recIDs_by_date(rank_method_code,dates=""):
"""Return recID range from records modified between DATES[0] and DATES[1].
If DATES is not set, then add records modified since the last run of
the ranking method RANK_METHOD_CODE.
"""
ifnotdates:
try:
dates=(get_lastupdated(rank_method_code),'')
exceptException:
dates=("0000-00-00 00:00:00",'')
ifdates[0]isNone:
dates=("0000-00-00 00:00:00",'')
query="""SELECT b.id FROM bibrec AS b WHERE b.modification_date >= %s"""
ifdates[1]:
query+=" and b.modification_date <= %s"
query+=" ORDER BY b.id ASC"""
ifdates[1]:
res=run_sql(query,(dates[0],dates[1]))
else:
res=run_sql(query,(dates[0],))
alist=create_range_list([row[0]forrowinres])
ifnotalist:
write_message("No new records added since last time method was run")