Django - Haystack Query Serialization
Asked Answered
C

2

8

I'm trying to serialize a HayStack SearchQuerySet:

from django.core import serializers
serializers.serialize("json", SearchQuerySet().filter(content=request.GET['q']))

but it throws:

'SearchQuery' object has no attribute '_build_query'

How can I fix this?

Calefaction answered 8/12, 2010 at 13:7 Comment(0)
S
7

I had faced a similar problem. used something like this and it worked:

serializers.serialize("json", [x.object for x in queryset]

Steere answered 18/12, 2010 at 12:35 Comment(0)
S
9

I don't recommend call 'object' per result as it would hit to database and beat purpose of search performance. Instead consider calling get_stored_fields method which can be used with json dumps:

import simplejson as json
data = map(lambda x: x.get_stored_fields(), search_result)
json.dumps(data)
Spill answered 12/11, 2013 at 1:47 Comment(0)
S
7

I had faced a similar problem. used something like this and it worked:

serializers.serialize("json", [x.object for x in queryset]

Steere answered 18/12, 2010 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.