views:

1001

answers:

0

I am using the Python, Django framework and PostgreSQL combination. I am using the full text search of PostgreSQL (8.3) and am overriding the default filter function of Manager class in Django. Using the link: http://barryp.org/blog/entries/postgresql-full-text-search-django/ I was able to configure my full text search, as mentioned in the following code:

q = 'hello world'
queryset = Entry.objects.extra(
    select={
        'snippet': "ts_headline(body, plainto_tsquery(%s))",
        'rank': "ts_rank_cd(body_tsv, plainto_tsquery(%s), 32)",
        },
    where=["body_tsv @@ query"],
    params=[q]
).order_by('-rank')

I need to use a regular expression for the search query such that I query something like q = '~^[A-Z][a-z][0-9]hello world[A-Z][a-z][0-9]$'

It doesn't seem to work when I use the regular expression there. Basically I need the "snippet" column of my table be searched with a match for any string that has a "hello world" substring and achieve both full text search and substring search as well. By default the substring search doesn't happen.