简体   繁体   English

使用Java技术实现搜索(Java Web)

[英]implementing search using java technology(java web)

I want to implement a search functionality in my web application that I am building using java technology. 我想在使用Java技术构建的Web应用程序中实现搜索功能。 I would have to search through the database, depending on the user query and will display the results. 我将不得不搜索数据库,具体取决于用户查询,并将显示结果。 Which way can I go about doing this(please take note I am using java technology)??.Thanks. 我可以采用哪种方式进行此操作(请注意我正在使用Java技术)。谢谢。

You can use a product like http://lucene.apache.org/core/ or http://lucene.apache.org/solr/ for this instead of writing this on your own. 您可以使用类似http://lucene.apache.org/core/http://lucene.apache.org/solr/的产品来代替自己编写。

Lucene is a high-performance search engine for documents. Lucene是文档的高性能搜索引擎。 SOLR is built on top of Lucene and provides additional features (like hit highlighting, faceted search, database integration or rich document (Word, PDF, ..) search) SOLR建立在Lucene之上,并提供其他功能(例如,命中突出显示,多面搜索,数据库集成或丰富的文档(Word,PDF等)搜索)

Lucene will analyze your text data and build up an index. Lucene将分析您的文本数据并建立索引。 When performing a search you run a lucene query against this index. 执行搜索时,您将针对此索引运行lucene查询。

Assuming you mean free text searching of the data in the database... 假设您的意思是对数据库中的数据进行自由文本搜索...

For free text searching Lucene and/or SOLR are very good solutions. 对于免费文本搜索,Lucene和/或SOLR是很好的解决方案。 These work by creating a separate index of the data in your database. 这些通过在数据库中创建数据的单独索引来工作。 It is up to you to either pull the data from the database and index it using Lucene/SOLR or arrange your code that writes to the database to also update the Lucene/SOLR index. 由您决定是从数据库中提取数据并使用Lucene / SOLR将其编入索引,还是安排写入数据库的代码来更新Lucene / SOLR索引。 Given what you have said it sounds like this is being retrofitted to an existing database so pulling the data and indexing it may be the best solution. 鉴于您所说的,这听起来像是正在对现有数据库进行改装,因此提取数据并为其建立索引可能是最好的解决方案。 In this case SOLR is probbaly a better fit as it is a packaged solution. 在这种情况下,SOLR可能是一个更好的解决方案,因为它是一个打包的解决方案。

Another option would be Hibernate Search . 另一个选择是Hibernate Search Again this would be a solution to use if you are starting out. 同样,如果您刚开始,这将是一个可以使用的解决方案。 It would be more difficult to add after the fact. 在此之后添加起来会更加困难。

Also bear in mind some databases support free text searching in addition to normal relational queries and could be worth a look. 还请记住,除了正常的关系查询之外,某些数据库还支持自由文本搜索,因此值得一看。 SQL Server certainly has text search capabilities and I would imagine other databases have some sort of support. SQL Server当然具有文本搜索功能,我想其他数据库也将提供某种支持。 I am not too sure how you access these but I would expect to be able to do it using SQL via JDBC. 我不太确定如何访问这些,但是我希望能够通过JDBC使用SQL来实现。 It is likely to be database specific though. 不过,它可能是特定于数据库的。

If you just mean normal SQL searching then there are a whole load of Java EE technologies, plain JDBC, Spring templates, ORM technologies (JPA, JDO, Hibernate etc). 如果您只是说普通的SQL搜索,那么就包含了Java EE技术,纯JDBC,Spring模板和ORM技术(JPA,JDO,Hibernate等)的全部负载。 The list goes on and it would be difficult to suggest any particular approach without a lot more info. 清单还在继续,如果没有很多信息,很难建议任何特定的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM