|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Lucene.Net.Documents;
namespace Raven.Database.Indexing
{
public class AnonymousObjectToLuceneDocumentConverter
{
public IEnumerable<Field> Index(object val, PropertyDescriptorCollection properties, IndexDefinition indexDefinition)
{
return (from property in properties.Cast<PropertyDescriptor>()
let name = property.Name
where name != "__document_id"
let value = property.GetValue(val)
where value != null
select new Field(name, ToIndexableString(value, indexDefinition.GetIndex(name)), indexDefinition.GetStorage(name), indexDefinition.GetIndex(name)));
}
private static string ToIndexableString(object val, Field.Index indexOptions)
{
if (indexOptions == Field.Index.UN_TOKENIZED)
return val.ToString();
if (val is DateTime)
return DateTools.DateToString((DateTime) val, DateTools.Resolution.DAY);
if (val is int)
return NumberTools.LongToString((int) val);
if (val is long)
return NumberTools.LongToString((long) val);
return val.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've been a software developer since 1996 and have enjoyed C# since 2003. I have a Bachelor's degree in Computer Science and for some reason, a Master's degree in Business Administration. I currently do software development contracting/consulting.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.