Created
January 13, 2014 15:12
-
-
Save BartDM/8402027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using Lucene.Net.Documents; | |
namespace LuceneWrapper | |
{ | |
/// <summary> | |
/// Abstract class as base for all Seach Documents | |
/// </summary> | |
public abstract class ADocument : IDocument | |
{ | |
private int id; | |
/// <summary> | |
/// The ID of the item | |
/// </summary> | |
[SearchField] | |
public int Id | |
{ | |
set | |
{ | |
id = value; | |
AddParameterToDocument("Id", id, Field.Store.YES, Field.Index.NOT_ANALYZED); | |
} | |
get { return id; } | |
} | |
private readonly Document document; | |
/// <summary> | |
/// The Lucene Document | |
/// </summary> | |
public Document Document { get { return document; } } | |
/// <summary> | |
/// Constructor | |
/// </summary> | |
protected ADocument() | |
{ | |
document = new Document(); | |
} | |
/// <summary> | |
/// Method to add parameters to the Lucene Document | |
/// Only parameters that are added to the Lucene document can be searched on | |
/// </summary> | |
/// <param name="name">The name of the parameter</param> | |
/// <param name="value">The value of the parameter</param> | |
/// <param name="store">The Store setting</param> | |
/// <param name="index">The Index setting</param> | |
private void AddParameterToDocument(string name, dynamic value, Field.Store store, Field.Index index) | |
{ | |
document.Add(new Field(name, value.ToString(), store, index)); | |
} | |
protected void AddParameterToDocumentStoreParameter(string name, dynamic value) | |
{ | |
AddParameterToDocument(name, value,Field.Store.YES,Field.Index.ANALYZED); | |
} | |
protected void AddParameterToDocumentNoStoreParameter(string name, dynamic value) | |
{ | |
AddParameterToDocument(name, value,Field.Store.NO,Field.Index.ANALYZED); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment