我在用django-haystack索引一堆地址。我的搜索索引是:
class AddressIndex(indexes.SearchIndex, indexes.Indexable):
street = indexes.CharField(model_attr='street')
city = indexes.CharField(model_attr='city')
location = indexes.LocationField(null=True)
def prepare_location(self, obj):
try:
return obj.location.point
except AttributeError:
return None
def get_model(self):
return Address搜索索引当然有更多的字段,但这就足够了。当我试图通过运行./manage.py update_index -k4 -b100 -v2 location (索引存储在location应用程序中)来对其进行索引时,只要prepare_location不返回任何内容,一切都会变得很棒。当它返回某物时(如。0.000,0.000)我从Solr那里得到了一个错误,提到了一些关于不兼容维度的内容。
准确的错误是org.apache.solr.common.SolrException: com.spatial4j.core.exception.InvalidShapeException: incompatible dimension (2) and values (POINT (0.0000000000000000 0.0000000000000000)). Only 0 values specified。我想“也许它不喜欢这一点”,并在point.x和point.y中添加了0.0000000000000001,但是错误保持不变(除了现在它提到了新的坐标)。
有人知道这是怎么回事吗?
我在用:
在Ubuntu 13.10上安装了所有最新更新。
发布于 2014-01-29 16:02:08
显然,django-haystack本身并没有做什么特别重要的事情。它不会将GeoDjango点转换为所需的"lat,lon“格式,而只是通过Point对象传递到XML。
因此,与其这样做:
def prepare_location(self, obj):
try:
return obj.location.point
except AttributeError:
return None其中一个需要这样做:
def prepare_location(self, obj):
try:
return "{lat},{lon}".format(lat=obj.location.point.y, obj.location.point.x)
except AttributeError:
return None如果我只是阅读文件,那就容易多了.
https://stackoverflow.com/questions/21307036
复制相似问题