Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 May 19, 2010 17:02:27

yafeng w.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


Hi,

I got the same problem when building my website. Have you solved it?
Please let me know.

Thanks,

On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
> Hi,
>
> I'm trying to create full text search on model, everything goes fine
> when
> searching TextFields but I have a problem with ForeignKey field.
>
> How can i do that? Can anyone point me to the right direction?
>
> Thanks
>
> Model example:
>
> class Model1(models.Model):
>
>      text_field =models.TextField(max_length=250)
>      fek_field = models.ForeignKey('Model2')
>
> class Model2(models.Model):
>      text_field = models.TextField(max_length=250)
>
> --
> View this message in
> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
> Sent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 May 20, 2010 14:01:58

David D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


On 13/04/10 09:04, urukay wrote:Hi,

I'm trying to create full text search on model, everything goes fine
when
searching TextFields but I have a problem with ForeignKey field.

How can i do that? Can anyone point me to the right direction?Do you mean you want the results for Model2 searches to include Model2instances when when a search string matches text in any of the Model1instances related to the Model2 instance?If you're don't actually need sphinx in particular but rather you arelooking for the ability to full-text search django models, thenhttp://haystacksearch.org/makes adding search facilities to djangoprojects extremely easy. With haystack and the handily-pure-pythonwhoosh, you can be up and running basic searches of your django modelsin a matter of minutes. In the case of the foreign key field, withhaystack, you could just include texts from related Model1s in thesearch template for Model2. That's of course a tad wasteful in someways, but OTOH might be exactly what you want.I don't use django-sphinx so I'm not clear how to do it there, buta conceptually related approach does work with raw sphinx apparently:you can use joins in sql_query in your source declarations. see this:http://stackoverflow.com/questions/1733816/sphinx-and-one-to-many-associationsFull text search isn't appropriate for everything, so django-filters isalso handy to remember for filter query-building type stuff.http://github.com/alex/django-filter--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 May 21, 2010 14:48:35

u.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


I need to search over Model1, but the query should "look" also in Model2 if
there is a match aand if there is, it returns Model1 which has relation with
Model2 which contains searched string.

But i'll take look at Haystack, maybe it'll be better for my needs.

Thanks a lot.



David De La Harpe Golden-3 wrote:
>
> On 13/04/10 09:04, urukay wrote:
>> Hi,
>>
>> I'm trying to create full text search on model, everything goes fine
>> when
>> searching TextFields but I have a problem with ForeignKey field.
>>
>> How can i do that? Can anyone point me to the right direction?
>>
>
> Do you mean you want the results for Model2 searches to include Model2
> instances when when a search string matches text in any of the Model1
> instances related to the Model2 instance?
>
> If you're don't actually need sphinx in particular but rather you are
> looking for the ability to full-text search django models, then
>http://haystacksearch.org/makes adding search facilities to django
> projects extremely easy. With haystack and the handily-pure-python
> whoosh, you can be up and running basic searches of your django models
> in a matter of minutes. In the case of the foreign key field, with
> haystack, you could just include texts from related Model1s in the
> search template for Model2. That's of course a tad wasteful in some
> ways, but OTOH might be exactly what you want.
>
> I don't use django-sphinx so I'm not clear how to do it there, but
> a conceptually related approach does work with raw sphinx apparently:
> you can use joins in sql_query in your source declarations. see this:
>http://stackoverflow.com/questions/1733816/sphinx-and-one-to-many-associations>
>
>
> Full text search isn't appropriate for everything, so django-filters is
> also handy to remember for filter query-building type stuff.
>
>http://github.com/alex/django-filter>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>

--
View this message in context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28633984.htmlSent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 May 21, 2010 14:48:36

u.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


Well, still trying to solve it...maybe i found the right way to do it, but
it's still in progress. If anything shows up, i'll keep you updated.
Hopefully this during few days i'll solve it.

Radovan


yafeng wu wrote:
>
> Hi,
>
> I got the same problem when building my website. Have you solved it?
> Please let me know.
>
> Thanks,
>
> On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to create full text search on model, everything goes fine
>> when
>> searching TextFields but I have a problem with ForeignKey field.
>>
>> How can i do that? Can anyone point me to the right direction?
>>
>> Thanks
>>
>> Model example:
>>
>> class Model1(models.Model):
>>
>>      text_field =models.TextField(max_length=250)
>>      fek_field = models.ForeignKey('Model2')
>>
>> class Model2(models.Model):
>>      text_field = models.TextField(max_length=250)
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>

