Apache的Lucene的 - 优化搜索 [英] Apache Lucene - Optimizing Searching

查看:97
本文介绍了Apache的Lucene的 - 优化搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发在Java中(使用S​​pring),它使用一个SQL Server数据库的Web应用程序。我使用Apache Lucene来实现我的web应用程序的搜索功能。与Apache Lucene的,以前我执行搜索创建标题的索引。我通过先获取数据库中的所有标题的列表做到这一点。然后,我遍历标题的列表,并添加他们中的每一个索引。这种情况发生在用户每次搜索的东西的时间。

I am developing a web application in Java (using Spring) that uses a SQL Server database. I use Apache Lucene to implement a search feature for my web application. With Apache Lucene, before I perform a search I create an index of titles. I do this by first obtaining a list of all titles from the database. Then I loop through the list of titles and add each one of them to the index. This happens every time a user searches for something.

我想知道是否有创建索引的更好的,更有效的方法?我知道我的方式是非常低效的,而且会需要很长的时间才能完成,当冠军的名单很长。

I would like to know if there is a better, more efficient way of creating the index? I know my way is very inefficient, and will take a long time to complete when the list of titles is very long.

任何建议将是非常美联社preciated。

Any suggestions would be highly appreciated.

感谢

推荐答案

在您优化的Lucene:SQL服务器已经有了一个的全文搜索功能。如果这包括你的使用情况,然后使用它。这是最简单的方法,因为SQL Server的需要与数据库保持搜索索引同步的照顾。

Before you optimize Lucene: SQL Server already has a full-text search feature. If this covers your use case then use it. It's the easiest way since SQL Server takes care of keeping the search index in sync with the database.

如果在SQL Server全文搜索不适合你的使用情况,那么您的应用程序来创建自己的搜索索引和数据库保持同步。要做到这一点,你应该:

If the SQL Server full-text search does not fit your use case then your application has to create its own search index and keep it in sync with the database. To do this you should:


  • 您的应用程序启动时创建/更新搜索索引

  • 更新搜索索引,当应用程序插入,更新或删除标题

Lucene是灵活的,它存储搜索索引。您可以在目录存储在文件系统或数据库(或写你自己的存储供应商)。我建议将其存储在文件系统中的性能是当你把它存储在数据库中比要好得多。

Lucene is flexible where it stores the search index. You can store it in a directory in your file system or in the database (or write you own storage provider). I recommend to store it in the file system as the performance is much better than when you store it in the database.

如果你没有太多的标题索引你也可以使用你每次重新创建你的应用程序启动时在内存中的搜索索引。

If you don't have too many titles to index you could also use an in-memory search index which you recreate every time your application starts.

这篇关于Apache的Lucene的 - 优化搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