2

I am facing a strange issue with django-haystack + Solr: each field receives a list instead of the actual raw value.

After indexing, here is an extract of my Solr index (pasted from Solr admin):

{
    "id":"forum.category.4",
    "django_ct":["forum.category"],
    "django_id":[4],
    "text":["Divers"],
    "name":["Divers"],
    "url":["/forum/#divers"],
    "url_str":["/forum/#divers"],
    "name_str":["Divers"],
    "django_ct_str":["forum.category"],
    "text_str":["Divers"]},

As you can see, each relevant data is indexed in a 1-element list, which makes further querying impossible.

Here is my index definition:

class CategoryIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, model_attr='name')
    name = indexes.CharField(model_attr='name')
    url = indexes.CharField(indexed=False)

    def get_model(self):
        return Category

    def prepare_url(self, obj):
        return obj.get_absolute_url()

Any suggestion? Thanks by advance.

user650108
  • 1,009
  • 1
  • 9
  • 18
  • Investigating, it seems to be related to another problem: ```app_label, model_name = raw_result[DJANGO_CT].split('.') AttributeError: 'list' object has no attribute 'split'```, see https://github.com/django-haystack/django-haystack/issues/1200 – user650108 Apr 21 '18 at 10:14

1 Answers1

2

If you haven't set an explicit schema for your collection in Solr, and you are using the data driven config set (also known as the schemaless mode), all fields are multivalued by default. Use a proper schema and set the fields to multiValued="false" to get the behavior you're looking for.

For django-haystack you can use the build_solr_schema command to manage.py.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84