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 Raivo Rebane <ra...@r-systems.ee> on 2020/11/05 15:08:07 UTC

getFirstValue problem with solrj

Hello

I have one problem

I made a query as foollws :

                     System.out.println("Querying by using SolrQuery...");
                     SolrQuery solrQuery = new SolrQuery("Name:" + Pattern);
                     solrQuery.addField("id");
                     solrQuery.addField("App_code");
                     solrQuery.setSort("App_code", ORDER.asc);
                     solrQuery.setRows(10);
                     QueryResponse response = null;
                     try {
                         response = 
AppServServlet.solrClientApps.query(solrQuery);
                     } catch (SolrServerException | IOException e) {
                         System.err.printf("\nFailed to search articles: 
%s", e.getMessage());
                     }

and got response as follows :

                     SolrDocumentList documents = null;
                     if (response != null) {
                             documents = response.getResults();
                             System.out.printf("Found %d documents\n", 
documents.getNumFound());
                             for (SolrDocument document : documents) {
                                 String id = (String) 
document.getFirstValue("id");
                                 String name = (String) 
document.getFirstValue("Name");
                                 long App_code1 = (long) 
document.getFirstValue("App_code");
                                 System.out.printf("id=%s, App_code=%s, 
name=%s\n", id, App_code1, name);
                             }
                      }

Found 1 document but name = (String) document.getFirstValue("Name"); 
returns null

Console looks like :

Querying by using SolrQuery...
Found 1 documents
id=0000000092, App_code=2, name=null

What is wrong ?

Please somebody helps me !

Regards

Raivo

PS. Collection is like :

0000000057 0  HIS
0000000045 1  RAN/AEGIR
0000000092 2  PIT2
*


Re: getFirstValue problem with solrj

Posted by Raivo Rebane <ra...@r-systems.ee>.
Heloo

I found mistake

Thanks

Raivo

On 05.11.20 17:08, Raivo Rebane wrote:
> Hello
>
> I have one problem
>
> I made a query as foollws :
>
>                     System.out.println("Querying by using SolrQuery...");
>                     SolrQuery solrQuery = new SolrQuery("Name:" + 
> Pattern);
>                     solrQuery.addField("id");
>                     solrQuery.addField("App_code");
>                     solrQuery.setSort("App_code", ORDER.asc);
>                     solrQuery.setRows(10);
>                     QueryResponse response = null;
>                     try {
>                         response = 
> AppServServlet.solrClientApps.query(solrQuery);
>                     } catch (SolrServerException | IOException e) {
>                         System.err.printf("\nFailed to search 
> articles: %s", e.getMessage());
>                     }
>
> and got response as follows :
>
>                     SolrDocumentList documents = null;
>                     if (response != null) {
>                             documents = response.getResults();
>                             System.out.printf("Found %d documents\n", 
> documents.getNumFound());
>                             for (SolrDocument document : documents) {
>                                 String id = (String) 
> document.getFirstValue("id");
>                                 String name = (String) 
> document.getFirstValue("Name");
>                                 long App_code1 = (long) 
> document.getFirstValue("App_code");
>                                 System.out.printf("id=%s, App_code=%s, 
> name=%s\n", id, App_code1, name);
>                             }
>                      }
>
> Found 1 document but name = (String) document.getFirstValue("Name"); 
> returns null
>
> Console looks like :
>
> Querying by using SolrQuery...
> Found 1 documents
> id=0000000092, App_code=2, name=null
>
> What is wrong ?
>
> Please somebody helps me !
>
> Regards
>
> Raivo
>
> PS. Collection is like :
>
> 0000000057 0  HIS
> 0000000045 1  RAN/AEGIR
> 0000000092 2  PIT2
> *
>