Skip to main content
 首页 » 编程设计

python之django-haystack 空间搜索要求

2025年05月04日13jirigala

我正在尝试使用 django-haystack 进行地理空间查询,如下所述:http://django-haystack.readthedocs.org/en/latest/spatial.html我正在使用 elasticsearch 作为后端。我根据文档创建了 search_indexes,配置了 django,当我第一次尝试使用 rebuild_index 管理命令时,我看到了一个错误:

python manage.py rebuild_index --settings=myproject.settings.local 
 
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. 
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command. 
Are you sure you wish to continue? [y/N] y 
Removing all documents from your index because you said so. 
All documents removed. 
Indexing 1 Venues 
Traceback (most recent call last): 
  File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
  ... 
  ... 
  File "/f/venvs/myproject/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 161, in update 
    prepped_data = index.full_prepare(obj) 
  File "/f/venvs/myproject/local/lib/python2.7/site-packages/haystack/indexes.py", line 204, in full_prepare 
    self.prepared_data = self.prepare(obj) 
  File "/f/venvs/myproject/local/lib/python2.7/site-packages/haystack/indexes.py", line 195, in prepare 
    self.prepared_data[field.index_fieldname] = field.prepare(obj) 
  File "/f/venvs/myproject/local/lib/python2.7/site-packages/haystack/fields.py", line 167, in prepare 
    from haystack.utils.geo import ensure_point 
  File "/f/venvs/myproject/local/lib/python2.7/site-packages/haystack/utils/geo.py", line 2, in <module> 
    from django.contrib.gis.geos import Point 
ImportError: cannot import name Point 

haystack 用于从 django.contrib.gis.geos 进行空间搜索的点无法导入,我不确定为什么。一个完整的工作 django.contrib.gis (geodjango) 是 haystack 中空间搜索的要求吗?换句话说:我必须为 geodjango 安装所有 c 库,配置 postgis,然后才能在 haystack 中使用 Point 类吗?

软件版本:

  • Django 1.6
  • django-haystack 2.1.0
  • pyelasticsearch 0.6.1
  • Elasticsearch 0.90.7

请您参考如下方法:

我通过安装 libgeos 和 libgeos-dev 解决了这个问题

sudo apt-get install libgeos-dev