How to integrate Solr with Web Application

2019-05-10 03:54发布

问题:

After reading many Solr books and article all over on the net, now I have an idea of the power of this server.

But... how to integrate it in a real application? For example: a web site written in PHP, etc.

Right now, I understand that Solr produces XML, JSON etc results... so to integrate this in a web application, the "simple" work is to convert this information for render in a page or there are other technique to avoid this?

I'm my case, I have to develop a search engine to scan many documents and find result.

My idea was:

  • Use Solr to build an index and search documents
  • Use a web application to show the result

Looking on the net I haven't find anything that explains how to integrate Solr in a real application, all the reading are about "How to use Solr... with Solr..." Anything about a real integration.

Does someone have some useful resource how to integrate Solr in a real application, with some clean examples?

回答1:

Edit: It looks like Apache maintains their own list of recommended client APIs, and their recommended tool for PHP is Google's library (though they refer to it as SolPHP). Given this, I imagine that this is the best place to start.

A Solr library for the programming language you're using could save you some of the trouble in implementing the integration. For instance, if your site is written in PHP, you could try Google's Solr library for PHP.

I have done most of my Solr work in Java, so I have used SolrJ quite a bit. This is a well supported tool because it comes from Apache in parallel with the Solr product itself.

If you are doing work in any other languages, you are likely to find libraries available for them. The amount of time they save you may vary according to the quality of the library itself.



回答2:

When I was using Solr in my project, only my application server (that is Tomcat) was communicating with Solr server. I wrote a class, which executes GET requests to Solr server based on input provided by end user. When Solr returns XML/JSON back to an application server you may parse it and process as every other bussiness data (render an *.html). So, summing up, Web Browser never communicates directly with Solr, all goes through an application server:

WebBrowser  -> GET to application server      -> GET to Solr server
show *.html <-  parse XML/JSON, render *.html <- return XML/JSON


标签: solr