split_search() - A Python functional for advanced search applications

15 May 2008   0 comments   Python


Mind That Age!

This blog post is 9 years old! Most likely, its content is outdated. Especially if it's technical.

Powered by Fusion×

Inspired by Google's way of working I today put together a little script in Python for splitting a search. The idea is that you can search by entering certain keywords followed by a colon like this:

Free Text name:Peter age: 28

And this will be converted into two parts:

'Free Text'
{'name': 'Peter', 'age':'28}

You can configure which keywords should be recognized and to make things simple, you can basically set this to be the columns you have to do advanced search on in your application. For example (from_date,to_date)

Feel free to download and use it as much as you like. You might not agree completely with it's purpose and design so you're allowed to change it as you please.

Here's how to use it:

$ wget http://www.peterbe.com/plog/split_search/split_search.py
$ python
>>> from split_search import split_search
>>> free_text, parameters = split_search('Foo key1:bar', ('key1',))
>>> free_text
>>> parameters
{'key1': 'bar'}


Version 1.3 fixes a bug when all you've entered is one of the keywords.


Thank you for posting a comment

Your email will never ever be published

Related posts

Releasing IssueTrackerProduct 0.9 29 April 2008
zope-memory-readings - Tracking Zope2's memory usage by URL 30 May 2008
Related by Text:
Autocompeter is Dead. Long live Autocompeter! 09 January 2017
Python inspect module 16 August 2004
Combining MOBi and EconoAccount 07 February 2005
Add links to a text (take III) 22 March 2005
window.onload from before 07 June 2005