smartfile / django-sphinx-db

Django database backend for SphinxQL.
BSD 3-Clause "New" or "Revised" License
17 stars 13 forks source link

LIMIT statement functionality #2

Open netfl0 opened 12 years ago

netfl0 commented 12 years ago

The default sphinx configuration returns 20 results, it would be nice to be able to configure that from django methods on the fly.

something like:

MyIndex.objects.filter(content__serach, limit=40)

I was thinking something similar for the offset functionality, but I don't know if the RT indexes support that yet.

btimby commented 12 years ago

Peter, this is a good idea. I am not sure of the details at this time either. I know that typically Django uses slicing to define limits.

MyIndex.objects.filter(content__search='keyword')[:20]

Would limit to the first 20 results. This could be added to the Sphinx backend.

MyIndex.objects.filter(content__search='keyword')[20:40]

The above would start at 20, and return 40 records.

netfl0 commented 12 years ago

I learned something new here :)

getitem() and slice objects

I think your recommended implementation is elegant. I have a lot of ideas for features, should I open up a bunch of separate tickets?

btimby commented 12 years ago

Please do.

btimby commented 12 years ago

Apparently Sphinx does not support the OFFSET keyword. This is what is used to perform a query that starts at a particular index, therefore the following is not valid:

MyIndexModel.objects.all()[1:2]

But, this is valid:

MyIndexModel.objects.all()[:2]

It would be nice if Sphinx supported OFFSET in addition to LIMIT, however, we can probably do some hackery to emulate it in the SphinxSQLCompiler. More research is needed.

btimby commented 12 years ago

Opened issue upstream.

http://sphinxsearch.com/bugs/view.php?id=1154

dbrgn commented 12 years ago

In the meantime, could you add simple LIMIT functionality?

Also, I think django-sphinx-db should return max_matches items by default, not 20. If people want, they can still limit it using slicing, but otherwise it will confuse people.