/// <summary> /// Indexing the entity /// </summary> /// <param name="doc">Lucene document</param> /// <param name="lce">Entity to index(annotations are used for indexing)</param> internal override void Indexing(Document doc, T lce) { Type leType = lce.GetType(); var properties = leType.GetProperties(); foreach (PropertyInfo pi in properties) { LuceneAnalysis attranalysis = MetaFinder.PropertyLuceneInfo <LuceneAnalysis>(pi); LuceneField fieldanalysis = MetaFinder.PropertyLuceneInfo <LuceneField>(pi); LuceneNoIndex noindex = MetaFinder.PropertyLuceneInfo <LuceneNoIndex>(pi); LuceneGeoIndex geoIndex = MetaFinder.PropertyLuceneInfo <LuceneGeoIndex>(pi); object pov = pi.GetValue(lce); ParrotConvertor value = lce.LuceneConvert(pov); if (noindex == null) { string fieldName = (attranalysis != null) ? attranalysis.Name : (fieldanalysis != null) ? fieldanalysis.Name : pi.Name; if (value.IsSpatial) { //set strategy for only one field if (geoIndex != null) { AddLocation(doc, value.Phi.Value, value.Lamda.Value); } doc.Add(new StringField(fieldName, $"{value.Phi};{value.Lamda}", Field.Store.YES)); } else { if (attranalysis != null) { StoreFieldData(doc, attranalysis.Name, pi.PropertyType, pov, value.Conversion); doc.Add(new TextField(attranalysis.AnalysisName, value.Conversion, Field.Store.YES)); } else { StoreFieldData(doc, fieldName, pi.PropertyType, pov, value.Conversion); } } } } }
/// <summary> /// Maps the document data into the entity /// </summary> /// <param name="doc">Lucene document</param> /// <param name="args">Spatial Arguments</param> /// <param name="score">Lucene score</param> /// <returns>The Mapped Entity T</returns> internal override T MapDocToData(Document doc, SpatialArgs args = null, float?score = null) { T lce = Activator.CreateInstance <T>(); if (args != null) { lce.Distance = DocumentDistance(doc, args); } Type leType = lce.GetType(); var properties = leType.GetProperties(); foreach (PropertyInfo pi in properties) { LuceneNoIndex noindex = MetaFinder.PropertyLuceneInfo <LuceneNoIndex>(pi); if (noindex != null) { continue; } LuceneAnalysis analysedField = MetaFinder.PropertyLuceneInfo <LuceneAnalysis>(pi); LuceneField storedField = MetaFinder.PropertyLuceneInfo <LuceneField>(pi); //first we get the analysed field the stored data located in named attribute //when the we have a non analysed field we check the stored field defined name else the name is the property name string fieldName = (analysedField != null) ? analysedField.Name : (storedField != null) ? storedField.Name : pi.Name; object value = null; string svalue; if (pi.PropertyType == typeof(GeoCoordinate)) { svalue = doc.Get($"{fieldName}"); var coords = svalue.Split(new char[] { ';' }); if (coords.Length > 1) { value = new GeoCoordinate() { Latitude = ParrotBeak.StringToDouble(coords[0]), Longitude = ParrotBeak.StringToDouble(coords[1]) }; } else { value = new GeoCoordinate(); } } else { svalue = doc.Get(fieldName); if (!string.IsNullOrEmpty(svalue)) { if (pi.PropertyType == typeof(string)) { value = svalue; } else if (pi.PropertyType == typeof(DateTime)) { value = ParrotBeak.DateDeserialize(svalue); } else if (pi.PropertyType == typeof(byte)) { value = ParrotBeak.StringToByte(svalue); } else if (pi.PropertyType == typeof(short)) { value = ParrotBeak.StringToShort(svalue); } else if (pi.PropertyType == typeof(int)) { value = ParrotBeak.StringToInt(svalue); } else if (pi.PropertyType == typeof(long)) { value = ParrotBeak.StringToLong(svalue); } else if (pi.PropertyType == typeof(ushort)) { value = ParrotBeak.StringToUShort(svalue); } else if (pi.PropertyType == typeof(uint)) { value = ParrotBeak.StringToUInt(svalue); } else if (pi.PropertyType == typeof(ulong)) { value = ParrotBeak.StringToULong(svalue); } else if (pi.PropertyType == typeof(float)) { value = ParrotBeak.StringToFloat(svalue); } else if (pi.PropertyType == typeof(double)) { value = ParrotBeak.StringToDouble(svalue); } else if (pi.PropertyType == typeof(decimal)) { value = ParrotBeak.StringToDecimal(svalue); } else if (pi.PropertyType == typeof(ParrotId)) { value = (ParrotId)svalue; } else { value = JsonConvert.DeserializeObject(svalue); } } } if (value != null) { if (pi.CanWrite) { pi.SetValue(lce, value); } } } return(lce); }