[英]For spatial search with haystack/solr, do I have to import both django.contrib.gis.geos.Point and haystack.utils.geo.Point?
I have used haystack 2.1.0 and solr for searching restaurants by name and it works. 我已经使用haystack 2.1.0和solr来按名称搜索餐厅,并且可以使用。 Now try to add spatial search.
现在尝试添加空间搜索。
Have followed the instruction on https://django-haystack.readthedocs.org/en/latest/spatial.html . 遵循了https://django-haystack.readthedocs.org/en/latest/spatial.html上的说明。 The following statement on that page, "Haystack prefers to work with Point objects, which are located in django.contrib.gis.geos.Point but conviently importable out of haystack.utils.geo.Point."
该页面上的以下语句:“ Haystack倾向于使用Point对象,这些对象位于django.contrib.gis.geos.Point中,但可以方便地从haystack.utils.geo.Point中导入。” gives me the impression that it is OK to just import haystack.utils.geo.Point.
给我的印象是只导入haystack.utils.geo.Point即可。 However that doesn't work for me.
但是,这对我不起作用。
Below are the codes I thought are relevant to this question: 以下是我认为与此问题相关的代码:
Model.py Model.py
from haystack.utils.geo import Point
class Restaurant(models.Model):
name = models.CharField(max_length=250)
latitude = models.FloatField()
longitude = models.FloatField()
def get_location(self):
return Point(self.longitude, self.latitude)
search_indexes.py search_indexes.py
class RestaurantIndex(indexes.SearchIndex, indexes.Indexable):
name = indexes.CharField(model_attr='name', faceted=True)
location = indexes.LocationField(model_attr='get_location')
schema.xml schema.xml中
<fieldType name='location' class='solr.LatLonType' subFieldSuffix='_coordinate' />
<field name="name" type="text" indexed="true" stored="true" multiValued="false" />
<field name="name_exact" type="string" indexed="true" stored="true" multiValued="false" />
<field name="location" type="location" indexed="true" stored="true" multiValued="false" />
However, when I ran 'python manage.py rebuild_index', I got the following errors: 但是,当我运行“ python manage.py rebuild_index”时,出现以下错误:
...
File "...\models.py", line 17, in <module> from haystack.utils.geo import Point
File "...\lib\site-packages\haystack\utils\geo.py", line 2, in <module>
from django.contrib.gis.geos import Point
File "...\lib\site-packages\django\contrib\gis\geos\__init__.py", line 6, in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
File ...\lib\site-packages\django\contrib\gis\geos\geometry.py", line 16, in <module>
from django.contrib.gis.geos.coordseq import GEOSCoordSeq
File "...\lib\site-packages\django\contrib\gis\geos\coordseq.py", line 9, in <module>
from django.contrib.gis.geos.libgeos import CS_PTR
File "...\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 52, in <module>
'", "'.join(lib_names))
ImportError: Could not find the GEOS library (tried "geos_c", "libgeos_c-1"). Try setting
GEOS_LIBRARY_PATH in your settings.
This part of the error ' File "...\\lib\\site-packages\\haystack\\utils\\geo.py", line 2, in from django.contrib.gis.geos import Point ' gives me the impression that haystack is calling django.contrib.gis.geos. 错误的这一部分“ django.contrib.gis.geos import Point中的文件“ ... \\ lib \\ site-packages \\ haystack \\ utils \\ geo.py”,第2行,给我的印象是haystack正在调用django.contrib.gis.geos。
Thus my question of whether I need to import both django.contrib.gis.geos.Point and haystack.utils.geo.Point. 因此,我的问题是我是否需要同时导入django.contrib.gis.geos.Point和haystack.utils.geo.Point。
I actually installed OSGeo4W64 after seeing this error. 看到此错误后,我实际上安装了OSGeo4W64。 However, when I ran 'python manage.py rebuild_index', I got the same error.
但是,当我运行“ python manage.py rebuild_index”时,出现了相同的错误。 Then I added "GEOS_LIBRARY_PATH = 'C:/OSGeo4W64/bin'" to setting.py and got the error of "WindowsError: [Error 126] The specified module could not be found".
然后,我在setting.py中添加了“ GEOS_LIBRARY_PATH ='C:/ OSGeo4W64 / bin'”,并得到了“ WindowsError:[Error 126]找不到指定的模块”的错误。
First, thanks so much for reading my long question. 首先,非常感谢您阅读我的冗长问题。 Any help is really appreciated.
任何帮助都非常感谢。 If I cannot figure this out, my next step is to develop without haystack, which I am not really looking forward to, because I am new to solr.
如果我不能弄清楚,我的下一步就是没有干草堆,这不是我真正期待的,因为我是新手。
Again, thanks in advance. 再次感谢您。
You need to supply the full path to the geos DLL, not the containing directory. 您需要提供geos DLL的完整路径,而不是包含目录。 Try: GEOS_LIBRARY_PATH = 'C:/OSGeo4W64/bin/geos_c.dll'
尝试:GEOS_LIBRARY_PATH ='C:/OSGeo4W64/bin/geos_c.dll'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.