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 ahammad <ah...@gmail.com> on 2009/06/02 17:06:55 UTC

Using SolrJ with multicore/shards

Hello,

I have a MultiCore install of solr with 2 cores with different schemas and
such. Querying directly using http request and/or the solr interface works
very well for my purposes.

I want to have a proper search interface though, so I have some code that
basically acts as a link between the server and the front-end. Basically,
depending on the options, the search string is built, and when the search is
submitted, that string gets passed as an http request. The code then would
parse through the xml to get the information.

This method works with shards because I can add the shards parameter
straight into the link that I end up hitting. Although this is currently
functional, I was thinking of using SolrJ simply because it is simpler to
use and would cut down the amount of code.

The question is, how would I be able to define the shards in my query, so
that when I do search, I hit both shards and get mixed results back? Using
http requests, it's as simple as adding a shard=core0,core1 snippet. What is
the equivalent of this in SolrJ?

BTW, I do have some SolrJ code that is able to query and return results, but
for a single core. I am currently using CommonsHttpSolrServer for that, not
the Embedded one.

Cheers
-- 
View this message in context: http://www.nabble.com/Using-SolrJ-with-multicore-shards-tp23834518p23834518.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Using SolrJ with multicore/shards

Posted by ahammad <ah...@gmail.com>.
Sorry for the additional message, the disclaimer was missing.

Disclaimer: The code that was used was taken from the following site:
http://e-mats.org/2008/04/using-solrj-a-short-guide-to-getting-started-with-solrj/
. 


ahammad wrote:
> 
> Hello,
> 
> I played around some more with it and I found out that I was pointing my
> constructor to an older class that doesn't have the MultiCore capability.
> 
> This is what I did to set up the shards:
> 
> query.setParam("shards",
> "localhost:8080/solr/core0/,localhost:8080/solr/core1/");
> 
> I do have a new issue with this though. Here is how the results are
> displayed:
> 
>            QueryResponse qr = server.query(query);
> 
>             SolrDocumentList sdl = qr.getResults();
> 
>             System.out.println("Found: " + sdl.getNumFound());
>             System.out.println("Start: " + sdl.getStart());
>             System.out.println("Max Score: " + sdl.getMaxScore());
>             System.out.println("--------------------------------");
> 
>             ArrayList<HashMap<String, Object>> hitsOnPage = new
> ArrayList<HashMap<String, Object>>();
> 
>             for(SolrDocument d : sdl)
>             {
>             	
>                 HashMap<String, Object> values = new HashMap<String,
> Object>();
> 
>                 for(Iterator<Map.Entry<String, Object>> i = d.iterator();
> i.hasNext(); )
>                 {
>                     Map.Entry<String, Object> e2 = i.next();
> 
>                     values.put(e2.getKey(), e2.getValue());
>                 }
> 
>                 hitsOnPage.add(values);
>                  
>                 String outputString = new String(  values.get("title") );
>                 System.out.println(outputString);
>             }
> 
> The field "title" is one of the common fields that is shared between the
> two schemas. When I print the results of my query, I get null for
> everything. However, the result of sdl.getNumFound() is correct, so I know
> that both cores are being accessed.
> 
> Is there a difference with how SolrJ handles multicore requests?
> 
> Disclaimer: The code 
> 
> 
> 
> ahammad wrote:
>> 
>> Hello,
>> 
>> I have a MultiCore install of solr with 2 cores with different schemas
>> and such. Querying directly using http request and/or the solr interface
>> works very well for my purposes.
>> 
>> I want to have a proper search interface though, so I have some code that
>> basically acts as a link between the server and the front-end. Basically,
>> depending on the options, the search string is built, and when the search
>> is submitted, that string gets passed as an http request. The code then
>> would parse through the xml to get the information.
>> 
>> This method works with shards because I can add the shards parameter
>> straight into the link that I end up hitting. Although this is currently
>> functional, I was thinking of using SolrJ simply because it is simpler to
>> use and would cut down the amount of code.
>> 
>> The question is, how would I be able to define the shards in my query, so
>> that when I do search, I hit both shards and get mixed results back?
>> Using http requests, it's as simple as adding a shard=core0,core1
>> snippet. What is the equivalent of this in SolrJ?
>> 
>> BTW, I do have some SolrJ code that is able to query and return results,
>> but for a single core. I am currently using CommonsHttpSolrServer for
>> that, not the Embedded one.
>> 
>> Cheers
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-SolrJ-with-multicore-shards-tp23834518p23838988.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Using SolrJ with multicore/shards

Posted by ahammad <ah...@gmail.com>.
Hello,

I played around some more with it and I found out that I was pointing my
constructor to an older class that doesn't have the MultiCore capability.

This is what I did to set up the shards:

query.setParam("shards",
"localhost:8080/solr/core0/,localhost:8080/solr/core1/");

I do have a new issue with this though. Here is how the results are
displayed:

           QueryResponse qr = server.query(query);

            SolrDocumentList sdl = qr.getResults();

            System.out.println("Found: " + sdl.getNumFound());
            System.out.println("Start: " + sdl.getStart());
            System.out.println("Max Score: " + sdl.getMaxScore());
            System.out.println("--------------------------------");

            ArrayList<HashMap<String, Object>> hitsOnPage = new
ArrayList<HashMap<String, Object>>();

            for(SolrDocument d : sdl)
            {
            	
                HashMap<String, Object> values = new HashMap<String,
Object>();

                for(Iterator<Map.Entry<String, Object>> i = d.iterator();
i.hasNext(); )
                {
                    Map.Entry<String, Object> e2 = i.next();

                    values.put(e2.getKey(), e2.getValue());
                }

                hitsOnPage.add(values);
                 
                String outputString = new String(  values.get("title") );
                System.out.println(outputString);
            }

