当前位置: 动力学知识库 > 问答 > 编程问答 >

.net - How to map a SolrNet Query result to a class?

问题描述:

I am trying to query Solr using the SolrNet client.

I can index documents and search for them with the Solr web admin with out error.

When I try to query using the same class I indexed the documents with I get an error like the following on every field.

Error:

Could not convert value 'System.Collections.ArrayList' to property 'Title' of document type Search.WebService.Handler.Document

Why is Solr trying to map an arraylist to each field?

Here are the details of my setup, the schema is based on the example schema.

My Schema:

<field name="ReferenceId" type="identifier" indexed="true" stored="true" required="true"/>

<field name="Title" type="text_general" indexed="true" stored="true"/>

<field name="Revision" type="identifier" indexed="true" stored="true"/>

<field name="Author" type="text_general" indexed="true" stored="true"/>

<field name="Filename" type="text_general" indexed="true" stored="true"/>

My Document class:

class Document

{

[SolrField("ReferenceId")]

public string ReferenceId { get; set; }

[SolrField("Title")]

public string Title { get; set; }

[SolrField("Revision")]

public string Revision { get; set; }

[SolrField("Author")]

public string Author { get; set; }

[SolrField("Filename")]

public string Filename { get; set; }

}

An example query:

string queryString = String.Format("Title :\"{0}\"", titleSearchTerm);

SolrQuery query = new SolrQuery(queryString);

SolrQueryResults<Document> results = index.Query(query);

网友答案:

Added the attribute multiValued="false" to each of the fields.

More details on multiValued fields is found in the documentation.

分享给朋友:
您可能感兴趣的文章:
随机阅读: