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 Kurt Sultana <ku...@gmail.com> on 2011/07/14 10:44:45 UTC

SolrJ Collapsable Query Fails

I am currently trying to run a collapsable query using SolrJ using SolR 3.3.
The problem is that when I run the query through the web interface, with
this url:

http://localhost:8080/solr/select/?q=attr_content%3Alynx&sort=attr_location+desc&group=true&group.field=attr_directory

I am able to see the XML which is returned. The problem though, is that when
I try to run the same query through SolrJ, using this code:

        SolrQuery queryString = new SolrQuery();

        for (String param : query.keySet())

        {
            if (param.equals("fq"))

            {
                queryString.addFilterQuery(query.get(param));

            }
            else
            {
                queryString.setParam(param, query.get(param));

            }
        }

        System.out.println(queryString.toString());

        QueryResponse response = server.query(queryString);
//Exception takes place at this line

        SolrDocumentList docList = response.getResults();

Which constructs a URL like so:

q=attr_content%3Alynx&sort=attr_location+desc&group=true&group.field=attr_directory

This throws an exception:

Caused by: org.apache.solr.common.SolrException: parsing error at
org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:145)
at
org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:106)
at
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:477)
at
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
at
org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
... 3 more Caused by: javax.xml.stream.XMLStreamException: ParseError at
[row,col]:[3,30088] Message: error reading value:LST at
org.apache.solr.client.solrj.impl.XMLResponseParser.readArray(XMLResponseParser.java:324)
at
org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:245)
at
org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:244)
at
org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:244)
at
org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:130)

I have tried it with both Jetty and Tomcat, the error is the same for both.
I have managed to get other queries to run (with both servers), so I presume
that the problem lies with this particular type of query.

Any insight on this problem will be highly appreciated,

Thanks :)

Re: SolrJ Collapsable Query Fails

Posted by Kurt Sultana <ku...@gmail.com>.
Hi,

Thanks for the code, snippet, it was very useful, however, can you please
include a very small description of certain unknown variables such as
'groupedInfo', 'ResultItem', 'searcher', 'fields' and the method
'solrDocumentToResultItem'?

Thanks

On Sat, Jul 16, 2011 at 3:36 PM, Kurt Sultana <ku...@gmail.com> wrote:

> > Thanks for the information. However, I still have one more
> > problem. I am
> > iterating over the values of the NamedList. I have 2
> > values, one
> > being 'responseHeader' and the other one being 'grouped'. I
> > would like to
> > access some information stored within the grouped section,
> > which has
> > data structured like so:
> >
> >
> grouped={attr_directory={matches=4,groups=[{groupValue=C:\Users\rvassallo\Desktop\Index,doclist={numFound=2,start=0,docs=[SolrDocument[{attr_meta=[Author,
> > kcook, Last-Modified, 2011-03-02T14:14:18Z...
> >
> > With the 'get("group")' method I am only able to access the
> > entire
> > '{attr_directory={matches=4,g...' section. Is there some
> > functionality which
> > allows me to get other data? Something like this for
> > instance:
> > 'get("group.matches")' or maybe
> > 'get(group.attr_directory.matches)' (which
> > will yield the value of 4), or do I need to process the
> > String that the
> > 'get("...")' returns to get what I need?
> >
> > Thanks :)
>
> I think accessing the relevant portion in a NamedList is troublesome. I
> suggest you to look at existing codes in solrJ. e.g. How facet info is
> extracted from NamedList.
>
> I am sending you the piece of code that I used to access grouped info.
> Hopefully It can give you some idea.
>
>  NamedList signature = (NamedList) groupedInfo.get("attr_directory");
>
>    if (signature == null) return new ArrayList(0);
>
>    matches.append(signature.get("matches"));
>
>
>    @SuppressWarnings("unchecked")
>    ArrayList<NamedList> groups = (ArrayList<NamedList>)
> signature.get("groups");
>
>    ArrayList<> resultItems = new ArrayList<>(groups.size());
>
>    StringBuilder builder = new StringBuilder();
>
>
>    for (NamedList res : groups) {
>
>      ResultItem resultItem = null;
>
>      String hash = null;
>      Integer found = null;
>      for (int i = 0; i < res.size(); i++) {
>        String n = res.getName(i);
>
>        Object o = res.getVal(i);
>
>        if ("groupValue".equals(n)) {
>          hash = (String) o;
>        } else if ("doclist".equals(n)) {
>          DocList docList = (DocList) o;
>          found = docList.matches();
>
>          try {
>            final SolrDocumentList list =
> SolrPluginUtils.docListToSolrDocumentList(docList, searcher, fields, null);
>            builder.setLength(0);
>
>            if (list.size() > 0)
>              resultItem = solrDocumentToResultItem(list.get(0), debug);
>
>            for (final SolrDocument document : list)
>              builder.append(document.getFieldValue("id")).append(',');
>
>
>          } catch (final IOException e) {
>            LOG.error("Unexpected Error", e);
>          }
>        }
>
>
>      }
>
>      if (found != null && found > 1 && resultItem != null) {
>        resultItem.setHash(hash);
>        resultItem.setFound(found);
>        builder.setLength(builder.length() - 1);
>        resultItem.setId(builder.toString());
>      }
>
>      // debug
>
>
>      resultItems.add(resultItem);
>    }
>
>    return resultItems;
>
>

Re: SolrJ Collapsable Query Fails

Posted by Ahmet Arslan <io...@yahoo.com>.

> Thanks for the information. However, I still have one more
> problem. I am
> iterating over the values of the NamedList. I have 2
> values, one
> being 'responseHeader' and the other one being 'grouped'. I
> would like to
> access some information stored within the grouped section,
> which has
> data structured like so:
> 
> grouped={attr_directory={matches=4,groups=[{groupValue=C:\Users\rvassallo\Desktop\Index,doclist={numFound=2,start=0,docs=[SolrDocument[{attr_meta=[Author,
> kcook, Last-Modified, 2011-03-02T14:14:18Z...
> 
> With the 'get("group")' method I am only able to access the
> entire
> '{attr_directory={matches=4,g...' section. Is there some
> functionality which
> allows me to get other data? Something like this for
> instance:
> 'get("group.matches")' or maybe
> 'get(group.attr_directory.matches)' (which
> will yield the value of 4), or do I need to process the
> String that the
> 'get("...")' returns to get what I need?
> 
> Thanks :)

I think accessing the relevant portion in a NamedList is troublesome. I suggest you to look at existing codes in solrJ. e.g. How facet info is extracted from NamedList.

I am sending you the piece of code that I used to access grouped info.
Hopefully It can give you some idea.

 NamedList signature = (NamedList) groupedInfo.get("attr_directory");

    if (signature == null) return new ArrayList(0);

    matches.append(signature.get("matches"));


    @SuppressWarnings("unchecked")
    ArrayList<NamedList> groups = (ArrayList<NamedList>) signature.get("groups");

    ArrayList<> resultItems = new ArrayList<>(groups.size());

    StringBuilder builder = new StringBuilder();


    for (NamedList res : groups) {

      ResultItem resultItem = null;

      String hash = null;
      Integer found = null;
      for (int i = 0; i < res.size(); i++) {
        String n = res.getName(i);

        Object o = res.getVal(i);

        if ("groupValue".equals(n)) {
          hash = (String) o;
        } else if ("doclist".equals(n)) {
          DocList docList = (DocList) o;
          found = docList.matches();

          try {
            final SolrDocumentList list = SolrPluginUtils.docListToSolrDocumentList(docList, searcher, fields, null);
            builder.setLength(0);

            if (list.size() > 0)
              resultItem = solrDocumentToResultItem(list.get(0), debug);

            for (final SolrDocument document : list)
              builder.append(document.getFieldValue("id")).append(',');


          } catch (final IOException e) {
            LOG.error("Unexpected Error", e);
          }
        }


      }

      if (found != null && found > 1 && resultItem != null) {
        resultItem.setHash(hash);
        resultItem.setFound(found);
        builder.setLength(builder.length() - 1);
        resultItem.setId(builder.toString());
      }

      // debug


      resultItems.add(resultItem);
    }

    return resultItems;

Re: SolrJ Collapsable Query Fails

Posted by Kurt Sultana <ku...@gmail.com>.
Hi,

Thanks for the information. However, I still have one more problem. I am
iterating over the values of the NamedList. I have 2 values, one
being 'responseHeader' and the other one being 'grouped'. I would like to
access some information stored within the grouped section, which has
data structured like so:

grouped={attr_directory={matches=4,groups=[{groupValue=C:\Users\rvassallo\Desktop\Index,doclist={numFound=2,start=0,docs=[SolrDocument[{attr_meta=[Author,
kcook, Last-Modified, 2011-03-02T14:14:18Z...

With the 'get("group")' method I am only able to access the entire
'{attr_directory={matches=4,g...' section. Is there some functionality which
allows me to get other data? Something like this for instance:
'get("group.matches")' or maybe 'get(group.attr_directory.matches)' (which
will yield the value of 4), or do I need to process the String that the
'get("...")' returns to get what I need?

Thanks :)

On Thu, Jul 14, 2011 at 12:52 PM, Ahmet Arslan <io...@yahoo.com> wrote:

>
> See the Yonik's reply : http://search-lucene.com/m/tCmky1v94D92/
>
> In short you need to use NamedList<Object> getResponse().
>
> > I am currently trying to run a
> > collapsable query using SolrJ using SolR 3.3.
> > The problem is that when I run the query through the web
> > interface, with
> > this url:
> >
> >
> http://localhost:8080/solr/select/?q=attr_content%3Alynx&sort=attr_location+desc&group=true&group.field=attr_directory
> >
> > I am able to see the XML which is returned. The problem
> > though, is that when
> > I try to run the same query through SolrJ, using this
> > code:
> >
> >         SolrQuery queryString = new
> > SolrQuery();
> >
> >         for (String param :
> > query.keySet())
> >
> >         {
> >             if
> > (param.equals("fq"))
> >
> >             {
> >
> > queryString.addFilterQuery(query.get(param));
> >
> >             }
> >             else
> >             {
> >
> > queryString.setParam(param, query.get(param));
> >
> >             }
> >         }
> >
> >
> > System.out.println(queryString.toString());
> >
> >         QueryResponse response =
> > server.query(queryString);
> > //Exception takes place at this line
> >
> >         SolrDocumentList docList =
> > response.getResults();
> >
> > Which constructs a URL like so:
> >
> >
> q=attr_content%3Alynx&sort=attr_location+desc&group=true&group.field=attr_directory
> >
> > This throws an exception:
> >
> > Caused by: org.apache.solr.common.SolrException: parsing
> > error at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:145)
> > at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:106)
> > at
> >
> org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:477)
> > at
> >
> org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
> > at
> >
> org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
> > ... 3 more Caused by: javax.xml.stream.XMLStreamException:
> > ParseError at
> > [row,col]:[3,30088] Message: error reading value:LST at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.readArray(XMLResponseParser.java:324)
> > at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:245)
> > at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:244)
> > at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:244)
> > at
> >
> org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:130)
> >
> > I have tried it with both Jetty and Tomcat, the error is
> > the same for both.
> > I have managed to get other queries to run (with both
> > servers), so I presume
> > that the problem lies with this particular type of query.
> >
> > Any insight on this problem will be highly appreciated,
> >
> > Thanks :)
> >
>

Re: SolrJ Collapsable Query Fails

Posted by Ahmet Arslan <io...@yahoo.com>.
See the Yonik's reply : http://search-lucene.com/m/tCmky1v94D92/

In short you need to use NamedList<Object> getResponse().

> I am currently trying to run a
> collapsable query using SolrJ using SolR 3.3.
> The problem is that when I run the query through the web
> interface, with
> this url:
> 
> http://localhost:8080/solr/select/?q=attr_content%3Alynx&sort=attr_location+desc&group=true&group.field=attr_directory
> 
> I am able to see the XML which is returned. The problem
> though, is that when
> I try to run the same query through SolrJ, using this
> code:
> 
>         SolrQuery queryString = new
> SolrQuery();
> 
>         for (String param :
> query.keySet())
> 
>         {
>             if
> (param.equals("fq"))
> 
>             {
>                
> queryString.addFilterQuery(query.get(param));
> 
>             }
>             else
>             {
>                
> queryString.setParam(param, query.get(param));
> 
>             }
>         }
> 
>        
> System.out.println(queryString.toString());
> 
>         QueryResponse response =
> server.query(queryString);
> //Exception takes place at this line
> 
>         SolrDocumentList docList =
> response.getResults();
> 
> Which constructs a URL like so:
> 
> q=attr_content%3Alynx&sort=attr_location+desc&group=true&group.field=attr_directory
> 
> This throws an exception:
> 
> Caused by: org.apache.solr.common.SolrException: parsing
> error at
> org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:145)
> at
> org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:106)
> at
> org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:477)
> at
> org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:244)
> at
> org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
> ... 3 more Caused by: javax.xml.stream.XMLStreamException:
> ParseError at
> [row,col]:[3,30088] Message: error reading value:LST at
> org.apache.solr.client.solrj.impl.XMLResponseParser.readArray(XMLResponseParser.java:324)
> at
> org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:245)
> at
> org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:244)
> at
> org.apache.solr.client.solrj.impl.XMLResponseParser.readNamedList(XMLResponseParser.java:244)
> at
> org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:130)
> 
> I have tried it with both Jetty and Tomcat, the error is
> the same for both.
> I have managed to get other queries to run (with both
> servers), so I presume
> that the problem lies with this particular type of query.
> 
> Any insight on this problem will be highly appreciated,
> 
> Thanks :)
>