--
View this message in context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28633986.htmlSent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 May 22, 2010 15:22:39

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


You probably want to use the indexer argument. It allows you to
specify which indexes you want sphinx to search over. Of course you
have to tell sphinx which indexes ( models ) you want it to search in.http://www.sphinxsearch.com/docs/current.html#ref-indexerOn May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
> Well, still trying to solve it...maybe i found the right way to do it, but
> it's still in progress. If anything shows up, i'll keep you updated.
> Hopefully this during few days i'll solve it.
>
> Radovan
>
>
>
>
>
> yafeng wu wrote:
>
> > Hi,
>
> > I got the same problem when building my website. Have you solved it?
> > Please let me know.
>
> > Thanks,
>
> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
> >> Hi,
>
> >> I'm trying to create full text search on model, everything goes fine
> >> when
> >> searching TextFields but I have a problem with ForeignKey field.
>
> >> How can i do that? Can anyone point me to the right direction?
>
> >> Thanks
>
> >> Model example:
>
> >> class Model1(models.Model):
>
> >>      text_field =models.TextField(max_length=250)
> >>      fek_field = models.ForeignKey('Model2')
>
> >> class Model2(models.Model):
> >>      text_field = models.TextField(max_length=250)
>
> >> --
> >> View this message in
> >> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
> >> Sent from the django-users mailing list archive at Nabble.com.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@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.
>
> --
> View this message in
> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group
> athttp://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 May 22, 2010 17:49:16

u.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


No that's not what i want..i want search model over another model.



esatterwh...@wi.rr.com wrote:
>
> You probably want to use the indexer argument. It allows you to
> specify which indexes you want sphinx to search over. Of course you
> have to tell sphinx which indexes ( models ) you want it to search in.
>
>http://www.sphinxsearch.com/docs/current.html#ref-indexer>
> On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
>> Well, still trying to solve it...maybe i found the right way to do it,
>> but
>> it's still in progress. If anything shows up, i'll keep you updated.
>> Hopefully this during few days i'll solve it.
>>
>> Radovan
>>
>>
>>
>>
>>
>> yafeng wu wrote:
>>
>> > Hi,
>>
>> > I got the same problem when building my website. Have you solved it?
>> > Please let me know.
>>
>> > Thanks,
>>
>> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>> >> Hi,
>>
>> >> I'm trying to create full text search on model, everything goes fine
>> >> when
>> >> searching TextFields but I have a problem with ForeignKey field.
>>
>> >> How can i do that? Can anyone point me to the right direction?
>>
>> >> Thanks
>>
>> >> Model example:
>>
>> >> class Model1(models.Model):
>>
>> >>      text_field =models.TextField(max_length=250)
>> >>      fek_field = models.ForeignKey('Model2')
>>
>> >> class Model2(models.Model):
>> >>      text_field = models.TextField(max_length=250)
>>
>> >> --
>> >> View this message in
>> >>
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>> >> Sent from the django-users mailing list archive at Nabble.com.
>>
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Django users" group.
>> > To post to this group, send email to django-us...@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.
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
>> Sent from the django-users mailing list archive at Nabble.com.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group
>> athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>

--
View this message in context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28644474.htmlSent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 May 22, 2010 23:40:35

Allen M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


search_string = req.REQUEST.get("search", "")

query = Model1.objects

if search_string == "":
query = query.all()
else:
query = query.filter(
Q(text_field__icontains=search_string) |
Q(fek_field__text_field__icontains=search_string))

the query variable will return the search results.

