"""Converts qrystr into querystring (uploader format)"""
self.default()
self.field=[]
self.format=[]
self.mode=["e","e","e"]
fields=string.split(qrystr,"||")
forfieldinfields:
tags=string.split(field,"::")
i=0
format=[]
fortagintags:
if(i==0):
self.field.append(tag)
else:
format.append(tag)
i+=1
self.format.append(format)
while(len(self.format)<3):
self.format.append("")
while(len(self.field)<3):
self.field.append("")
i=0
forlettinsearch_mode:
self.mode[i]=lett
i+=1
i=0
forlettinoperator:
self.operator[i]=lett
i+=1
return
defdefault(self):
self.pattern=[]
self.field=[]
self.mode=[]
self.operator=[]
self.format=[]
self.pattern.append("")
self.pattern.append("")
self.pattern.append("")
self.field.append("245__a")
self.field.append("")
self.field.append("")
self.mode.append("a")
self.mode.append("")
self.mode.append("")
self.operator.append("")
self.operator.append("")
self.format.append([])
self.format.append([])
self.format.append([])
self.advanced=1
return
defchange_search_mode(self,mode="a"):
self.mode=[mode,mode,mode]
return
defsearch_engine_encode(self):
field_=[]
forfieldinself.field:
i=0
field__=""
forletterinfield:
if(letter=="%"):
if(i==5):
letter="a"
else:
letter="_"
i+=1
field__+=str(letter)
field_.append(field__)
self.field=field_
return
defget_field_tags(field):
"Gets list of field 'field' for the record with 'sysno' system number from the database."
query="select tag.value from tag left join field_tag on tag.id=field_tag.id_tag left join field on field_tag.id_field=field.id where field.code='%s'"%field;
out=[]
res=run_sql(query)
forrowinres:
out.append(row[0])
returnout
defget_subfield(field,subfield):
"Return subfield of a field."
forsbfinfield:
if(sbf[0][0][0]==subfield):
returnsbf[0][0][1]
return""
defmatched_records(recID_lists):
"Analyze list of matches. Ambiguous record result is always preferred."
recID_tmp=[]
forrecID_listinrecID_lists:
if(len(recID_list)>1):
return2
if(len(recID_list)==1):
if(len(recID_tmp)==0):
recID_tmp.append(recID_list[0])
else:
if(recID_list[0]inrecID_tmp):
pass
else:
return2
if(len(recID_tmp)==1):
return1
return0
defmatched_records_min(recID_lists):
"Analyze lists of matches. New record result is preferred if result is unmatched."
min=2
forrecID_listinrecID_lists:
if(len(recID_list)<min):
min=len(recID_list)
if(min==1):
returnmin
returnmin
defmatched_records_max(recID_lists):
"Analyze lists of matches. Ambiguous result is preferred if result is unmatched."
max=0
forrecID_listinrecID_lists:
if(len(recID_list)==1):
return1
if(len(recID_list)>max):
max=len(recID_list)
if(max>1):
return2
elif(max==1):
return1
else:
return0
return2
defmain():
# Record matches database content when defined search gives exactly one record in the result set.
# By default the match is done on the title field.
# Using advanced search only 3 fields can be queried concurrently