Search Customization

73 views
Skip to first unread message

Vignesh Sarma

unread,
Apr 25, 2012, 4:42:19 AM4/25/12
to django-...@googlegroups.com
Hi,

and my Model is like:
class Note(models.Model):
    user =  models.ForeignKey(User)
    pub_date = models.DateTimeField()
    title = models.CharField(max_length= 200)
    body = models.TextField()

Now I want to change it so that I can search only in one of the fields like, search in title or user etc.
I would be like gmail, advanced search option.

where you can search with specific values in different fields.

I am using solr as the backend.

David Sauve

unread,
Apr 25, 2012, 11:41:58 AM4/25/12
to django-...@googlegroups.com
Hi Vignesh,

To constrain your search to a specific field you'll need to do something like:

`SearchQuerySet().filter(my_field='searchterm')`

This should explain further: http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html#filter but it works very similar to how the Django ORM works.

Good luck,

David
--
You received this message because you are subscribed to the Google Groups "django-haystack" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-haystack/-/U7HoSqryi0MJ.
To post to this group, send email to django-...@googlegroups.com.
To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.

Vignesh Sarma

unread,
Apr 26, 2012, 5:17:58 AM4/26/12
to django-...@googlegroups.com
Hi,

I was able to solve that thanks,



On Wednesday, April 25, 2012 9:11:58 PM UTC+5:30, notanumber wrote:
Hi Vignesh,

To constrain your search to a specific field you'll need to do something like:

`SearchQuerySet().filter(my_field='searchterm')`

This should explain further: http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html#filter but it works very similar to how the Django ORM works.

Good luck,

David

On Wednesday, 25 April, 2012 at 1:42 AM, Vignesh Sarma wrote:

Hi,

and my Model is like:
class Note(models.Model):
    user =  models.ForeignKey(User)
    pub_date = models.DateTimeField()
    title = models.CharField(max_length= 200)
    body = models.TextField()

Now I want to change it so that I can search only in one of the fields like, search in title or user etc.
I would be like gmail, advanced search option.

where you can search with specific values in different fields.

I am using solr as the backend.

--
You received this message because you are subscribed to the Google Groups "django-haystack" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-haystack/-/U7HoSqryi0MJ.
To post to this group, send email to django-haystack@googlegroups.com.
To unsubscribe from this group, send email to django-haystack+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages