Hi,
I have two fields in the bean class, id and title.
After adding the bean to SOLR, I want to search for, say "kitten", in all
defined fields in the bean, like this -- query.setQuery( "kitten"); --
But I get results only when I affix the bean field name before the search
text like this -- query.setQuery( "title:kitten"); --
Same case even when I use SolrInputDocument, and add these fields.
Can we search text in all fields of a bean, without having to specify a
field?
If we can, what am I missing in my code?
*Code:*
Bean:
-----------------------------------
public class SOLRTitle {
@Field
public String id = "";
@Field
public String title = "";
}
-----------------------------------
Indexing function:
-----------------------------------
private static void uploadData() {
try {
... // Get Titles
List<SOLRTitle> solrTitles = new
ArrayList<SOLRTitle>();
Iterator<Title> it = titles.iterator();
while(it.hasNext()) {
Title title = (Title) it.next();
SOLRTitle solrTitle = new SOLRTitle();
solrTitle.id = title.getID().toString();
solrTitle.title = title.getTitle();
solrTitles.add(solrTitle);
}
server.addBeans(solrTitles);
server.commit();
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
-----------------------------------
Querying function:
-----------------------------------
private static void queryData() {
try {
SolrQuery query = new SolrQuery();
query.setQuery( "kitten");
QueryResponse rsp = server.query( query );
List<SOLRTitle> beans = rsp.getBeans(SOLRTitle.class);
System.out.println(beans.size());
Iterator<SOLRTitle> it = beans.iterator();
while(it.hasNext()) {
SOLRTitle solrTitle = (SOLRTitle)it.next();
System.out.println(solrTitle.id);
System.out.println(solrTitle.title);
}
} catch (SolrServerException e) {
e.printStackTrace();
}
}
--------------------------------------
Subhash Bhushan.