The field "title" is one of the common fields that is shared between the two
schemas. When I print the results of my query, I get null for everything.
However, the result of sdl.getNumFound() is correct, so I know that both
cores are being accessed.

Is there a difference with how SolrJ handles multicore requests?

Disclaimer: The code 



ahammad wrote:
> 
> Hello,
> 
> I have a MultiCore install of solr with 2 cores with different schemas and
> such. Querying directly using http request and/or the solr interface works
> very well for my purposes.
> 
> I want to have a proper search interface though, so I have some code that
> basically acts as a link between the server and the front-end. Basically,
> depending on the options, the search string is built, and when the search
> is submitted, that string gets passed as an http request. The code then
> would parse through the xml to get the information.
> 
> This method works with shards because I can add the shards parameter
> straight into the link that I end up hitting. Although this is currently
> functional, I was thinking of using SolrJ simply because it is simpler to
> use and would cut down the amount of code.
> 
> The question is, how would I be able to define the shards in my query, so
> that when I do search, I hit both shards and get mixed results back? Using
> http requests, it's as simple as adding a shard=core0,core1 snippet. What
> is the equivalent of this in SolrJ?
> 
> BTW, I do have some SolrJ code that is able to query and return results,
> but for a single core. I am currently using CommonsHttpSolrServer for
> that, not the Embedded one.
> 
> Cheers
> 

-- 
View this message in context: http://www.nabble.com/Using-SolrJ-with-multicore-shards-tp23834518p23838351.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Using SolrJ with multicore/shards

Posted by ahammad <ah...@gmail.com>.
I'm still not sure what you meant. I took a look at that class but I haven't
got any idea on how to proceed.

BTW I tried something like this 

query.setParam("shard", "http://localhost:8080/solr/core0/" ,
"http://localhost:8080/solr/core1/");

But it doesn't seem to work for me. I tried it with different variations
too, like removing the http://, and combining both cores as a single string.

Could you please clarify your suggestion?

Regards


Otis Gospodnetic wrote:
> 
> 
> You should be able to set any name=value URL parameter pair and send it to
> Solr using SolrJ.  What's the name of that class... MapSolrParams, I
> believe.
> 
>  Otis
> --
> Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch
> 
> 
> 
> ----- Original Message ----
>> From: ahammad <ah...@gmail.com>
>> To: solr-user@lucene.apache.org
>> Sent: Tuesday, June 2, 2009 11:06:55 AM
>> Subject: Using SolrJ with multicore/shards
>> 
>> 
>> Hello,
>> 
>> I have a MultiCore install of solr with 2 cores with different schemas
>> and
>> such. Querying directly using http request and/or the solr interface
>> works
>> very well for my purposes.
>> 
>> I want to have a proper search interface though, so I have some code that
>> basically acts as a link between the server and the front-end. Basically,
>> depending on the options, the search string is built, and when the search
>> is
>> submitted, that string gets passed as an http request. The code then
>> would
>> parse through the xml to get the information.
>> 
>> This method works with shards because I can add the shards parameter
>> straight into the link that I end up hitting. Although this is currently
>> functional, I was thinking of using SolrJ simply because it is simpler to
>> use and would cut down the amount of code.
>> 
>> The question is, how would I be able to define the shards in my query, so
>> that when I do search, I hit both shards and get mixed results back?
>> Using
>> http requests, it's as simple as adding a shard=core0,core1 snippet. What
>> is
>> the equivalent of this in SolrJ?
>> 
>> BTW, I do have some SolrJ code that is able to query and return results,
>> but
>> for a single core. I am currently using CommonsHttpSolrServer for that,
>> not
>> the Embedded one.
>> 
>> Cheers
>> -- 
>> View this message in context: 
>> http://www.nabble.com/Using-SolrJ-with-multicore-shards-tp23834518p23834518.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-SolrJ-with-multicore-shards-tp23834518p23836485.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Using SolrJ with multicore/shards

Posted by Otis Gospodnetic <ot...@yahoo.com>.
You should be able to set any name=value URL parameter pair and send it to Solr using SolrJ.  What's the name of that class... MapSolrParams, I believe.

 Otis
--
Sematext -- http://sematext.com/ -- Lucene - Solr - Nutch



----- Original Message ----
> From: ahammad <ah...@gmail.com>
> To: solr-user@lucene.apache.org
> Sent: Tuesday, June 2, 2009 11:06:55 AM
> Subject: Using SolrJ with multicore/shards
> 
> 
> Hello,
> 
> I have a MultiCore install of solr with 2 cores with different schemas and
> such. Querying directly using http request and/or the solr interface works
> very well for my purposes.
> 
> I want to have a proper search interface though, so I have some code that
> basically acts as a link between the server and the front-end. Basically,
> depending on the options, the search string is built, and when the search is
> submitted, that string gets passed as an http request. The code then would
> parse through the xml to get the information.
> 
> This method works with shards because I can add the shards parameter
> straight into the link that I end up hitting. Although this is currently
> functional, I was thinking of using SolrJ simply because it is simpler to
> use and would cut down the amount of code.
> 
> The question is, how would I be able to define the shards in my query, so
> that when I do search, I hit both shards and get mixed results back? Using
> http requests, it's as simple as adding a shard=core0,core1 snippet. What is
> the equivalent of this in SolrJ?
> 
> BTW, I do have some SolrJ code that is able to query and return results, but
> for a single core. I am currently using CommonsHttpSolrServer for that, not
> the Embedded one.
> 
> Cheers
> -- 
> View this message in context: 
> http://www.nabble.com/Using-SolrJ-with-multicore-shards-tp23834518p23834518.html
> Sent from the Solr - User mailing list archive at Nabble.com.