我所知道的一样Django Solr和solango全文搜索应用等特定的Django模型
高级搜索我正在寻找内置更像是一家房地产网站的高级搜索。 例如他们可以选择位置,价格等与www.viewr.com高级搜索相似。
我迄今所做的就是这一点,该机型自定义管理器下:
def advanced_search(self, district, location, type, facilities, features, not_permitted):
q_objects = []
l_objects = []
t_objects = []
fc_objects = []
ft_objects = []
np_objects = []
if district:
if location:
for loc in location:
l_objects.append(Q(location__exact=loc))
else:
l_objects.append(Q(location__district=district))
if type:
for ty in type:
t_objects.append(Q(listing_type__exact=ty))
if facilities:
for fc in facilities:
fc_objects.append(Q(property_facilities__exact=fc))
if features:
for ft in features:
ft_objects.append(Q(property_features__exact=ft))
ft_objects.append(Q(community_features__exact=ft))
if not_permitted:
for np in not_permitted:
np_objects.append(Q(not_permitted__exact=np))
# Start with a bare QuerySet
qs = self.get_query_set()
if location:
qs = qs.filter(reduce(operator.or_, l_objects))
if type:
qs = qs.filter(reduce(operator.or_, t_objects))
if facilities:
qs = qs.filter(reduce(operator.or_, fc_objects))
if features:
qs = qs.filter(reduce(operator.or_, ft_objects))
if not_permitted:
qs = qs.filter(reduce(operator.or_, np_objects))
# Use operator's or_ to string together all of your Q objects.
return qs
现在,我没有得到非常明确的结果。有什么我可能做错了吗?有没有更好的方法来做各种OR搜索/连接?
嗯,我错过了你想要的OR事实,而不是AND。 在这种情况下,我认为最好的解决方案是使用诸如Djapian之类的东西,并根据需要为各个字段设置权重。 但正如我所见www.viewr.com高级搜索使用AND方法来筛选它们,而不是OR。 – 2009-06-10 02:57:51
嗨,看到我下面的评论,你的接近于示例片段 – Rasiel 2009-06-10 03:24:01