Well, then, that is quite a strange use case :-)  Nevermind my simple
methods.  Malcom's suggestion of an extension for postgres seems like
a good idea--writing functions in various languages (like Python!) is
_really_ easy in postgres.

Just out of curiosity (for either of you,) what is a search like that
used for?  I've had a lot of strange requests from a lot of (generally
strange) clients, but that's a pretty weird one.

On Mar 5, 12:14 am, koranthala <koranth...@gmail.com> wrote:
> Thank you very much Jeff and Malcolm for the extremely helpful
> replies.
> Jeff, the substring match is not based on spaces. Rather, the string
> can start anywhere and end anywhere.
> So, I cannot think of a way to do it, as Malcolm said.
> I had also done the same thing as Malcolm, i.e. pulled every tuple to
> memory (luckily I dont expect more than 200 odd tuples for this
> particular scenario) and am comparing individually - except for the
> fact that I was stopping at the first substring match. -  I guess I
> should be doing the "longest common substring" as Malcolm mentioned.
> Again, thank you Jeff and Malcolm.
>
> On Mar 5, 6:18 am, Malcolm Tredinnick <malc...@pointy-stick.com>
> wrote:
>
> > On Wed, 2009-03-04 at 05:01 -0800,koranthalawrote:
> > > Hi,
> > >      How do I implement a substring query?
> > >      Please find the example below.
> > > From Django Documentation:
> > >   Entry.objects.get(headline__icontains='Lennon')
> > >   => This matches the headline 'Today lennon honoured'
>
> > > My query is the opposite:
> > >    I have the string 'Lennon' inside my DB, and I have to match 'Today
> > > Lennon honoured'
> > > Say:
> > > Entry.objects.get(headline__isubstring='Today Lennon Honoured')
> > > should return headline 'Lennon'.
>
> > >     I checked iregex too, but I cannot seem to solve it myself. If
> > > somebody has solved this, could you please help me out.
>
> > This isn't the type of searching operating that is going to be standard
> > outside of specialised packages. It's actually a really hard problem
> > (not impossible, there are solutions, but hard) in general. The
> > complexity comes from the fact that the match could start anywhere and
> > involve any number of characters. So to do this efficiently requires
> > some special datastructures (with suffix trees and some other
> > structures, you can the search in about O(total length of text)).
>
> > Now, I'm sure it wouldn't be impossible to write, say, an extension for,
> > say, PostgreSQL (picking that database because of its excellent support
> > for extensions) that supported this kind of searching, but it would be a
> > fair bit of work. It would require a particular sort of index structure
> > to support the searches. I don't know any package off the top of my head
> > that does this for databases. Might be a fun project for somebody with a
> > bit of time and curiosity.
>
> > I've done this kind of thing in the past for a couple of clients and
> > I've always pulled the text to be searched into memory. Create a data
> > structure of all the headlines to be searched (using your example) and
> > then match the search string against them to find the longest common
> > substring match. There's a lot of literature on this sort of stuff, and
> > searching for things like "longest common substring" will give you a
> > place to start.
>
> > Regards,
> > Malcolm
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to