On 5/22/10, urukay <radovan.be...@gmail.com> wrote:
>
> No that's not what i want..i want search model over another model.
>
>
>
> esatterwh...@wi.rr.com wrote:
>>
>> You probably want to use the indexer argument. It allows you to
>> specify which indexes you want sphinx to search over. Of course you
>> have to tell sphinx which indexes ( models ) you want it to search in.
>>
>>http://www.sphinxsearch.com/docs/current.html#ref-indexer>>
>> On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
>>> Well, still trying to solve it...maybe i found the right way to do it,
>>> but
>>> it's still in progress. If anything shows up, i'll keep you updated.
>>> Hopefully this during few days i'll solve it.
>>>
>>> Radovan
>>>
>>>
>>>
>>>
>>>
>>> yafeng wu wrote:
>>>
>>> > Hi,
>>>
>>> > I got the same problem when building my website. Have you solved it?
>>> > Please let me know.
>>>
>>> > Thanks,
>>>
>>> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>>> >> Hi,
>>>
>>> >> I'm trying to create full text search on model, everything goes fine
>>> >> when
>>> >> searching TextFields but I have a problem with ForeignKey field.
>>>
>>> >> How can i do that? Can anyone point me to the right direction?
>>>
>>> >> Thanks
>>>
>>> >> Model example:
>>>
>>> >> class Model1(models.Model):
>>>
>>> >>      text_field =models.TextField(max_length=250)
>>> >>      fek_field = models.ForeignKey('Model2')
>>>
>>> >> class Model2(models.Model):
>>> >>      text_field = models.TextField(max_length=250)
>>>
>>> >> --
>>> >> View this message in
>>> >>
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>>> >> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Django users" group.
>>> > To post to this group, send email to django-us...@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.
>>>
>>> --
>>> View this message in
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
>>> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group
>>> athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>>
>>
>
> --
> View this message in context:
>http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28644474.html> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 May 22, 2010 23:41:51

Allen M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


search_string = req.REQUEST.get("search", "")

query = Model1.objects

if search_string == "":
query = query.all()
else:
query = query.filter(
Q(text_field__icontains=search_string) |
Q(fek_field__text_field__icontains=search_string))

the query variable will return the search results, searching the
text_field from model1 and then model2

On 5/22/10, urukay <radovan.be...@gmail.com> wrote:
>
> No that's not what i want..i want search model over another model.
>
>
>
> esatterwh...@wi.rr.com wrote:
>>
>> You probably want to use the indexer argument. It allows you to
>> specify which indexes you want sphinx to search over. Of course you
>> have to tell sphinx which indexes ( models ) you want it to search in.
>>
>>http://www.sphinxsearch.com/docs/current.html#ref-indexer>>
>> On May 21, 8:47 am, urukay <radovan.be...@gmail.com> wrote:
>>> Well, still trying to solve it...maybe i found the right way to do it,
>>> but
>>> it's still in progress. If anything shows up, i'll keep you updated.
>>> Hopefully this during few days i'll solve it.
>>>
>>> Radovan
>>>
>>>
>>>
>>>
>>>
>>> yafeng wu wrote:
>>>
>>> > Hi,
>>>
>>> > I got the same problem when building my website. Have you solved it?
>>> > Please let me know.
>>>
>>> > Thanks,
>>>
>>> > On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>>> >> Hi,
>>>
>>> >> I'm trying to create full text search on model, everything goes fine
>>> >> when
>>> >> searching TextFields but I have a problem with ForeignKey field.
>>>
>>> >> How can i do that? Can anyone point me to the right direction?
>>>
>>> >> Thanks
>>>
>>> >> Model example:
>>>
>>> >> class Model1(models.Model):
>>>
>>> >>      text_field =models.TextField(max_length=250)
>>> >>      fek_field = models.ForeignKey('Model2')
>>>
>>> >> class Model2(models.Model):
>>> >>      text_field = models.TextField(max_length=250)
>>>
>>> >> --
>>> >> View this message in
>>> >>
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>>> >> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "Django users" group.
>>> > To post to this group, send email to django-us...@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.
>>>
>>> --
>>> View this message in
>>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p286...
>>> Sent from the django-users mailing list archive at Nabble.com.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group
>>> athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>>
>>
>
> --
> View this message in context:
>http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28644474.html> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#9 June 18, 2010 22:12:37

u.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


So, here is the solution that can help u. I will explain it using
these models:

class Model1(models.Model):
text_field = ....
model_2 = models.ForeignKey('Model2')

class Model2(models.Model):
model_3 = models.ForeignKey('Model3')

class Model3(models.Model):
....
....

Goal is to get only those objects of Model1 which have model_3
field ,in Model2, equal to number let's say 201 :-)

1. main point to do foreign key search is to edit sphinx.config int he
way Sphinx can find "it's way through our tables", to create the
appropriate relations
- after creating sphinx.config file for Model1, you can see that
SQL_QUERY statement is:
SELECT id, text_field, model_2_id from myApp.model1
- we will edit this statement according the "columns logic"

