SOLRJ - Searching text in all fields of a Bean

2010-10-08 Thread Subhash Bhushan
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 solrTitles = new
ArrayList();
Iterator 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 beans = rsp.getBeans(SOLRTitle.class);
System.out.println(beans.size());
Iterator 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.


Re: SOLRJ - Searching text in all fields of a Bean

2010-10-15 Thread Subhash Bhushan
Ahmet,

I got it working to an extent.

Now:
SolrQuery query = new SolrQuery();
query.setQueryType("dismax");
query.setQuery( "kitten");
query.setParam("qf", "title");


QueryResponse rsp = server.query( query );
List beans = rsp.getBeans(SOLRTitle.class);
System.out.println(beans.size());
Iterator it = beans.iterator();
while(it.hasNext()) {
SOLRTitle solrTitle = (SOLRTitle)it.next();
System.out.println(solrTitle.id);
System.out.println(solrTitle.title);
}

*This code is able to find the record, and prints the ID. But fails to print
the Title.*

Whereas:
SolrQuery query = new SolrQuery();
query.setQuery( "title:kitten" );

QueryResponse rsp = server.query( query );
SolrDocumentList docs = rsp.getResults();

Iterator iter = rsp.getResults().iterator();

while (iter.hasNext()) {
  SolrDocument resultDoc = iter.next();

  String title = (String) resultDoc.getFieldValue("
title");
  String id = (String) resultDoc.getFieldValue("id"); //id is
the uniqueKey field
  System.out.println(id);
  System.out.println(title);
}
*
This query succeeds!*

What am I doing wrong in dismax params? The title field is being fetched as
Null.

Regards,
Subhash Bhushan.


On Fri, Oct 8, 2010 at 2:05 PM, Ahmet Arslan  wrote:

> > 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?
>
> With dismax, you can query several fields using different boosts.
> http://wiki.apache.org/solr/DisMaxQParserPlugin
>
>
>
>
>


Re: SOLRJ - Searching text in all fields of a Bean

2010-10-15 Thread Subhash Bhushan
Hi Savvas,

Thanks!! Was able to search using  directive.

I was using the default example schema packaged with solr. I added the
following directive for title field and reindexed data:
**

Regards,
Subhash Bhushan.

On Fri, Oct 8, 2010 at 2:09 PM, Savvas-Andreas Moysidis <
savvas.andreas.moysi...@googlemail.com> wrote:

> Hello,
>
> What does your schema look like? Have you defined a  "catch all" field and
> copy every value from all your other fields in it with a 
> directive?
>
> Cheers,
> -- Savvas
>
>
> On 8 October 2010 08:30, Subhash Bhushan wrote:
>
>> 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 solrTitles = new
>> ArrayList();
>> Iterator 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 beans = rsp.getBeans(SOLRTitle.class);
>>System.out.println(beans.size());
>>Iterator 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.
>>
>
>