You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by huda barakat <en...@gmail.com> on 2016/11/24 09:42:43 UTC
term frequency
I'm using SOLRJ to find term frequency for each term in a field, I wrote
this code but it is not working:
1. String urlString = "http://localhost:8983/solr/huda";
2. SolrClient solr = new HttpSolrClient.Builder(urlString).build();
3.
4. SolrQuery query = new SolrQuery();
5. query.setTerms(true);
6. query.addTermsField("name");
7. SolrRequest<QueryResponse> req = new QueryRequest(query);
8. QueryResponse rsp = req.process(solr);
9.
10. System.out.println(rsp);
11.
12. System.out.println("numFound: " +
rsp.getResults().getNumFound());
13.
14. TermsResponse termResp =rsp.getTermsResponse();
15. List<TermsResponse.Term> terms = termResp.getTerms("name");
16. System.out.print(terms.size());
I got this error:
Exception in thread "main" java.lang.NullPointerException at
solr_test.solr.App2.main(App2.java:50)
Re: term frequency
Posted by huda barakat <en...@gmail.com>.
This the error I get it is the same:
Exception in thread "main" java.lang.NullPointerException
at solr_test.solr.SolrJTermsApplication.main(SolrJTermsApplication.java:30)
I know the object is null but I don't know why it is null??
when I change the query to this:
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
SolrRequest<QueryResponse> req = new QueryRequest(query);
QueryResponse rsp = req.process(solr);
System.out.println("numFound: " +
rsp.getResults().getNumFound());
I get results but the problem I want to get term frequency in the field
"name" how can I do that???
Thank you!
On 24 November 2016 at 16:27, Jason Wee <pe...@gmail.com> wrote:
> the exception line does not match the code you pasted, but do make
> sure your object actually not null before accessing its method.
>
> On Thu, Nov 24, 2016 at 5:42 PM, huda barakat
> <en...@gmail.com> wrote:
> > I'm using SOLRJ to find term frequency for each term in a field, I wrote
> > this code but it is not working:
> >
> >
> > 1. String urlString = "http://localhost:8983/solr/huda";
> > 2. SolrClient solr = new HttpSolrClient.Builder(
> urlString).build();
> > 3.
> > 4. SolrQuery query = new SolrQuery();
> > 5. query.setTerms(true);
> > 6. query.addTermsField("name");
> > 7. SolrRequest<QueryResponse> req = new QueryRequest(query);
> > 8. QueryResponse rsp = req.process(solr);
> > 9.
> > 10. System.out.println(rsp);
> > 11.
> > 12. System.out.println("numFound: " +
> > rsp.getResults().getNumFound());
> > 13.
> > 14. TermsResponse termResp =rsp.getTermsResponse();
> > 15. List<TermsResponse.Term> terms =
> termResp.getTerms("name");
> > 16. System.out.print(terms.size());
> >
> >
> > I got this error:
> >
> > Exception in thread "main" java.lang.NullPointerException at
> > solr_test.solr.App2.main(App2.java:50)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: term frequency
Posted by Jason Wee <pe...@gmail.com>.
the exception line does not match the code you pasted, but do make
sure your object actually not null before accessing its method.
On Thu, Nov 24, 2016 at 5:42 PM, huda barakat
<en...@gmail.com> wrote:
> I'm using SOLRJ to find term frequency for each term in a field, I wrote
> this code but it is not working:
>
>
> 1. String urlString = "http://localhost:8983/solr/huda";
> 2. SolrClient solr = new HttpSolrClient.Builder(urlString).build();
> 3.
> 4. SolrQuery query = new SolrQuery();
> 5. query.setTerms(true);
> 6. query.addTermsField("name");
> 7. SolrRequest<QueryResponse> req = new QueryRequest(query);
> 8. QueryResponse rsp = req.process(solr);
> 9.
> 10. System.out.println(rsp);
> 11.
> 12. System.out.println("numFound: " +
> rsp.getResults().getNumFound());
> 13.
> 14. TermsResponse termResp =rsp.getTermsResponse();
> 15. List<TermsResponse.Term> terms = termResp.getTerms("name");
> 16. System.out.print(terms.size());
>
>
> I got this error:
>
> Exception in thread "main" java.lang.NullPointerException at
> solr_test.solr.App2.main(App2.java:50)
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org