zoukankan      html  css  js  c++  java
  • django全文搜索学习心得(一)haystack 篇

        最近开始学习django开发,而网站避免不了使用全文搜索,于是乎,就研究了一下。

        首先,说一下个人对网站全文搜索的简单认识,就是将部分数据库内容以特定索引方式存在一个文件中,然后利用各种高效方法对其进行查找,匹配。django中我查看一些app,可用的很多。这里先记录一下简单应用,后期再补充各种高级应用。

        这里先介绍一个比较强势的,django-haystack ,官方说完成了对 SolrElasticsearchWhooshXapian, 等等的使用封装,让我们在使用过程中只需更改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')),
    )
    

      

    随缘
  • 相关阅读:
    POJ 3253 Fence Repair
    POJ 2431 Expedition
    NYOJ 269 VF
    NYOJ 456 邮票分你一半
    划分数问题 DP
    HDU 1253 胜利大逃亡
    NYOJ 294 Bot Trust
    NYOJ 36 最长公共子序列
    HDU 1555 How many days?
    01背包 (大数据)
  • 原文地址:https://www.cnblogs.com/chang/p/2855197.html
Copyright © 2011-2022 走看看