How to add individual objects to django haystack?
Asked Answered
E

1

6

I have a search index that I have created using Solr. I want to add individual django objects to the search index.

To remove objects from the solr database we use remove_object.

some = SomFooModel.objects.get(pk=1)
foo = FooIndex()
foo.remove_object(some) #This works

To add it, is there something like add_object or a work around here ?

What I want is.

foo.add_object(some). # there is no such thing 

This also does not work. It does not add the object to index.

foo.update_object(some)

I have tried reading the django-haystack documentation but there seems to be nothing that might help.

Execrative answered 5/6, 2015 at 20:46 Comment(0)
E
2

I did not read the documentation well enough as a result I messed up on the QuerySet part.

foo.update_object(some)

The above does add the object to the index. Its just that I was not searching for it properly. I was searching for the object after removing it in the following way.

SearchQuerySet().filter(foo=some.foo)

This gave a empty query set always.

SearchQuerySet().models(SomFooModel).filter(foo = some.foo)

This gives the correct result.

Reference

Execrative answered 8/6, 2015 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.