/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Collections.Specialized;
using Lucene.Net.Documents;
using NBear.Mapping;
using Everest.Library.ExtensionMethod;
namespace Everest.Search.Convertor{
internal class StandardConvertor : IDocumentConvertor
{
Type type;
public StandardConvertor(Type type)
{
this.type = type;
}
#region IDocumentConvertor Members
public Lucene.Net.Documents.Document ToDocument(object o)
{
Document document = new Document();
NameValueCollection properties = ObjectConvertor.ToObject<NameValueCollection>(o);
foreach (string key in properties.Keys)
{
document.Add(new Field(key, properties[key], Field.Store.YES, Field.Index.TOKENIZED));
}
return document;
}
public object ToObject(Lucene.Net.Documents.Document document)
{
NameValueCollection properties = new NameValueCollection();
foreach (Field field in document.GetFields())
{
if (field.IsStored())
{
properties.Add(field.Name(), document.Get(field.Name()));
}
}
object o = ObjectConvertor.ToObject(typeof(NameValueCollection), type, type, properties);
return o;
}
#endregion
#region IDocumentConvertor Members
public void SetAnalyzer(Lucene.Net.Analysis.Analyzer analyzer)
{
}
public void SetHighlighter(Lucene.Net.Highlight.Highlighter highlighter)
{
}
#endregion
}
}
|