And if we add a little more information to the schema, we will have a fast search interface:
class Clients(CSVFile):
columns = ['client_id', 'name', 'email',
'registration_date']
schema = {
'client_id': Integer,
'name': Unicode(index='text'),
'email': String,
'registration_date': Date(index='keyword')}
In this example we will search the CSV file by the columns name and registration date, so we add the parameter index with the right analyser (text for Unicode values, keyword for anything else) to the these columns.
Now we can use the search interface:
>>> clients = Clients('clients.csv')
>>>
>>> results = clients.search(name='Macuk')
>>> print results
[0]
The search interface is rather powerful, but since it is the same offered by the itools.catalog package, we prefer not to repeat ourselves. Check the Section 14.6 for the details.
What we will explain here is that the value returned by the method search is a list with all the rows that matched the query. So maybe we want to get the row to do something with it:
>>> for row_number in clients.search(name='Macuk'):
... row = clients.get_row(row_number)