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 at http://groups.google.com/group/django-users?hl=en.