How to iterate the solrdocumentlist result

2009-05-03 Thread ahmed baseet
Hi All,
I'm able to get the whole result bundle by using the following method,

   QueryResponse qr = server.query(query);

SolrDocumentList sdl = qr.getResults();

but I'm not able to iterate over the results. I converted this to string and
displayed that and that is a full result bundle, I think its in XML.
Actually I want to display the result in a browser and each one separately,
I mean not as a bundle. There must be some standard methods for this, right
? Can some one give me some pointers in this regard... I'm trying to
integrate the java method calls withing html code itself[ the solr server is
on my box, and I want to do the testing on my box, so I want to access the
indexer from my local box's browser only]. Any good ideas on this?

Thanks,
Ahmed.


Re: How to iterate the solrdocumentlist result

2009-05-03 Thread Avlesh Singh
SolrDocumentList extends an ArrayList. You can iterate on it the way you
would do on a list. Here's an example

for(SolrDocument doc : listingSearchResponse.getResults()){
>   System.out.print(doc.getFieldValue("yourFieldName"));
> }
>

Cheers
Avlesh

On Mon, May 4, 2009 at 10:36 AM, ahmed baseet wrote:

> Hi All,
> I'm able to get the whole result bundle by using the following method,
>
>   QueryResponse qr = server.query(query);
>
>SolrDocumentList sdl = qr.getResults();
>
> but I'm not able to iterate over the results. I converted this to string
> and
> displayed that and that is a full result bundle, I think its in XML.
> Actually I want to display the result in a browser and each one separately,
> I mean not as a bundle. There must be some standard methods for this, right
> ? Can some one give me some pointers in this regard... I'm trying to
> integrate the java method calls withing html code itself[ the solr server
> is
> on my box, and I want to do the testing on my box, so I want to access the
> indexer from my local box's browser only]. Any good ideas on this?
>
> Thanks,
> Ahmed.
>


org.apache.*.*.... class not found exception in Internet Explorer

2009-05-03 Thread ahmed baseet
Hi,
I'm trying to query solr indexer thru a web page and trying to display the
result. I've the following class to query solr [I'm using the query(string)
method],

import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrDocument;
import java.util.Map;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;


public class SolrjTest
{
public String query(String q)
{
CommonsHttpSolrServer server = null;

try
{
server = new CommonsHttpSolrServer("http://localhost:8983/solr/
");
}
catch(Exception e)
{
e.printStackTrace();
}

SolrQuery query = new SolrQuery();
query.setQuery(q);
query.setQueryType("dismax");
query.setIncludeScore(true);

try
{
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("");
//System.out.println("Result doc : " + sdl);

return sdl.toString();

}
catch (SolrServerException e)
{
e.printStackTrace();
return null;
}


}

  }


and the following to pass the queries to solr, get results and display it on
the browser,

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;

public class ControlJava extends Applet {
Font f = new Font("TimesRoman", Font.BOLD, 20);
String Message;

public void init() {
  Message = new String("ubuntu");
}

public void SetMessage(String MsgText) {
SolrjTest solr = new SolrjTest();
Message = solr.query(MsgText);

   repaint();
}

public void paint(Graphics g) {
  g.setFont(f);
  g.drawString(Message, 15, 50);
  }
}

and finally the html page is this,



Control a Java Applet


Control a Java Applet

The Java applet below displays text in a large font. You can enter
new text to display in the form below, and JavaScript will call the
Java applet to change the text.









End of page.



When I'm trying to access this page and putting the query in the box that
this html shows, the browser [IE] gives some error and after checking I
found that the error is some class not found exception, its not able to find
the org.apache.*.* classes and hence giving errors. Now instead of
calling that I wrote a simpe class not using any apache.solr classes and
called the method therein [just returns a string] and it worked fine. I
added both both the classes [.class files] given above to the same location
where this web page resides.
The problem is that browser is not able to find those org.apache.*** classes
and creating the mess. Can anyone help this newbie fixing the problem.
Thanks a lot.
Do let me know if some information is missing/want some extra information on
this issue.

--Ahmed.


Re: org.apache.*.*.... class not found exception in Internet Explorer

2009-05-03 Thread ahmed baseet
Missed some information.
I'm working on Windows XP and my class path is this,

.;E:\Program Files\Java\jdk1.6.0_05\bin;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\commons-httpclient-3.1.jar;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\apache-solr-common.jar;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\apache-solr-1.3.0.jar;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\solr-solrj-1.3.0.jar;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\commons-io-1.3.1.jar;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\commons-codec-1.3.jar;D:\firefox
download\apache-solr-1.3.0\apache-solr-1.3.0\dist\solrj-lib\commons-logging-1.0.4.jar


Thanks,
Ahmed.

On Mon, May 4, 2009 at 12:10 PM, ahmed baseet wrote:

> Hi,
> I'm trying to query solr indexer thru a web page and trying to display the
> result. I've the following class to query solr [I'm using the query(string)
> method],
>
> import org.apache.solr.common.SolrDocumentList;
> import org.apache.solr.common.SolrDocument;
> import java.util.Map;
> import java.util.Iterator;
> import java.util.List;
> import java.util.ArrayList;
> import java.util.HashMap;
>
> import org.apache.solr.client.solrj.SolrServerException;
> import org.apache.solr.client.solrj.SolrQuery;
> import org.apache.solr.client.solrj.response.QueryResponse;
> import org.apache.solr.client.solrj.response.FacetField;
> import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
>
>
> public class SolrjTest
> {
> public String query(String q)
> {
> CommonsHttpSolrServer server = null;
>
> try
> {
> server = new CommonsHttpSolrServer("
> http://localhost:8983/solr/";);
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
>
> SolrQuery query = new SolrQuery();
> query.setQuery(q);
> query.setQueryType("dismax");
> query.setIncludeScore(true);
>
> try
> {
> 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("");
> //System.out.println("Result doc : " + sdl);
>
> return sdl.toString();
>
> }
> catch (SolrServerException e)
> {
> e.printStackTrace();
> return null;
> }
>
>
> }
>
>   }
>
>
> and the following to pass the queries to solr, get results and display it
> on the browser,
>
> import java.applet.Applet;
> import java.awt.Graphics;
> import java.awt.Font;
>
> public class ControlJava extends Applet {
> Font f = new Font("TimesRoman", Font.BOLD, 20);
> String Message;
>
> public void init() {
>   Message = new String("ubuntu");
> }
>
> public void SetMessage(String MsgText) {
> SolrjTest solr = new SolrjTest();
> Message = solr.query(MsgText);
>
>repaint();
> }
>
> public void paint(Graphics g) {
>   g.setFont(f);
>   g.drawString(Message, 15, 50);
>   }
> }
>
> and finally the html page is this,
>
> 
> 
> Control a Java Applet
> 
> 
> Control a Java Applet
> 
> The Java applet below displays text in a large font. You can enter
> new text to display in the form below, and JavaScript will call the
> Java applet to change the text.
> 
> 
> 
>  onClick="document.ControlJava.SetMessage(document.form1.text1.value);">
> 
> 
> 
> 
> 
> End of page.
> 
> 
>
> When I'm trying to access this page and putting the query in the box that
> this html shows, the browser [IE] gives some error and after checking I
> found that the error is some class not found exception, its not able to find
> the org.apache.*.* classes and hence giving errors. Now instead of
> calling that I wrote a simpe class not using any apache.solr classes and
> called the method therein [just returns a string] and it worked fine. I
> added both both the classes [.class files] given above to the same location
> where this web page resides.
> The problem is that browser is not able to find those org.apache.***
> classes and creating the mess. Can anyone help this newbie fixing the
> problem. Thanks a lot.
> Do let me know if some information is missing/want some extra information
> on this issue.
>
> --Ahmed.
>
>
>