internal SearchTerm(string field, DateTime dFrom, DateTime dTo, Occur toccur = Occur.MUST) { Field = field; From = ParrotBeak.DateSerialize(dFrom); To = ParrotBeak.DateSerialize(dTo); TermOccur = toccur; SearchingOption = SearchFieldOption.INTRANGE; }
/// <summary> /// Converts the object value into a text or spatial data suitable for storing into the lucene index /// Override in order to include custom attributes /// </summary> /// <param name="value">The object value</param> /// <returns>The converted data of the object value</returns> public virtual ParrotConvertor LuceneConvert(object value) { string converted = ""; double?phi = null; double?lamda = null; if (value != null) { if (value.GetType() == typeof(DateTime)) { converted = ParrotBeak.DateSerialize((DateTime)value); } else if (value.GetType() == typeof(ParrotId)) { converted = ((ParrotId)value).ToString(CultureInfo.InvariantCulture); } else if (value.GetType() == typeof(string)) { converted = Convert.ToString(value); } //else if (value.GetType() == typeof(decimal)) //{ // converted = ParrotBeak.DecimalSerialize(((decimal)value)); //} else if (value.GetType() == typeof(float) || value.GetType() == typeof(double) || value.GetType() == typeof(short) || value.GetType() == typeof(int) || value.GetType() == typeof(byte) || value.GetType() == typeof(long) || value.GetType() == typeof(ushort) || value.GetType() == typeof(uint) || value.GetType() == typeof(ulong) || value.GetType() == typeof(decimal)) { converted = null;// ((ulong)value).ToString(CultureInfo.InvariantCulture; } else if (value.GetType() == typeof(GeoCoordinate)) { var point = (GeoCoordinate)value; phi = point.Latitude; lamda = point.Longitude; } else { //unknown data in order to be analysed user should override converted = JsonConvert.SerializeObject(value); } } return(new ParrotConvertor() { Conversion = converted, Lamda = lamda, Phi = phi }); }
internal int Pages(int ResultsPerPage) { int count = Searcher.IndexReader.NumDocs;; return(ParrotBeak.PagesCount(ResultsPerPage, count)); }
/// <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); }