How to search the multiple fields in SolrNet

1,012 views
Skip to first unread message

MrBurn

unread,
Jun 27, 2011, 5:53:52 PM6/27/11
to SolrNet
I am trying to do the search but I got stumble as there are no example
in the web showing how to run the search on multiple fields.

Here is my schema:

<fields>
<field name="RID" type="string" indexed="true" stored="true"
required="true" />
<field name="Name" type="text" indexed="true" stored="true"
required="false" />
<field name="Address" type="text" indexed="true" stored="true"
required="false" />
<field name="Style" type="text" indexed="true" stored="true"
required="false" />

<field name="DID" type="string" indexed="true" stored="true"
required="true" />
<field name="Title" type="text" indexed="true" stored="true"
required="false" />
<field name="Description" type="text" indexed="true"
stored="true" multiValued="true" required="false" />
<field name="WordSearch" type="text" indexed="true"
stored="true" required="false" />

<field name="textSearch" type="text" indexed="true"
stored="false" required="false" multiValued="true"/>
</fields>

<uniqueKey>DID</uniqueKey>
<defaultSearchField>textSearch</defaultSearchField>
<solrQueryParser defaultOperator="OR" />

<copyField source="Name" dest="textSearch"/>
<copyField source="Style" dest="textSearch"/>
<copyField source="Title" dest="textSearch"/>
<copyField source="Description" dest="textSearch"/>
<copyField source="WordSearch" dest="textSearch"/>

Here is the part of my test app:

public class Review
{
/* attribute decorations tell solrnet how to map
the properties to Solr fields. */
[SolrUniqueKey("RID")]
public string RID { get; set; }

[SolrField("Name")]
public string Name { get; set; }

[SolrField("Address")]
public string Address { get; set; }

[SolrField("Style")]
public string Style { get; set; }

[SolrUniqueKey("DID")]
public string DID { get; set; }

[SolrField("Title")]
public string Title { get; set; }

[SolrField("Description")]
public string Description { get; set; }

[SolrField("WordSearch")]
public string WordSearch { get; set; }

[SolrField("textSearch")]
public string textSearch { get; set; }

}

static void Main(string[] args)
{
/* create a session */
Startup.Init<Review>("http://localhost:8080/solr");
ISolrOperations<Review> solr =

ServiceLocator.Current.GetInstance<ISolrOperations<Review>>();
/* issue a lucene query */
ICollection<Review> results = solr.Query("Solr");


foreach (Review r in results)
{
Console.WriteLine(r.Name);
}
Console.Read();
}

I am not sure why but I either got nothing in return when it suppose
to have around 59 records or I got this crazy error message

"Object of type 'System.Collections.ArrayList' cannot be converted to
type 'System.String'."

I saw an example here:

http://surinder.computing-studio.com/post/2010/12/13/Multi-Query-Search-Using-LuceneNET.aspx

But in this example on line 80 they use:

Analyzer analyzer = new StandardAnalyzer();

//Search by multiple fields
MultiFieldQueryParser parser = new MultiFieldQueryParser

how do I use these fields in SolrNet?

Thanks

Briggs Thompson

unread,
Jun 27, 2011, 6:50:13 PM6/27/11
to sol...@googlegroups.com
I think the issue is that you are trying to cast your description field to a string. Your schema says description is multi-valued, so you need to cast it to an array list (as the error suggests). 

Try changing the following in your review class:

       [SolrField("Description")]
       public string Description { get; set; }

to 
       [SolrField("Description")]
       public ArrayList Description { get; set; }


-Briggs


--
You received this message because you are subscribed to the Google Groups "SolrNet" group.
To post to this group, send email to sol...@googlegroups.com.
To unsubscribe from this group, send email to solrnet+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/solrnet?hl=en.


MrBurn

unread,
Jun 27, 2011, 10:15:15 PM6/27/11
to SolrNet
Thank you very much. It works now.

One more question, how can I restrict how many records return from the
search?

Here is what I want to establish:

Name1
1. Title A 2. Title B 3. Title C

Even the search bring up Name1 with 10 Titles

Thank you very much

On Jun 27, 6:50 pm, Briggs Thompson <w.briggs.thomp...@gmail.com>
wrote:
> >http://surinder.computing-studio.com/post/2010/12/13/Multi-Query-Sear...

Mauricio Scheffer

unread,
Jun 28, 2011, 8:41:06 AM6/28/11
to sol...@googlegroups.com
Use QueryOptions.Start/Rows for pagination. See http://code.google.com/p/solrnet/wiki/Querying#Pagination for reference.

--
Mauricio

MrBurn

unread,
Jun 28, 2011, 1:03:02 PM6/28/11
to SolrNet
Thank you very much,

But that paging won't work well with what I am trying to do. Basically
the search will have the results of multiple Names and titles. Here's
what I am trying to do.
Name1
1. Title A 2. Title B 3. Title C
Name2
1. Title D 2. Title E 3. Title F
...

NameN
1. TitleX 2.TitleY TitleZ

sorry for the confusion.

Thank you very much.

On Jun 28, 8:41 am, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> Use QueryOptions.Start/Rows for pagination. Seehttp://code.google.com/p/solrnet/wiki/Querying#Paginationfor reference.

Mauricio Scheffer

unread,
Jun 28, 2011, 1:23:23 PM6/28/11
to sol...@googlegroups.com

MrBurn

unread,
Jun 28, 2011, 1:44:42 PM6/28/11
to SolrNet
thank you very much, I will give it a try.

On Jun 28, 1:23 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> It seems you want to group documents by name. If that's the case see:http://wiki.apache.org/solr/FieldCollapsinghttps://github.com/mausch/SolrNet/blob/master/SolrNet.Tests/Integrati...
Reply all
Reply to author
Forward
0 new messages