推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
leoYu
V2EX  ›  Python

实现 AutoComplete(自动完成),求最佳方案

  •  
  •   leoYu · Apr 23, 2014 · 7193 views
    This topic created in 4402 days ago, the information mentioned may be changed or developed.
    1.使用Solr的搜索组件(SearchComponent):termsComponent

    打开某实例的配置文件 solrConfig.xml,增加搜索组件配置

    2.直接使用Solr的基础搜索接口Select实现

    3.还有这篇文章,用redis实现autocomplete的文章 http://oldblog.antirez.com/post/autocomplete-with-redis.html

    4.redis的交集功能来做搜索

    但这个办法有几个缺陷
    我觉得还是偏重,因为我只想实现一个用户名自动联想的功能而不是搜索。这样的系统还要维护一套庞大的索引,每次更新用户名还得一个一个删掉然后再塞入新的。
    无法做LIMIT和OFFSET啊,翻页怎么半,万一一个交集非常大,岂不是要把系统撑死
    模糊查询的功能偏弱,只能处理以关键词开头的情况。不过这个不是重点,能把上面两点解决就很好了。
    不知道各位有什么好的方案?
    solr也不够灵活
    2 replies    2014-06-03 00:40:06 +08:00
    okidogi
        1
    okidogi  
       Apr 23, 2014
    redis就可以啊,目前用来还不错的性能。
    试试这个: https://github.com/fengli/autocomplete-redis
    KennyZJ
        2
    KennyZJ  
       Jun 3, 2014
    redis最新的2.8.9比之前更进一步,zrangebylex已经很好用了,基本上这个command就主要针对的autocompletion,类比google instant search
    http://redis.io/commands/zrangebylex
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2910 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 163ms · UTC 15:22 · PVG 23:22 · LAX 08:22 · JFK 11:22
    ♥ Do have faith in what you're doing.