Skip to content

Instantly share code, notes, and snippets.

@timo
Created May 20, 2009 20:04
Show Gist options
  • Save timo/115056 to your computer and use it in GitHub Desktop.
Save timo/115056 to your computer and use it in GitHub Desktop.
def query(self, query=None, type=None, valsi=[], gloss=None,
rafsi=[], selmaho=None, definition=None, notes=None,
regexp=False, like=None):
results = []
if query:
args = {"gloss": gloss, "valsi": valsi, "rafsi": rafsi,
"selmaho": selmaho, "definition": definition, "notes": notes,
"regexp": regexp, "type": type}
listargs = ["valsi", "rafsi"]
normalargs = ["gloss", "selmaho", "definition", "notes"]
for arg in args.keys():
copyarg = dict(args)
if arg in listargs:
copyarg[arg] = [query]
results.extend(self.find(**copyarg))
elif arg in normalargs:
copyarg[arg] = query
results.extend(self.find(**copyarg))
results = list(set(results))
if like:
results.sort(_Damerau(like, results).cmp)
return results
else:
return self.find(type=type, rafsi=rafsi, selmaho=selmaho,
definition=definition, notes=notes, like=like,
gloss=gloss, valsi=valsi, regexp=regexp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment