当前位置 : 主页 > 网络推广 > seo >

全文搜索django:Mysql没那么糟糕? (vs sphinx,xapian)

来源:互联网 收集:自由互联 发布时间:2021-06-16
我正在研究 django的全文搜索引擎. 它必须易于安装,快速索引,快速索引更新,索引时不阻塞,快速搜索. 阅读了很多网页后,我列入了简短的列表: Mysql MYISAM全文,djapian / python-xapian和django-
我正在研究 django的全文搜索引擎.
它必须易于安装,快速索引,快速索引更新,索引时不阻塞,快速搜索.

阅读了很多网页后,我列入了简短的列表:
Mysql MYISAM全文,djapian / python-xapian和django-sphinx
我没有选择lucene,因为它似乎很复杂,也没有干草堆,因为它的功能比djapian / django-spĥinx少(比如字段加权).

然后我做了一些基准测试,为此,我在网上收集了许多免费书籍以生成一个包含1 485 000条记录(id,title,body)的数据库表,每条记录长约600字节.
从数据库中,我还生成了一个包含10万个现有单词的列表,并将它们混洗以创建搜索列表.对于测试,我在我的笔记本电脑上进行了2次运行(4Go RAM,双核2.0Ghz):第一次,在服务器重新启动以清除所有缓存之后,第二次完成juste以便测试缓存结果有多好.以下是“自制”基准测试结果:

1485000 records with Title (150 bytes) and body (450 bytes)

Mysql 5.0.75/Ubuntu 9.04 Fulltext :
==========================================================================

Full indexing : 7m14.146s

1 thread, 1000 searchs with single word randomly taken from database : 
First run : 0:01:11.553524
next run : 0:00:00.168508

Mysql 5.5.4 m3/Ubuntu 9.04 Fulltext :
==========================================================================

Full indexing : 6m08.154s

1 thread, 1000 searchs with single word randomly taken from database : 
First run : 0:01:09.553524
next run : 0:00:20.316903

1 thread, 100000 searchs with single word randomly taken from database : 
First run : 9m09s
next run : 5m38s

1 thread, 10000 random strings (random strings should not be found in database) :
just after the 100000 search test : 0:00:15.007353

1 thread, boolean search : 1000 x (+word1 +word2) 
First run : 0:00:21.205404
next run : 0:00:00.145098

Djapian Fulltext : 
==========================================================================

Full indexing : 84m7.601s

1 thread, 1000 searchs with single word randomly taken from database with prefetch : 
First run : 0:02:28.085680
next run : 0:00:14.300236

python-xapian Fulltext :
==========================================================================

1 thread, 1000 searchs with single word randomly taken from database : 
First run : 0:01:26.402084
next run : 0:00:00.695092

django-sphinx Fulltext :
==========================================================================

Full indexing : 1m25.957s

1 thread, 1000 searchs with single word randomly taken from database : 
First run : 0:01:30.073001
next run : 0:00:05.203294

1 thread, 100000 searchs with single word randomly taken from database : 
First run : 12m48s
next run : 9m45s

1 thread, 10000 random strings (random strings should not be found in database) :
just after the 100000 search test : 0:00:23.535319

1 thread, boolean search : 1000 x (word1 word2) 
First run : 0:00:20.856486
next run : 0:00:03.005416

正如您所看到的,Mysql对于全文搜索来说并不是那么糟糕.此外,它的查询缓存非常有效.

Mysql在我看来是一个不错的选择,因为没有什么可以安装的(我只需要编写一个小脚本来将Innodb生产表同步到MyISAM搜索表),因为我真的不需要像词干等高级搜索功能……

这是一个问题:你如何看待Mysql全文搜索引擎vs sphinx和xapian?

我没有测试Xapian,但去年我做了一个比较全文解决方案的演示:
http://www.slideshare.net/billkarwin/practical-full-text-search-with-my-sql

狮身人面像是搜索速度最快的.但是很难对逐步增加的数据进行索引,因为向索引添加数据与从头创建整个索引一样昂贵.

因此,有些人维护两个Sphinx索引:一个带有归档数据的大索引,一个带有最新数据的小索引.他们定期(例如每周)将最近的索引合并到归档索引(合并两个索引更便宜),并截断小索引以准备新的一周.这对于像论坛这样的东西很有用,但对于维基来说却不是很好.

您也可以查看Apache Solr.这是Lucene的包装器,它使Lucene使用起来更容易,而且功能更强大.当我设计那个演示时,我不知道Solr.

华盛顿时报是一个将Solr与Django一起使用的项目示例:

> http://www.screeley.com/djangosolr/
> http://www.chrisumbel.com/article/django_solr

网友评论