2014-11-09 13 views
5

Sau khi nâng cấp django lên 1.7 Tôi không thể thực thi lệnh update_index quản lý.Django-haystack với công cụ xapian: không thể thực thi update_index nếu mô hình có ManyToManyField

Traceback (most recent call last): 
    File "/opt/pycharm-3.4.1/helpers/pydev/pydevd.py", line 1733, in <module> 
    debugger.run(setup['file'], None, None) 
    File "/opt/pycharm-3.4.1/helpers/pydev/pydevd.py", line 1226, in run 
    pydev_imports.execfile(file, globals, locals) # execute the script 
    File "/home/tochium/projects/povary/manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/tochium/projects/povary/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line 
    utility.execute() 
    File "/home/tochium/projects/povary/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/home/tochium/projects/povary/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/home/tochium/projects/povary/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute 
    output = self.handle(*args, **options) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/management/commands/update_index.py", line 184, in handle 
    return super(Command, self).handle(*items, **options) 
    File "/home/tochium/projects/povary/local/lib/python2.7/site-packages/django/core/management/base.py", line 503, in handle 
    label_output = self.handle_label(label, **options) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/management/commands/update_index.py", line 189, in handle_label 
    self.update_backend(label, using) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/management/commands/update_index.py", line 234, in update_backend 
    do_update(backend, index, qs, start, end, total, self.verbosity) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/management/commands/update_index.py", line 89, in do_update 
    backend.update(index, current_qs) 
    File "/home/tochium/projects/povary/src/xapian-haystack/xapian_backend.py", line 355, in update 
    data = index.full_prepare(obj) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/indexes.py", line 207, in full_prepare 
    self.prepared_data = self.prepare(obj) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/indexes.py", line 198, in prepare 
    self.prepared_data[field.index_fieldname] = field.prepare(obj) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/fields.py", line 159, in prepare 
    return self.convert(super(CharField, self).prepare(obj)) 
    File "/home/tochium/projects/povary/src/django-haystack/haystack/fields.py", line 106, in prepare 
    return current_object() 
    File "/home/tochium/projects/povary/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 839, in __call__ 
    manager = getattr(self.model, kwargs.pop('manager')) 
KeyError: u'manager' 

tôi sử dụng python2.7.6, django 1,7, django-đống cỏ khô 2.3.1, công cụ tìm kiếm: Xapian

Tôi nghĩ rằng vấn đề xuất hiện vì django từ phương pháp 1,7 add gọi() để ManyRelatedManager và bây giờ trong tập tin /haystack/fields.py tình trạng này cháy.

if callable(current_object): 
    return current_object() 

Nhưng trong gọi MANAGER_NAME cần được xác định, làm thế nào chúng ta có thể nhìn thấy trong phương pháp thích hợp

def __call__(self, **kwargs): 
     # We use **kwargs rather than a kwarg argument to enforce the 
     # `manager='manager_name'` syntax. 
     manager = getattr(self.model, kwargs.pop('manager')) 

Cảm ơn.

+0

bạn đã giải quyết vấn đề này. Tôi đã gặp phải vấn đề tương tự. –

+0

@kobymeir, sự cố xuất hiện vì trường manyToMany, chúng tôi chỉ xóa nó khỏi chỉ mục tìm kiếm :) Tôi nghĩ rằng đó không phải là giải pháp tốt. – Znack

+0

Mọi cập nhật của kẻ này. Tôi cũng bị mắc kẹt ở đây. – Tanuj

Trả lời

1

Sử dụng phương thức tùy chỉnh để trả về một mảng chuỗi hoặc số nguyên (sử dụng mẫu chuỗi nếu bạn muốn lưu trữ thông tin phức tạp hơn trong một trường chỉ mục đa giá trị).

class MyModelIndex(indexes.SearchIndex, indexes.Indexable): 
    my_m2m_field = indexes.CharField() 

    def prepare_my_m2m_field(self, my_model): 
     return [m2m.prop for m2m in my_model.m2m_field.all()] 

khai Dòng cho Solr bao gồm các lĩnh vực cho faceting và autocomplete:

<field name="my_m2m_field" type="text_general" indexed="true" stored="true" multiValued="true"/> 
<field name="my_m2m_field_exact" type="string" indexed="true" stored="false" multiValued="true"/> 
<field name="my_m2m_field_ac" type="ngram" indexed="true" stored="true" multiValued="true" 
     termVectors="true" termPositions="true" termOffsets="true"/> 
<copyField source="my_m2m_field" dest="emotion_exact" /> 
<copyField source="my_m2m_field" dest="emotion_ac" /> 
+0

Điều này đã giải quyết nó cho tôi. Hãy chắc chắn rằng 'my_m2m_field' của bạn chỉ là một' indexes.CharField() 'trống và không phải' indexes.CharField (model_attr = 'my_field') '. Cảm ơn @Risadinha! – Will

Các vấn đề liên quan