Linq to Lucene error: "Classes must define at least one field as a default search field"
I have the following attributes applied to my linq to sql class:
[Document(MetadataType = typeof(SomeObjectMetadata))]
public partial class SomeObject
{
}
And this is the metadata code:
public class SomeObjectMetadata
{
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsKey = true)]
private object ProductId { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsDefault = true)]
private object Name { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Description { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Breadcrumb { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab1Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab2Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab3Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab4Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Tab5Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
private object Manufacturer { get; set; }
}
The index store writes just fine, but when I try to search it, I get the error shown in the title. Here's an example search:
var qry = from r in _dbi.Get<SomeOb开发者_运维技巧ject>()
where r.Description.Like(search)
select r;
Upon enumerating "qry", the Exception "Classes must define at least one field as a default search field" is thrown.
Wow, I'm an idiot. The metadata fields were private. This fixes it, of course:
public class Catalog_ProductMetadata
{
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsKey = true)]
public object ProductId { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes, IsDefault = true)]
public object Name { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Description { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Breadcrumb { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab1Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab2Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab3Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab4Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Tab5Content { get; set; }
[Field(FieldIndex.Tokenized, FieldStore.Yes)]
public object Manufacturer { get; set; }
}
精彩评论