internal FieldBase ToField(ModuleJson module, string name, string description, ModuleOffset offset) { return(Type switch { "boolean" => new BooleanField(null, BuildCommon(1), NumericCodec.Range8, GetDefaultValue()), "boolean32" => new BooleanField(null, BuildCommon(4), NumericCodec.Range32, GetDefaultValue()), string ph when ph.StartsWith("placeholder") => new PlaceholderField(null, BuildCommon(int.Parse(ph.Substring("placeholder".Length)) / 8)), "enum" => BuildEnumField(NumericCodec.Range8), "enum16" => BuildEnumField(NumericCodec.Range16), "enum24" => BuildEnumField(NumericCodec.Full24), "enum32" => BuildEnumField(NumericCodec.Range32), "instrument" => new InstrumentField(null, BuildCommon(4), BankOffset is null ? (ModuleOffset?)null : ModuleOffset.FromDisplayValue(BankOffset.Value)), "midi32" => new NumericField(null, BuildCommon(4), 0, 128, Default ?? 0, NumericCodec.Range32, null, null, null, null, (128, "Off")), "overlay" => BuildOverlay(), "range8" => BuildNumericField(NumericCodec.Range8), "range16" => BuildNumericField(NumericCodec.Range16), "urange16" => BuildNumericField(NumericCodec.URange16), "range32" => BuildNumericField(NumericCodec.Range32), "string" => BuildStringField(1), "string16" => BuildStringField(2), "tempo" => BuildTempoField(), "volume32" => new NumericField(null, BuildCommon(4), -601, 60, 0, NumericCodec.Range32, 10, null, 0, "dB", (-601, "-INF")), "fixme_enum32" => BuildEnumField(NumericCodec.Fixme32), "fixme_range32" => BuildNumericField(NumericCodec.Fixme32), "fixme_boolean32" => new BooleanField(null, BuildCommon(4), NumericCodec.Fixme32, GetDefaultValue()), _ => throw new InvalidOperationException($"Invalid field type: '{Type}'") });
private IField ToField(ModuleSchema schema, ModuleJson module, string name, int offset, string description, FieldCondition?condition) { // TODO: Validate that we don't have "extra" parameters? return(Type switch { "boolean" => (IField) new BooleanField(BuildCommon(1)), "boolean32" => new BooleanField(BuildCommon(4)), "range8" => BuildNumericField(1), "range16" => BuildNumericField(2), "range32" => BuildNumericField(4), "enum" => BuildEnumField(1), "enum16" => BuildEnumField(2), "enum32" => BuildEnumField(4), "dynamicOverlay" => BuildDynamicOverlay(), "instrument" => new InstrumentField(BuildCommon(4), ValidateNotNull(BankOffset, nameof(BankOffset)).Value, ValidateNotNull(VeditOffset, nameof(VeditOffset)).Value), "musicalNote" => new EnumField(BuildCommon(4), MusicalNoteValues, 0, 0), "volume32" => new NumericField(BuildCommon(4), -601, 60, 0, 10, null, 0, "dB", (-601, "-INF")), "string" => BuildStringField(1), "string16" => BuildStringField(2), "midi32" => new MidiNoteField(BuildCommon(4)), string text when text.StartsWith(ContainerPrefix) => BuildContainer(), _ => throw new InvalidOperationException($"Unknown field type: {Type}") });
private Document AnalyzerDocument(RecordInfo record) { Document doc = new Document(); doc.Add(new Field("ModuleType", record.ModuleType, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("TableName", record.TableName, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("RowId", record.RowId, Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("CollectTime", record.CollectTime.ToString("yyyy-MM-dd HH:mm:ss"), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Title", record.Title, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Body", record.Body, Field.Store.YES, Field.Index.ANALYZED)); if (record.StringTags != null && record.StringTags.Any()) { foreach (var tag in record.StringTags) { doc.Add(new Field(tag.Name, tag.Value, tag.Store, tag.Index)); } } if (record.FloatTags != null && record.FloatTags.Any()) { foreach (var tag in record.FloatTags) { NumericField field = new NumericField(tag.Name, tag.Store, tag.Index != Field.Index.NO); field = field.SetFloatValue(tag.Value); doc.Add(field); } } return(doc); }
private static AbstractField CreateField(IndexFieldInfo fieldInfo) { NumericField nf; switch (fieldInfo.Type) { case FieldInfoType.StringField: return(new Field(fieldInfo.Name, fieldInfo.Value, fieldInfo.Store, fieldInfo.Index, fieldInfo.TermVector)); case FieldInfoType.IntField: nf = new NumericField(fieldInfo.Name, fieldInfo.Store, fieldInfo.Index != Field.Index.NO); nf.SetIntValue(Int32.Parse(fieldInfo.Value, CultureInfo.InvariantCulture)); return(nf); case FieldInfoType.LongField: nf = new NumericField(fieldInfo.Name, 8, fieldInfo.Store, fieldInfo.Index != Field.Index.NO); nf.SetLongValue(Int64.Parse(fieldInfo.Value, CultureInfo.InvariantCulture)); return(nf); case FieldInfoType.SingleField: nf = new NumericField(fieldInfo.Name, fieldInfo.Store, fieldInfo.Index != Field.Index.NO); nf.SetFloatValue(Single.Parse(fieldInfo.Value, CultureInfo.InvariantCulture)); return(nf); case FieldInfoType.DoubleField: nf = new NumericField(fieldInfo.Name, 8, fieldInfo.Store, fieldInfo.Index != Field.Index.NO); nf.SetDoubleValue(Double.Parse(fieldInfo.Value, CultureInfo.InvariantCulture)); return(nf); default: throw new NotImplementedException("IndexFieldInfo." + fieldInfo.Type); } }
public void FillDocument(Song song, Document doc) { if (!string.IsNullOrWhiteSpace(song.RelativePath)) { doc.Add(new Field(nameof(song.RelativePath), song.RelativePath, Field.Store.YES, Field.Index.ANALYZED)); } if (!string.IsNullOrWhiteSpace(song.Name)) { doc.Add(new Field(nameof(song.Name), song.Name, Field.Store.YES, Field.Index.ANALYZED)); } if (!string.IsNullOrWhiteSpace(song.Artist)) { doc.Add(new Field(nameof(song.Artist), song.Artist, Field.Store.YES, Field.Index.ANALYZED)); } var fieldFileLenght = new NumericField(nameof(song.FileLength), Field.Store.YES, false); fieldFileLenght.SetIntValue(song.FileLength); doc.Add(fieldFileLenght); var fieldLenght = new NumericField(nameof(song.Length), Field.Store.YES, false); fieldLenght.SetIntValue((int)song.Length.TotalMilliseconds); doc.Add(fieldLenght); doc.Add(new Field(nameof(song.LastModified), DateTools.DateToString(song.LastModified, DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.NOT_ANALYZED)); }
private static void SetLocationAsDoubleField(Examine.LuceneEngine.DocumentWritingEventArgs e) { //Get existing field - some members may not have a valueset - so check in case //Oddly some members only have one field set?! if (e.Fields.ContainsKey("latitude") == false || e.Fields.ContainsKey("longitude") == false) { return; } var existingLatField = e.Document.GetField("latitude"); var existingLonField = e.Document.GetField("longitude"); //More sanity checking if (existingLatField != null && existingLonField != null) { try { var latitude = Convert.ToDouble(existingLatField.StringValue()); var longitude = Convert.ToDouble(existingLonField.StringValue()); var latNumnber = new NumericField("latitudeNumber", Field.Store.YES, true).SetDoubleValue(latitude); var lonNumnber = new NumericField("longitudeNumber", Field.Store.YES, true).SetDoubleValue(longitude); e.Document.Add(latNumnber); e.Document.Add(lonNumnber); } catch (Exception ex) { var message = $"Unable to cast lat or lon to a double. Attempted to convert Lat:'{existingLatField.StringValue()}' Lon:'{existingLonField.StringValue()}' for Member ID: '{e.NodeId}'"; LogHelper.Error <MapEventHandler>(message, ex); } } }
private void AddFakeDocument(int fromNodeId) { //minimal fakeobject: NodeId, VersionId, Path, Version, NodeTimestamp, VersionTimestamp var node = Node.LoadNode(fromNodeId); var doc = IndexDocumentInfo.CreateDocument(node); doc.RemoveField(LucObject.FieldName.NodeId); doc.RemoveField(LucObject.FieldName.VersionId); doc.RemoveField(LucObject.FieldName.Name); doc.RemoveField(LucObject.FieldName.Path); var nf = new NumericField(LucObject.FieldName.NodeId, LucField.Store.YES, true); nf.SetIntValue(99999); doc.Add(nf); nf = new NumericField(LucObject.FieldName.VersionId, LucField.Store.YES, true); nf.SetIntValue(99999); doc.Add(nf); doc.Add(new LucField(LucObject.FieldName.Name, "fakedocument", LucField.Store.YES, LucField.Index.NOT_ANALYZED, LucField.TermVector.NO)); doc.Add(new LucField(LucObject.FieldName.Path, "/root/fakedocument", LucField.Store.YES, LucField.Index.NOT_ANALYZED, LucField.TermVector.NO)); LuceneManager.AddCompleteDocument(doc, 0, false); LuceneManager.UnregisterActivity(0, false); }
static void IndexItems(List <Product> list) { Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo(@"D:\Index")); IndexWriter indexWriter = new IndexWriter( directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.LIMITED); foreach (Product product in list) { Document doc = new Document(); Field productName = new Field("ProductName", product.ProductName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO); doc.Add(productName); NumericField price = new NumericField("Price", Field.Store.YES, true); price.SetIntValue(product.Price); doc.Add(price); indexWriter.AddDocument(doc); } indexWriter.Optimize(); indexWriter.Commit(); }
internal static NumericField SetValue(this NumericField field, ValueType value) { if (value.GetType().IsEnum) { value = (ValueType)Convert.ChangeType(value, Enum.GetUnderlyingType(value.GetType())); } if (value is int) { return(field.SetIntValue((int)value)); } if (value is long) { return(field.SetLongValue((long)value)); } if (value is double) { return(field.SetDoubleValue((double)value)); } if (value is float) { return(field.SetFloatValue((float)value)); } throw new ArgumentException("Unable to store ValueType " + value.GetType() + " as NumericField.", "value"); }
private static IFieldable GetCategoryField(CategoryProductDisplayOrder order) { var numericField = new NumericField(GetCategoryFieldName(order.Category.Id), Field.Store.YES, true); numericField.SetIntValue(order.DisplayOrder); return(numericField); }
private void button1_Click(object sender, EventArgs e) { StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); Index = new RAMDirectory(); IndexWriter writer = new IndexWriter(Index, analyzer, new IndexWriter.MaxFieldLength(15)); foreach (var book in Books) { var doc = new Document(); var bookId = new NumericField("Id", Field.Store.YES, false); bookId.SetIntValue(book.Id); var bookTitle = new Field("Title", book.Title, Field.Store.YES, Field.Index.ANALYZED); doc.Add(bookId); doc.Add(bookTitle); foreach (var page in book.Pages) { var pageNo = new NumericField("no", Field.Store.YES, false); pageNo.SetIntValue(page.No); doc.Add(pageNo); doc.Add(new Field("Text", page.Text, Field.Store.YES, Field.Index.ANALYZED)); } writer.AddDocument(doc); } writer.Dispose(); }
/// <summary> /// /// </summary> /// <param name="docId"></param> /// <param name="rng"></param> /// <param name="ctx"></param> /// <param name="percentageWithSpatialFields">ensures that some documents are missing spatial fields. This forces the cache to use FixedBitSet rather than MatchAllBits or MatchNoBits</param> /// <returns></returns> private Document CreateRandomDoc(int docId, Random rng, SpatialContext ctx, double percentageWithSpatialFields) { var doc = new Document(); var idField = new NumericField("locationId", Field.Store.YES, true); idField.SetIntValue(docId); doc.Add(idField); if (rng.NextDouble() > percentageWithSpatialFields) { return(doc); } Point shape = ctx.MakePoint(DistanceUtils.NormLonDEG(rng.NextDouble() * 360.0), DistanceUtils.NormLatDEG(rng.NextDouble() * 180.0)); foreach (AbstractField field in _spatialStrategy.CreateIndexableFields(shape)) { doc.Add(field); } doc.Add(_spatialStrategy.CreateStoredField(shape)); return(doc); }
/// <summary> /// Recursively tokenize the object into fields whose names are available via dot notation. /// </summary> /// <param name="obj"></param> /// <param name="prefix"></param> /// <param name="dictionary"></param> private static void TokenizeObject(JObject obj, string prefix, ref Dictionary <string, AbstractField> dictionary) { if (obj == null) { return; } //TODO: Add property-based ("$propertyName") conventions that allow the parameters to be customized. foreach (var property in obj.Properties().Where(p => p.Value != null)) { var fieldName = String.IsNullOrEmpty(prefix) ? property.Name : prefix + "." + property.Name; switch (property.Value.Type) { case JTokenType.Date: var dateString = DateTools.DateToString((DateTime)property.Value, DateTools.Resolution.MILLISECOND); var dateField = new Field(fieldName, dateString, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.YES); dictionary.Add(fieldName, dateField); break; case JTokenType.TimeSpan: var timeSpanField = new NumericField(fieldName, Field.Store.YES, true); timeSpanField.SetLongValue(((TimeSpan)property.Value).Ticks); dictionary.Add(fieldName, timeSpanField); break; case JTokenType.Integer: var intField = new NumericField(fieldName, Field.Store.YES, true); intField.SetIntValue((int)property.Value); dictionary.Add(fieldName, intField); break; case JTokenType.Float: var floatField = new NumericField(fieldName, Field.Store.YES, true); floatField.SetFloatValue((float)property.Value); dictionary.Add(fieldName, floatField); break; case JTokenType.Guid: var guidField = new Field(fieldName, property.Value.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO); dictionary.Add(fieldName, guidField); break; case JTokenType.Object: TokenizeObject(property.Value as JObject, fieldName, ref dictionary); break; default: if (String.IsNullOrEmpty(property.Value.ToString()) == false) { var stringField = new Field(fieldName, property.Value.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); dictionary.Add(fieldName, stringField); } break; } } }
protected void AddNumericField(string name, long value) { NumericField numericField = new NumericField(name, 4, Field.Store.YES, true); numericField.SetLongValue(value); _document.Add(numericField); }
public static NumericField NewNumericField(NumericFieldType fieldType, string name = null) { NumericField field; switch (fieldType) { case NumericFieldType.Currency: field = new NumericField { Id = Guid.NewGuid(), Name = "Cash Recieved", Required = false, Tooltip = "How much cash was given on arrival", Mask = "c", Maximum = 1000, Minimum = 0, Value = (decimal?)2.54, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; break; case NumericFieldType.Numeric: field = new NumericField { Id = Guid.NewGuid(), DecimalPlaces = 0, Mask = "g", //normal decimal Minimum = 1, Maximum = 1000, Name = "Oil Collected", Tooltip = "in gallons", Value = 125, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; break; default: field = new NumericField { Id = Guid.NewGuid(), Name = "Percent Full", Required = false, Tooltip = "How full is the barrel?", Maximum = 1, Minimum = 0, Mask = "p", Value = (decimal?)0.25, CreatedDate = DateTime.UtcNow, LastModified = DateTime.UtcNow }; break; } if (name != null) field.Name = name; return field; }
public void BuildIndex() { var dirInfo = new System.IO.DirectoryInfo(indexFolder); using (var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)) using (var indexDir = FSDirectory.Open(dirInfo)) { using (var indexWriter = new IndexWriter(indexDir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED)) { foreach (var fileName in System.IO.Directory.GetFiles(baseFolder)) { var xmlDoc = XDocument.Load(fileName); string docid = xmlDoc.Root.Attribute("docid").Value; // remove older index entry var searchQuery = new TermQuery(new Term("exact", docid)); indexWriter.DeleteDocuments(searchQuery); // Create a Lucene document... Document document = new Document(); document.Add(new Field("exact", docid, Field.Store.YES, Field.Index.NOT_ANALYZED)); foreach (var element in xmlDoc.Root.Descendants()) { var name = element.Name.LocalName.ToLower(); var value = (element.Value ?? string.Empty).Trim().ToUpper(); switch (name) { case "rank": var numericField = new NumericField("rank", Field.Store.YES, true); numericField.SetIntValue(Convert.ToInt32(value)); document.Add(numericField); break; case "doj": var dateField = new Field(name, DateTools.DateToString(Convert.ToDateTime(value), DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NOT_ANALYZED); document.Add(dateField); break; default: var field = new Field(name, value, Field.Store.YES, Field.Index.ANALYZED); document.Add(field); break; } } //add doc indexWriter.AddDocument(document); } } } }
private AbstractField DoubleField(string field, double value) { var f = new NumericField(field, precisionStep, Field.Store.NO, true); f.SetOmitNorms(true); f.SetOmitTermFreqAndPositions(true); f.SetDoubleValue(value); return(f); }
protected static Document CloneDocument(Document luceneDoc) { var clonedDocument = new Document(); foreach (AbstractField field in luceneDoc.GetFields()) { var numericField = field as NumericField; if (numericField != null) { var clonedNumericField = new NumericField(numericField.Name, numericField.IsStored ? Field.Store.YES : Field.Store.NO, numericField.IsIndexed); var numericValue = numericField.NumericValue; if (numericValue is int) { clonedNumericField.SetIntValue((int)numericValue); } else if (numericValue is long) { clonedNumericField.SetLongValue((long)numericValue); } else if (numericValue is double) { clonedNumericField.SetDoubleValue((double)numericValue); } else if (numericValue is float) { clonedNumericField.SetFloatValue((float)numericValue); } clonedDocument.Add(clonedNumericField); } else { Field clonedField; if (field.IsBinary) { clonedField = new Field(field.Name, field.GetBinaryValue(), field.IsStored ? Field.Store.YES : Field.Store.NO); } else if (field.StringValue != null) { clonedField = new Field(field.Name, field.StringValue, field.IsStored ? Field.Store.YES : Field.Store.NO, field.IsIndexed ? Field.Index.ANALYZED_NO_NORMS : Field.Index.NOT_ANALYZED_NO_NORMS, field.IsTermVectorStored ? Field.TermVector.YES : Field.TermVector.NO); } else { //probably token stream, and we can't handle fields with token streams, so we skip this. continue; } clonedDocument.Add(clonedField); } } return(clonedDocument); }
private IEnumerable <AbstractField> CreateNumericFieldWithCaching(string name, object value, Field.Store defaultStorage) { var fieldName = name + "_Range"; var storage = indexDefinition.GetStorage(name, defaultStorage); var cacheKey = new { fieldName, storage, multipleItemsSameFieldCountSum = multipleItemsSameFieldCount.Sum() }; NumericField numericField; if (numericFieldsCache.TryGetValue(cacheKey, out numericField) == false) { numericFieldsCache[cacheKey] = numericField = new NumericField(fieldName, storage, true); } if (value is int) { if (indexDefinition.GetSortOption(name) == SortOptions.Long) { yield return(numericField.SetLongValue((int)value)); } else { yield return(numericField.SetIntValue((int)value)); } } if (value is long) { yield return(numericField .SetLongValue((long)value)); } if (value is decimal) { yield return(numericField .SetDoubleValue((double)(decimal)value)); } if (value is float) { if (indexDefinition.GetSortOption(name) == SortOptions.Double) { yield return(numericField.SetDoubleValue((float)value)); } else { yield return(numericField.SetFloatValue((float)value)); } } if (value is double) { yield return(numericField .SetDoubleValue((double)value)); } }
protected long GetNumericFieldValue(string fieldName) { NumericField field = (NumericField)_document.GetFieldable(fieldName); if (field != null) { return((long)field.NumericValue); } return(0); }
protected void AddContent(Document document, DateTime?timestamp) { var timestampValue = timestamp.HasValue ? timestamp.Value.ToFieldValue(_timeGranularity) : 0; var field = new NumericField(_fieldName).setIntValue(timestampValue); _booster.SetBoost(field); document.add(field); }
public void Add(NumericField score) { if (scores.Count > 0) { score.Top = scores [scores.Count - 1].Top + scores [scores.Count - 1].Height; } score.Width = ClientRectangle.Width; scores.Add(score); Controls.Add(score); score.Changed = DoLayout; }
public static NumericField SetIntValue(this NumericField f, int?value) { if (value.HasValue) { f.SetIntValue(value.Value); } else { f.SetIntValue(int.MinValue); } return(f); }
public void NumericField_CanImplicitCastToDecimal() { using (var item = new TestItemContext()) { item.SetField(TestFields.NUMERIC, "3.14159"); var field = new NumericField(new Lazy <Field>(() => item[TestFields.NUMERIC]), null); decimal value = field; Assert.AreEqual(value, 3.14159m); } }
private static Document CreateDocument(string content, DateTime filterDate) { var document = new Document(); document.Add(new Field(TextFieldName, content, Field.Store.YES, Field.Index.ANALYZED)); var numfield = new NumericField(DateFieldName, Field.Store.YES, true); numfield.SetIntValue(int.Parse(filterDate.ToString(NumericDateFormat))); document.Add(numfield); return(document); }
private void SetBoostIfNotDefault(NumericField numericField) { const float threshold = 0.002f; var diff = Math.Abs(Boost - 1.0f); if (diff < threshold) { return; } numericField.ForceDisableOmitNorms(); numericField.Boost = Boost; }
internal static IDataField CreateDataField(IField field, ModuleSchema schema) { return(field switch { StringField f => new StringDataField(f), BooleanField f => new BooleanDataField(f), NumericField f => new NumericDataField(f), EnumField f => new EnumDataField(f), InstrumentField f => new InstrumentDataField(f, schema), OverlayField f => new OverlayDataField(f, schema), TempoField f => new TempoDataField(f), _ => throw new ArgumentException($"Can't handle {field} yet") });
public TransformalizeFormPart() { Arrangement = new TextField { Text = @"<cfg name=""Form""> <parameters> <!-- primary key must be defined here as an integer - default it to zero to indicate a new submission --> <add name=""FormId"" type=""int"" value=""0"" label=""Id"" primary-key=""true"" /> <!-- if you plan to mark things as deleted, add this field on insert with a default of false (not deleted) --> <add name=""Deleted"" type=""bool"" value=""false"" input=""false"" scope=""insert"" /> <!-- if you want to audit who created a record on insert --> <add name=""Created"" type=""datetime"" input=""false"" t=""now()"" scope=""insert"" format=""o"" /> <add name=""CreatedBy"" type=""string"" input=""false"" t=""username()"" scope=""insert"" label=""Created By"" /> <!-- if you want to audit who updated a record on update --> <add name=""Updated"" type=""datetime"" input=""false"" t=""now()"" scope=""update"" format=""o"" /> <add name=""UpdatedBy"" type=""string"" input=""false"" t=""username()"" scope=""update"" label=""Updated By"" /> <!-- your custom fields are defined here --> <!-- hint: set prompt to true to prompt the user --> <!-- hint: set label and hint as necessary --> <!-- hint: use type and input-type to control user input --> <!-- hint: use transforms and validation to control user input --> </parameters> <connections> <!-- hint: define a connection here or use one from common settings (e.g. Transformalize > Settings) --> <!-- hint: if the table does not already exist, you'll have to create it yourself --> <add name=""connection-name"" table=""table-name"" /> </connections> </cfg>" }; LocationEnableHighAccuracy = new BooleanField() { Value = false }; LocationMaximumAge = new NumericField() { Value = 0 }; LocationTimeout = new NumericField() { Value = -1 }; }
private static Document CloneDocument(Document luceneDoc) { var clonedDocument = new Document(); foreach (AbstractField field in luceneDoc.GetFields()) { var numericField = field as NumericField; if (numericField != null) { var clonedNumericField = new NumericField(numericField.Name(), numericField.IsStored() ? Field.Store.YES : Field.Store.NO, numericField.IsIndexed()); var numericValue = numericField.GetNumericValue(); if (numericValue is int) { clonedNumericField.SetIntValue((int)numericValue); } else if (numericValue is long) { clonedNumericField.SetLongValue((long)numericValue); } else if (numericValue is double) { clonedNumericField.SetDoubleValue((double)numericValue); } else if (numericValue is float) { clonedNumericField.SetFloatValue((float)numericValue); } clonedDocument.Add(clonedNumericField); } else { Field clonedField; if (field.IsBinary()) { clonedField = new Field(field.Name(), field.BinaryValue(), field.IsStored() ? Field.Store.YES : Field.Store.NO); } else { clonedField = new Field(field.Name(), field.StringValue(), field.IsStored() ? Field.Store.YES : Field.Store.NO, field.IsIndexed() ? Field.Index.ANALYZED_NO_NORMS : Field.Index.NOT_ANALYZED_NO_NORMS); } clonedDocument.Add(clonedField); } } return(clonedDocument); }
/// <summary> /// See https://issues.apache.org/jira/browse/LUCENENET-519. /// <see cref="NumericField"/> uses <see cref="Field.Index.ANALYZED_NO_NORMS"/> and does /// not allow alternative indexing methods to be used. This prevents boost from being applied /// when a document is being indexed. /// </summary> internal static NumericField ForceDisableOmitNorms(this NumericField field) { const string fieldName = "internalOmitNorms"; var fieldInfo = typeof(AbstractField).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic); if (fieldInfo == null) { throw new InvalidOperationException(string.Format("Type {0} does not have a non-public field named {1}.", typeof(AbstractField), fieldName)); } fieldInfo.SetValue(field, false); return(field); }
internal FieldBase ToField(ModuleJson module, string name, string description, ModuleOffset offset) { return(Type switch { "boolean" => new BooleanField(null, BuildCommon(1)), "boolean32" => new BooleanField(null, BuildCommon(4)), string ph when ph.StartsWith("placeholder") => new PlaceholderField(null, BuildCommon(int.Parse(ph.Substring("placeholder".Length)) / 8)), "enum" => BuildEnumField(1), "enum16" => BuildEnumField(2), "enum24" => BuildEnumField(3), "enum32" => BuildEnumField(4), "instrument" => new InstrumentField(null, BuildCommon(4), ModuleOffset.FromDisplayValue(ValidateNotNull(BankOffset, nameof(BankOffset)).Value)), "midi32" => new NumericField(null, BuildCommon(4), 0, 128, Default ?? 0, null, null, null, null, (128, "Off")), "overlay" => BuildOverlay(), "range8" => BuildNumericField(1, 0, 127), "range16" => BuildNumericField(2, -128, 127), "range32" => BuildNumericField(4, short.MinValue, short.MaxValue), "string" => BuildStringField(1), "string16" => BuildStringField(2), "tempo" => BuildTempoField(), "volume32" => new NumericField(null, BuildCommon(4), -601, 60, 0, 10, null, 0, "dB", (-601, "-INF")), _ => throw new InvalidOperationException($"Invalid field type: '{Type}'") });
private static ValidationResult IsValueValidHelper(decimal? value, decimal minimum, decimal maximum, NumericField numericField) { if (numericField.Mask == "c") return ValidationResult.Success; if(maximum < minimum) return new ValidationResult(String.Format("The Maximum must be greater than or equal to the minimum ({0})", minimum), new[] { "Maximum", "Minimum" }); if (value < minimum) return new ValidationResult(String.Format("The Value must be greater than or equal to the minimum ({0})", minimum), new[] { "Value", "Minimum" }); if (value > maximum) return new ValidationResult(String.Format("The Value must be less than or equal to the maximum ({0})", maximum), new[] { "Value", "Maximum" }); return ValidationResult.Success; }
/// <summary> /// Converts from the FoundOPS model to the API model /// </summary> /// <param name="fieldModel">The FoundOPS model of a NumericField to be converted</param> /// <returns>A NumericField that has been converted to it's API model</returns> public static NumericField ConvertModel(Core.Models.CoreEntities.NumericField fieldModel) { var field = new NumericField { Id = fieldModel.Id, CreatedDate = fieldModel.CreatedDate, Name = fieldModel.Name, Required = fieldModel.Required, ToolTip = fieldModel.Tooltip, ParentFieldId = fieldModel.ParentFieldId, ServiceTemplateId = fieldModel.ServiceTemplateId, Mask = fieldModel.Mask, DecimalPlaces = fieldModel.DecimalPlaces, Minimum = fieldModel.Minimum, Maximum = fieldModel.Maximum, Value = fieldModel.Value }; field.SetLastModified(fieldModel.LastModified, fieldModel.LastModifyingUserId); return field; }
/// <summary> /// Converts the API model back to the FoundOPS model /// </summary> /// <param name="numericField"></param> /// <returns></returns> public static Core.Models.CoreEntities.Field ConvertBack(NumericField numericField) { var field = new Core.Models.CoreEntities.NumericField { Id = numericField.Id, Name = numericField.Name, Required = numericField.Required, Tooltip = numericField.ToolTip, ParentFieldId = numericField.ParentFieldId, ServiceTemplateId = numericField.ServiceTemplateId, Mask = numericField.Mask, DecimalPlaces = numericField.DecimalPlaces, Minimum = numericField.Minimum, Maximum = numericField.Maximum, Value = numericField.Value, CreatedDate = numericField.CreatedDate, LastModified = numericField.LastModified, LastModifyingUserId = numericField.LastModifyingUserId }; return field; }
public LocationField(string latitudeFieldName, string longitudeFieldName) { LatitudeField = new NumericField(latitudeFieldName); LongitudeField = new NumericField(longitudeFieldName); FieldType = FieldType.Composite; }
/// <summary> /// Adds the field to the lucene document. /// </summary> /// <param name="doc">The doc.</param> /// <param name="field">The field.</param> private static void AddFieldToDocument(ref Document doc, IDocumentField field) { if (field == null) { return; } var store = Field.Store.YES; var index = Field.Index.NOT_ANALYZED; if (field.ContainsAttribute(value: IndexStore.NO)) { store = Field.Store.NO; } if (field.ContainsAttribute(IndexType.ANALYZED)) { index = Field.Index.ANALYZED; } else if (field.ContainsAttribute(IndexType.NO)) { index = Field.Index.NO; } if (field.Value == null) { return; } field.Name = field.Name.ToLower(); if (field.Name == "__key") { foreach (var val in field.Values) { doc.Add(new Field(field.Name, val.ToString(), store, index)); } } else if (field.Value is string) { foreach (var val in field.Values) { doc.Add(new Field(field.Name, val.ToString(), store, index)); doc.Add(new Field("_content", val.ToString(), Field.Store.NO, Field.Index.ANALYZED)); } } else if (field.Value is decimal) // parse prices { foreach (var val in field.Values) { var numericField = new NumericField(field.Name, store, index != Field.Index.NO); numericField.SetDoubleValue(double.Parse(val.ToString())); doc.Add(numericField); } } else if (field.Value is DateTime) // parse dates { foreach (var val in field.Values) { doc.Add( new Field( field.Name, DateTools.DateToString((DateTime)val, DateTools.Resolution.SECOND), store, index)); } } else // try detecting the type { // TODO: instead of auto detecting, use meta data information decimal t; if (Decimal.TryParse(field.Value.ToString(), out t)) { foreach (var val in field.Values) { var numericField = new NumericField(field.Name, store, index != Field.Index.NO); numericField.SetDoubleValue(double.Parse(val.ToString())); doc.Add(numericField); } } else { foreach (var val in field.Values) { doc.Add(new Field(field.Name, val.ToString(), store, index)); } } } }