Re: search across models

2013-02-03 Thread Ashwin Kumar
thank you dennis,

what you suggested is a difficult process where we need to look into
performance its the query gets more complex and database gets bigger which
is obvious.

but its a good idea. i will try that for a while.

With Best
-Ashwin.
+91-9959166266


On Sun, Feb 3, 2013 at 11:54 PM, Dennis Lee Bieber wrote:

> On Sun, 3 Feb 2013 13:11:55 +0530, Ashwin Kumar 
> declaimed the following in gmane.comp.python.django.user:
>
> > thank you joey,
> >
> > but i want to build search for queries like
> >
> >
> >1. restaurants in city1
> >2. city1 restaurants
> >3. Chinese restaurants
> >4. Chinese restaurants in city1
> >5. vegetarian restaurants in city1
> >6. vegetarian american restaurants
> >
> > the above are exact search queries we get from template.
> > i wrote
> > restas = restaurant.objects.filter(Q(name__contains =
> > request.REQUEST.get('title')) & ~Q(city__name='') )
> > this works fine to search with restaurant name.
> >
> >  i really have no idea on how to get results if the search phrase is
> > complex.
> >
> I've not been following, and don't know the schema, but for such
> searches I suspect you'll have to bypass Django's ORM and go to direct
> SQL...
>
> You'd split the search on words, skip the noise terms ("in", "and",
> "the", etc.), and then create a select statement in which you've created
> a test for each remaining word:
>
> select ... from ...
> where field contains  and field contains  and ...
>
> If you have two (or more) fields that need to be matched, it gets
> more complex (unless you build a separate index containing terms from
> all relevant fields).
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: search across models

2013-02-02 Thread Ashwin Kumar
thank you joey,

but i want to build search for queries like


   1. restaurants in city1
   2. city1 restaurants
   3. Chinese restaurants
   4. Chinese restaurants in city1
   5. vegetarian restaurants in city1
   6. vegetarian american restaurants

the above are exact search queries we get from template.
i wrote
restas = restaurant.objects.filter(Q(name__contains =
request.REQUEST.get('title')) & ~Q(city__name='') )
this works fine to search with restaurant name.

 i really have no idea on how to get results if the search phrase is
complex.

With Best
-Ashwin.
+91-9959166266


On Sun, Feb 3, 2013 at 12:46 AM, Joey Espinosa wrote:

> I'll assume city1 is a City object:
>
> 1) restaurants.objects.filter(city=city1)
>
> 2) city1.restaurant_set.all()
>
> 3) For this one, you have your choices variable in a difficult setup. I'd
> rewrite your restaurant class like this:
>
> class Restaurant(models.Model):  # keep class names singular, with minor
> exceptions
> CHINESE = 'c'
> AMERICAN = 'a'
> JAPANESE = 'j'
>
> RESTAURANT_TYPES = (
> (CHINESE, 'Chinese'),
> (AMERICAN, 'American'),
> (JAPANESE, 'Japanese'),
> (
>
> name = models.CharField(max_length=456)
> city = models.ForeignKey(city) # on a side note, the "city" class
> should be defined as "class City(models.Model)"
> rtype = models.CharField(max_length=10, choices=RESTAURANT_TYPES) #
> another side note... don't use Python reserved keywords such as
>
>   #
> "type" for your own variables
> is_veg = models.BooleanField(default=True)
>
> Now you'll be able to do this:
>
> Restaurant.objects.filter(rtype=Restaurant.CHINESE)
>
> 4) Using the above rewritten class as a guide:
>
> city1.restaurant_set.filter(rtype=Restaurant.CHINESE)
>
> or
>
> Restaurant.objects.filter(city=city1, rtype=Restaurant.CHINESE)
>
> 5) city1.restaurant_set.filter(is_veg=True)
>
> 6) city1.restaurant_set.filter(is_veg=True, rtype=Restaurant.AMERICAN)
>
> 7) ... and so on.
>
> Hope this helped. Also, I'd recommend getting familiar with this:
> http://www.python.org/dev/peps/pep-0008/
>
> --
> Joey "JoeLinux" Espinosa*
> *
>  
> 
>
>
> On Sat, Feb 2, 2013 at 1:13 PM, Aswani Kumar  wrote:
>
>> hi all, i have a big question.
>> how can i perform search queries like on following models
>>
>> RESTAURANT_TYPES = (
>> ('C', 'Chinese'),
>> ('A', 'American'),
>> ('J', 'Japanese'),
>> )
>>
>> class city (models.Model):
>> name = models.CharField(max_length=200)
>>
>> class restaurants(models.Model):
>> name = models.CharField(max_length=456)
>> city = models.ForeignKey(city)
>> type = models.CharField(max_length=10, choices=RESTAURANT_TYPES)
>> is_veg = models.BooleanField(default=True)
>>
>> search queries:
>>
>>1. restaurants in city1
>>2. city1 restaurants
>>3. Chinese restaurants
>>4. Chinese restaurants in city1
>>5. vegetarian restaurants in city1
>>6. vegetarian american restaurants
>>7. and so on...
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




search across models

2013-02-02 Thread Aswani Kumar
hi all, i have a big question. 
how can i perform search queries like on following models

RESTAURANT_TYPES = (
('C', 'Chinese'),
('A', 'American'),
('J', 'Japanese'),
)

class city (models.Model):
name = models.CharField(max_length=200)

class restaurants(models.Model):
name = models.CharField(max_length=456)
city = models.ForeignKey(city)
type = models.CharField(max_length=10, choices=RESTAURANT_TYPES)
is_veg = models.BooleanField(default=True)

search queries:

   1. restaurants in city1
   2. city1 restaurants
   3. Chinese restaurants
   4. Chinese restaurants in city1
   5. vegetarian restaurants in city1
   6. vegetarian american restaurants
   7. and so on...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.