我所知道的一樣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