private static string[] getLuceneSearchEOFields() { LuceneSearchEO obj = new LuceneSearchEO(); PropertyInfo[] props = obj.GetType().GetProperties(); return props.Select(a => a.Name).ToArray(); }
private static LuceneSearchEO _mapLuceneDocumentToData(Document doc) { LuceneSearchEO obj = new LuceneSearchEO(); PropertyInfo[] props = obj.GetType().GetProperties(); foreach (var prop in props) { if (obj.GetType().GetProperty(prop.Name).PropertyType.FullName == "System.Guid") obj.GetType().GetProperty(prop.Name).SetValue(obj, Guid.Parse(doc.Get(prop.Name))); else obj.GetType().GetProperty(prop.Name).SetValue(obj, doc.Get(prop.Name)); } return obj; }
public static void ClearLuceneIndexRecord(LuceneSearchType searchType, int record_id) { // init lucene var analyzer = new StandardAnalyzer(Version.LUCENE_30); using (var writer = new IndexWriter(getFSDirectory(searchType), analyzer, IndexWriter.MaxFieldLength.UNLIMITED)) { LuceneSearchEO LuceneSearchEO = new LuceneSearchEO(); PropertyInfo[] props = LuceneSearchEO.GetType().GetProperties(); foreach (var prop in props) { Attribute att = prop.GetCustomAttribute(typeof(LuceneTypeAttribute)); LuceneTypeAttribute luceneAtt = (LuceneTypeAttribute)att; if (luceneAtt != null && luceneAtt.Key) { // remove older index entry var searchQuery = new TermQuery(new Term(prop.Name, record_id.ToString())); writer.DeleteDocuments(searchQuery); } } // close handles analyzer.Close(); writer.Dispose(); } }
private static void _addToLuceneIndex(LuceneSearchEO LuceneSearchEO, IndexWriter writer) { PropertyInfo[] props = LuceneSearchEO.GetType().GetProperties(); foreach (var prop in props) { Attribute att = prop.GetCustomAttribute(typeof(LuceneTypeAttribute)); LuceneTypeAttribute luceneAtt = (LuceneTypeAttribute)att; if (luceneAtt != null && luceneAtt.Key) { // remove older index entry var searchQuery = new TermQuery(new Term(prop.Name, prop.GetValue(LuceneSearchEO).ToString())); writer.DeleteDocuments(searchQuery); } } // add new index entry var doc = new Document(); // add lucene fields mapped to db fields foreach (var prop in props) { Attribute att = prop.GetCustomAttribute(typeof(LuceneTypeAttribute)); LuceneTypeAttribute luceneAtt = (LuceneTypeAttribute)att; if (luceneAtt != null) { string value = string.Empty; if (luceneAtt.Key) doc.Add(new Field(prop.Name, prop.GetValue(LuceneSearchEO).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); else { value = Convert.ToString(LuceneSearchEO.GetType().GetProperty(prop.Name).GetValue(LuceneSearchEO)); doc.Add(new Field(prop.Name, value, Field.Store.YES, Field.Index.ANALYZED)); } } } // add entry to index writer.AddDocument(doc); }
public static void AddUpdateLuceneIndex(LuceneSearchType searchType, LuceneSearchEO LuceneSearchEO) { AddUpdateLuceneIndex(searchType, new List<LuceneSearchEO> { LuceneSearchEO }); }