"""Checks if a method is valid for the collection given"""
enabled_colls=dict(run_sql("SELECT id_collection, score from collection_rnkMETHOD,rnkMETHOD WHERE id_rnkMETHOD=rnkMETHOD.id AND name='%s'"%rank_method_code))
colID=int(colID)
ifenabled_colls.has_key(colID):
return1
else:
whilecolID:
colID=run_sql("SELECT id_dad FROM collection_collection WHERE id_son=%s"%colID)
ifcolIDandenabled_colls.has_key(colID[0][0]):
return1
elifcolID:
colID=colID[0][0]
return0
defget_bibrank_methods(collection,ln=cdslang):
"""Returns a list of rank methods and the name om them in the language defined by the ln parameter, if collection is given, only methods enabled for that collection is returned."""
result=(None,"",adderrorbox("An error occured when trying to rank the search result",["Unexpected error: %s<br><b>Traceback:</b>%s"%(e,traceback.format_tb(sys.exc_info()[2]))]),voutput)
ifresult[0]andresult[1]:#split into two lists for search_engine
tf_values[term]=int((1+math.log(tf[0]))*tf[1])#calculate term weigth
tf_values=tf_values.items()
tf_values.sort(lambdax,y:cmp(y[1],x[1]))#sort based on weigth
lwords=[]
stime=time.time()
(recdict,rec_termcount)=({},{})
for(t,tf)intf_values:#t=term, tf=term frequency
term_recs=deserialize_via_marshal(terms_recs[t])
iflen(tf_values)<=methods[rank_method_code]["max_nr_words_lower"]or(len(term_recs)>=methods[rank_method_code]["min_nr_words_docs"]and(((float(len(term_recs))/float(methods[rank_method_code]["col_size"]))<=methods[rank_method_code]["max_word_occurence"])and((float(len(term_recs))/float(methods[rank_method_code]["col_size"]))>=methods[rank_method_code]["min_word_occurence"]))):#too complicated...something must be done
lwords.append((t,methods[rank_method_code]["rnkWORD_table"]))#list of terms used
(recdict,rec_termcount)=calculate_record_relevance_findsimilar((t,round(tf,4)),term_recs,hitset,recdict,rec_termcount,verbose,"true")#true tells the function to not calculate all unimportant terms