2. let's edit sql_query in this way:
SELECT myApp.model1.id as id, text_field, model_2_id,
myApp.model2.model_3_id as model_3_id from myApp.model1, myApp.model2
where myApp.model2.id = model_2_id
- i've created relation between Model1 and Model2, so that Model2's
field model_2 is accessible through Model1

3. After creatin indexes you do searching Model2 through Model1:
Model1.search.all().filter(model_3_id=201)

I have tested this approach in my project and it works like a charm, i
can confirm that :-)
This way you can search multiple models in FK relation and to do
fulltext searching (not only id searching), just modify sql_query
accordingly.

Also great article can be found here:http://www.marcofucci.com/tumblelog/31/aug/2009/django-sphinx-search-different-models-m2m-fields/I've discussed this foreign key search with author of that article,
Marco Fucci, and he helped me really a lot to understand the way
Sphinx works.

Hope it helps.

Sorry for the delay, but i needed to finish adding google maps to my
project.

Radovan


On 19. Máj, 17:59 h., yafeng wu <wuyaf...@gmail.com> wrote:
> Hi,
>
> I got the same problem when building my website. Have you solved it?
> Please let me know.
>
> Thanks,
>
> On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I'm trying to create full text search on model, everything goes fine
> > when
> > searching TextFields but I have a problem with ForeignKey field.
>
> > How can i do that? Can anyone point me to the right direction?
>
> > Thanks
>
> > Model example:
>
> > class Model1(models.Model):
>
> >      text_field =models.TextField(max_length=250)
> >      fek_field = models.ForeignKey('Model2')
>
> > class Model2(models.Model):
> >      text_field = models.TextField(max_length=250)
>
> > --
> > View this message in
> > context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
> > Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group
> athttp://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#10 June 19, 2010 04:14:14

u.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Django Sphinx Foreign key search


So, here is the solution that can help u. I will explain it using
these models:

class Model1(models.Model):
text_field = ....
model_2 = models.ForeignKey('Model2')

class Model2(models.Model):
model_3 = models.ForeignKey('Model3')

class Model3(models.Model):
....
....

Goal is to get only those objects of Model1 which have model_3
field ,in Model2, equal to number let's say 201 :-)

1. main point to do foreign key search is to edit sphinx.config int he
way Sphinx can find "it's way through our tables", to create the
appropriate relations
- after creating sphinx.config file for Model1, you can see that
SQL_QUERY statement is:
SELECT id, text_field, model_2_id from myApp.model1
- we will edit this statement according the "columns logic"

2. let's edit sql_query in this way:
SELECT myApp.model1.id as id, text_field, model_2_id,
myApp.model2.model_3_id as model_3_id from myApp.model1, myApp.model2
where myApp.model2.id = model_2_id
- i've created relation between Model1 and Model2, so that Model2's
field model_2 is accessible through Model1

3. After creatin indexes you do searching Model2 through Model1:
Model1.search.all().filter(model_3_id=201)

I have tested this approach in my project and it works like a charm, i
can confirm that :-)
This way you can search multiple models in FK relation and to do
fulltext searching (not only id searching), just modify sql_query
accordingly.

Also great article can be found here:http://www.marcofucci.com/tumblelog/31/aug/2009/django-sphinx-search-...
I've discussed this foreign key search with author of that article,
Marco Fucci, and he helped me really a lot to understand the way
Sphinx works.

Hope it helps.

Sorry for the delay, but i needed to finish adding google maps to my
project.

Radovan

yafeng wu wrote:
>
> Hi,
>
> I got the same problem when building my website. Have you solved it?
> Please let me know.
>
> Thanks,
>
> On Apr 13, 4:04 am, urukay <radovan.be...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to create full text search on model, everything goes fine
>> when
>> searching TextFields but I have a problem with ForeignKey field.
>>
>> How can i do that? Can anyone point me to the right direction?
>>
>> Thanks
>>
>> Model example:
>>
>> class Model1(models.Model):
>>
>>      text_field =models.TextField(max_length=250)
>>      fek_field = models.ForeignKey('Model2')
>>
>> class Model2(models.Model):
>>      text_field = models.TextField(max_length=250)
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28219147p282...
>> Sent from the django-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>
>

--
View this message in context:http://old.nabble.com/Django-Sphinx-Foreign-key-search-tp28228784p28931105.htmlSent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support