You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Romi <ro...@gmail.com> on 2011/06/02 09:14:20 UTC

How to display search results of solr in to other application.

Hi, I am creating indexes using solr which is running on jetty server port
8983, and my application is running on tomcat server port 8080. Now my
problem is i want to display the results of search on my application. i
created a ajax-javascript page for parsing Json object. now please suggest
me how i send my request to solr server for search and get back the result.

Here is my sample html file where i parsed Json data.

<html>
<head>
<title>Solr Ajax Example</title>

</head>
<body>

<form name="f1" onsubmit='xmlhttpPost("/solr/db/select"); return false;'>
  <p>query: <input name="query" type="text">  
  <input value="Go" type="submit"></p>
  
<div id="result"></div>
<p/><pre>Raw JSON String: <div id="raw"></div></pre>
</form>
</body>
</html>



I suppose i am making mistake in xmlhttpPost("/solr/db/select").

Thanks and regards
Romi.

-----
Thanks & Regards
Romi
--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-display-search-results-of-solr-in-to-other-application-tp3014101p3014101.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to display search results of solr in to other application.

Posted by Naveen Gupta <nk...@gmail.com>.
Hi Romi

As per me, you need to understand how ajax with jquery works .. then go for
json and then jsonp (if you are fetching from different)

query here is dynamic query which you will be trying to hit solr .. (it
could be simple text, or more advanced query string)

http://wiki.apache.org/solr/CommonQueryParameters

Callback is the method name which you will define .. after getting response,
this method will be called (callback mechanism)

using the response from solr (json format), you need to show the response or
analyze the response as per your business need.

Thanks
Naveen


On Fri, Jun 3, 2011 at 12:00 PM, Romi <ro...@gmail.com> wrote:

> $.getJSON(
>           "http://[server]:[port]/solr/select/?jsoncallback=?",
>               {"q": queryString,
>               "version": "2.2",
>               "start": "0",
>               "rows": "10",
>               "indent": "on",
>               "json.wrf": "callbackFunctionToDoSomethingWithOurData",
>               "wt": "json",
>               "fl": "field1"}
>       );
>
> would you please explain what are  queryString and "json.wrf":
> "callbackFunctionToDoSomethingWithOurData". and what if i want to change my
> query string each time.
>
> -----
> Thanks & Regards
> Romi
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/How-to-display-search-results-of-solr-in-to-other-application-tp3014101p3018740.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: How to display search results of solr in to other application.

Posted by Romi <ro...@gmail.com>.
$.getJSON(
           "http://[server]:[port]/solr/select/?jsoncallback=?",
               {"q": queryString,
               "version": "2.2",
               "start": "0",
               "rows": "10",
               "indent": "on",
               "json.wrf": "callbackFunctionToDoSomethingWithOurData",
               "wt": "json",
               "fl": "field1"}
       ); 

would you please explain what are  queryString and "json.wrf":
"callbackFunctionToDoSomethingWithOurData". and what if i want to change my
query string each time.

-----
Thanks & Regards
Romi
--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-display-search-results-of-solr-in-to-other-application-tp3014101p3018740.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to display search results of solr in to other application.

Posted by lee carroll <le...@googlemail.com>.
did you include the jquery lib,
make sure you use the jsasoncallback

ie
$.getJSON(
           "http://[server]:[port]/solr/select/?jsoncallback=?",
               {"q": queryString,
               "version": "2.2",
               "start": "0",
               "rows": "10",
               "indent": "on",
               "json.wrf": "callbackFunctionToDoSomethingWithOurData",
               "wt": "json",
               "fl": "field1"}
       );

not what you have got



On 2 June 2011 13:00, Romi <ro...@gmail.com> wrote:
> I did this:
>
>  $(document).ready(function(){
>
>
> $.getJSON("http://[remotehost]:8983/solr/select/?q=diamond&wt=json&json.wrf=?",
> function(result){
>
>  alert("hello" + result.response.docs[0].name);
> });
> });
>
>
> But i am not getting any result, what i did wrong ??
>
> -----
> Thanks & Regards
> Romi
> --
> View this message in context: http://lucene.472066.n3.nabble.com/How-to-display-search-results-of-solr-in-to-other-application-tp3014101p3014797.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: How to display search results of solr in to other application.

Posted by Romi <ro...@gmail.com>.
I did this:

 $(document).ready(function(){


$.getJSON("http://[remotehost]:8983/solr/select/?q=diamond&wt=json&json.wrf=?",
function(result){

 alert("hello" + result.response.docs[0].name);
});
});


But i am not getting any result, what i did wrong ?? 

-----
Thanks & Regards
Romi
--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-display-search-results-of-solr-in-to-other-application-tp3014101p3014797.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to display search results of solr in to other application.

Posted by lee carroll <le...@googlemail.com>.
this is from another post and could help

Can you use a javascript library which handles ajax and json / jsonp
You will end up with much cleaner client code for example a jquery
implementation looks quite nice using solrs neat jsonp support:

queryString = "*:*"
$.getJSON(
            "http://[server]:[port]/solr/select/?jsoncallback=?",
                {"q": queryString,
                "version": "2.2",
                "start": "0",
                "rows": "10",
                "indent": "on",
                "json.wrf": "callbackFunctionToDoSomethingWithOurData",
                "wt": "json",
                "fl": "field1"}
        );

and the callback function

function callbackFunctionToDoSomethingWithOurData(solrData) {
           // do stuff with your nice data
        }

Their is also a javascript client for solr as well but i've not used this

On 2 June 2011 08:14, Romi <ro...@gmail.com> wrote:
> Hi, I am creating indexes using solr which is running on jetty server port
> 8983, and my application is running on tomcat server port 8080. Now my
> problem is i want to display the results of search on my application. i
> created a ajax-javascript page for parsing Json object. now please suggest
> me how i send my request to solr server for search and get back the result.
>
> Here is my sample html file where i parsed Json data.
>
> <html>
> <head>
> <title>Solr Ajax Example</title>
>
> </head>
> <body>
>
> <form name="f1" onsubmit='xmlhttpPost("/solr/db/select"); return false;'>
>  <p>query: <input name="query" type="text">
>  <input value="Go" type="submit"></p>
>
> <div id="result"></div>
> <p/><pre>Raw JSON String: <div id="raw"></div></pre>
> </form>
> </body>
> </html>
>
>
>
> I suppose i am making mistake in xmlhttpPost("/solr/db/select").
>
> Thanks and regards
> Romi.
>
> -----
> Thanks & Regards
> Romi
> --
> View this message in context: http://lucene.472066.n3.nabble.com/How-to-display-search-results-of-solr-in-to-other-application-tp3014101p3014101.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>