django全文搜索学习心得(一)haystack 篇
生活随笔
收集整理的這篇文章主要介紹了
django全文搜索学习心得(一)haystack 篇
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近開始學習django開發,而網站避免不了使用全文搜索,于是乎,就研究了一下。
首先,說一下個人對網站全文搜索的簡單認識,就是將部分數據庫內容以特定索引方式存在一個文件中,然后利用各種高效方法對其進行查找,匹配。django中我查看一些app,可用的很多。這里先記錄一下簡單應用,后期再補充各種高級應用。
這里先介紹一個比較強勢的,django-haystack ,官方說完成了對Solr,Elasticsearch,Whoosh,Xapian, 等等的使用封裝,讓我們在使用過程中只需更改settings.py 中的引擎即可方便切換方法,不用更改其他代碼。
安裝
到https://github.com/toastdriven/django-haystack 下載zip,2.0版本的。2.0版本的settings.py 設置方法比較好。
INSTALLED_APPS = [
...
'haystack',
...
]
import os
HAYSTACK_CONNECTIONS = {
'default': {
# For Solr:
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://localhost:9001/solr/example',
'TIMEOUT': 60 * 5,
'INCLUDE_SPELLING': True,
},
'whoosh': {
# For Whoosh:
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
'INCLUDE_SPELLING': True,
},
'simple': {
# For Simple:
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
},
'xapian': {
# For Xapian (requires the third-party install):
'ENGINE': 'xapian_haystack.xapian_backend.XapianEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'xapian_index'),
}
}
urls.py 的配置
urlpatterns = patterns('',
(r'^search/', include('haystack.urls')),
)
隨緣
總結
以上是生活随笔為你收集整理的django全文搜索学习心得(一)haystack 篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SSH私钥取消密码(passphrase
- 下一篇: ash, bash, ksh, csh,