Crosstips.org

My fun Crossword solver project. Crosstips.org & Krysstips.se

Kung Fu

Fujian White Crane Kung Fu

Fry-IT

Fry-IT is the company I work for

Photos

Photoalbum, both old and new.

Zope

What I have and am doing with Zope

Receptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact me

My contact details and how to contact me.

 

KungFuPeople.com
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com


Mobile version of this page Mobile version of this page


 

split_search() - A Python functional for advanced search applications

http://www.peterbe.com/plog/split_search/split_search.py

15th of May 2008

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
 'Foo'
 >>> parameters
 {'key1': 'bar'}

UPDATE

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



Comment

 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.