public override int GetHashCode() { int hash = 1; if (StringField.Length != 0) { hash ^= StringField.GetHashCode(); } if (Int64Field != 0L) { hash ^= Int64Field.GetHashCode(); } if (Uint32Field != 0) { hash ^= Uint32Field.GetHashCode(); } hash ^= repeatedDoubleField_.GetHashCode(); if (EnumField != 0) { hash ^= EnumField.GetHashCode(); } if (subMessageField_ != null) { hash ^= SubMessageField.GetHashCode(); } hash ^= repeatedSubMessageField_.GetHashCode(); return(hash); }
public DocState(bool reuseFields, FieldType ft, FieldType bodyFt) { this.reuseFields = reuseFields; if (reuseFields) { fields = new Dictionary <string, Field>(); numericFields = new Dictionary <string, Field>(); // Initialize the map with the default fields. fields[BODY_FIELD] = new Field(BODY_FIELD, "", bodyFt); fields[TITLE_FIELD] = new Field(TITLE_FIELD, "", ft); fields[DATE_FIELD] = new Field(DATE_FIELD, "", ft); fields[ID_FIELD] = new StringField(ID_FIELD, "", Field.Store.YES); fields[NAME_FIELD] = new Field(NAME_FIELD, "", ft); numericFields[DATE_MSEC_FIELD] = new Int64Field(DATE_MSEC_FIELD, 0L, Field.Store.NO); numericFields[TIME_SEC_FIELD] = new Int32Field(TIME_SEC_FIELD, 0, Field.Store.NO); doc = new Document(); } else { numericFields = null; fields = null; doc = null; } }
public override int GetHashCode() { int hash = 1; if (StringField.Length != 0) { hash ^= StringField.GetHashCode(); } if (Int64Field != 0L) { hash ^= Int64Field.GetHashCode(); } if (Uint32Field != 0) { hash ^= Uint32Field.GetHashCode(); } hash ^= repeatedDoubleField_.GetHashCode(); if (EnumField != global::Plexus.Interop.Testing.Generated.EchoRequest.Types.SubEnum.ValueOne) { hash ^= EnumField.GetHashCode(); } if (subMessageField_ != null) { hash ^= SubMessageField.GetHashCode(); } hash ^= repeatedSubMessageField_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { unchecked { var hashCode = ByteField.GetHashCode(); hashCode = (hashCode * 397) ^ SByteField.GetHashCode(); hashCode = (hashCode * 397) ^ Int16Field.GetHashCode(); hashCode = (hashCode * 397) ^ UInt16Field.GetHashCode(); hashCode = (hashCode * 397) ^ Int32Field; hashCode = (hashCode * 397) ^ (int)UInt32Field; hashCode = (hashCode * 397) ^ Int64Field.GetHashCode(); hashCode = (hashCode * 397) ^ UInt64Field.GetHashCode(); hashCode = (hashCode * 397) ^ DecimalField.GetHashCode(); hashCode = (hashCode * 397) ^ SingleFiled.GetHashCode(); hashCode = (hashCode * 397) ^ DoubleField.GetHashCode(); hashCode = (hashCode * 397) ^ (StringField != null ? StringField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)MyEnumField; hashCode = (hashCode * 397) ^ BooleanField.GetHashCode(); hashCode = (hashCode * 397) ^ DateTimeField.GetHashCode(); hashCode = (hashCode * 397) ^ DateTimeOffsetField.GetHashCode(); hashCode = (hashCode * 397) ^ GuidField.GetHashCode(); hashCode = (hashCode * 397) ^ TimeSpanField.GetHashCode(); hashCode = (hashCode * 397) ^ (UrlField != null ? UrlField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (NullField != null ? NullField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (IntArrayField != null ? IntArrayField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (StringArrayField != null ? StringArrayField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (EmptyArrayField != null ? EmptyArrayField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (NullArrayField != null ? NullArrayField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (DictionaryArrayField != null ? DictionaryArrayField.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ObjectArrayField != null ? ObjectArrayField.GetHashCode() : 0); return(hashCode); } }
/// <summary> /// Adds a stored or un-stored <see cref="Int64Field"/> with the provided value. /// <para/> /// Expert: allows you to customize the <see cref="FieldType"/>. /// </summary> /// <param name="document">This <see cref="Document"/>.</param> /// <param name="name"> field name </param> /// <param name="value"> 64-bit <see cref="long"/> value </param> /// <param name="type"> customized field type: must have <see cref="FieldType.NumericType"/> /// of <see cref="NumericType.INT64"/>. </param> /// <returns>The field that was added to this <see cref="Document"/>.</returns> /// <exception cref="System.ArgumentNullException"> if the field <paramref name="name"/> or <paramref name="type"/> is <see cref="NumericType.NONE"/> </exception> /// <exception cref="System.ArgumentException"> if the field type does not have a /// <see cref="FieldType.NumericType"/> of <see cref="NumericType.INT64"/> </exception> public static Int64Field AddInt64Field(this Document document, string name, long value, FieldType type) { var field = new Int64Field(name, value, type); document.Add(field); return(field); }
public virtual void TestLongFieldCache() { Directory dir = NewDirectory(); IndexWriterConfig cfg = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)); cfg.SetMergePolicy(NewLogMergePolicy()); RandomIndexWriter iw = new RandomIndexWriter(Random, dir, cfg); Document doc = new Document(); Int64Field field = new Int64Field("f", 0L, Field.Store.YES); doc.Add(field); long[] values = new long[TestUtil.NextInt32(Random, 1, 10)]; for (int i = 0; i < values.Length; ++i) { long v; switch (Random.Next(10)) { case 0: v = long.MinValue; break; case 1: v = 0; break; case 2: v = long.MaxValue; break; default: v = TestUtil.NextInt64(Random, -10, 10); break; } values[i] = v; if (v == 0 && Random.NextBoolean()) { // missing iw.AddDocument(new Document()); } else { field.SetInt64Value(v); iw.AddDocument(doc); } } iw.ForceMerge(1); DirectoryReader reader = iw.GetReader(); Int64s longs = FieldCache.DEFAULT.GetInt64s(GetOnlySegmentReader(reader), "f", false); for (int i = 0; i < values.Length; ++i) { Assert.AreEqual(values[i], longs.Get(i)); } reader.Dispose(); iw.Dispose(); dir.Dispose(); }
public void TestAddInt64Field_Stored() { Int64Field field = null; long value = 123; var stored = Field.Store.YES; AssertDocumentExtensionAddsToDocument(document => field = document.AddInt64Field("theName", value, stored)); Assert.AreEqual("theName", field.Name); Assert.AreEqual(value, field.GetInt64ValueOrDefault()); Assert.AreSame(Int64Field.TYPE_STORED, field.FieldType); }
public DbMessageStream(IDbConnectionFactory db) { this.db = db; BatchSize = 1000; messageId = new Int64Field {Name = "MessageId"}; format = new StringField {Name = "Format"}; source = new StringField {Name = "Source"}; createdOn = new DateTimeOffsetField {Name = "CreatedOn"}; sequence = new Int64Field {Name = "Sequence"}; content = new StringField {Name = "Content"}; }
/// <summary> /// Adds a stored or un-stored <see cref="Int64Field"/> with the provided value. /// <para/> /// Expert: allows you to customize the <see cref="FieldType"/>. /// </summary> /// <param name="document">This <see cref="Document"/>.</param> /// <param name="name"> field name </param> /// <param name="value"> 64-bit <see cref="long"/> value </param> /// <param name="type"> customized field type: must have <see cref="FieldType.NumericType"/> /// of <see cref="NumericType.INT64"/>. </param> /// <returns>The field that was added to this <see cref="Document"/>.</returns> /// <exception cref="ArgumentNullException"> if this <paramref name="document"/>, the field <paramref name="name"/> or <paramref name="type"/> is <c>null</c>. </exception> /// <exception cref="ArgumentException"> if the field type does not have a /// <see cref="FieldType.NumericType"/> of <see cref="NumericType.INT64"/> </exception> public static Int64Field AddInt64Field(this Document document, string name, long value, FieldType type) { if (document is null) { throw new ArgumentNullException(nameof(document)); } var field = new Int64Field(name, value, type); document.Add(field); return(field); }
private static void addIdField(Document doc, string fieldName, long fieldValue) { fieldName = fieldName.ToLower(Str.Culture); var field = new Int64Field(fieldName, fieldValue, new FieldType(Int64Field.TYPE_STORED) { IsIndexed = false }); doc.Add(field); }
public static Field[] ToFieldArray(this IEnumerable<ICustomFieldDefinition> items, ICollection<Field> collection, string namePrefix, Action<Field, ICustomFieldDefinition> initialize = null) { var result = new List<Field>(); foreach (var item in items) { var flags = item.IsRequired ? Required : NotRequired; var caption = ToLocalText(item.Title); var name = (namePrefix ?? "") + item.Name; Field field; switch (item.FieldType) { case CustomFieldType.Boolean: field = new BooleanField(collection, name, caption, 0, flags); break; case CustomFieldType.Date: field = new DateTimeField(collection, name, caption, 0, flags) { DateTimeKind = DateTimeKind.Unspecified }; break; case CustomFieldType.DateTime: field = new DateTimeField(collection, name, caption, 0, flags) { DateTimeKind = DateTimeKind.Local }; break; case CustomFieldType.Decimal: field = new DecimalField(collection, name, caption, item.Size, flags); break; case CustomFieldType.Int32: field = new Int32Field(collection, name, caption, item.Size, flags); break; case CustomFieldType.Int64: field = new Int64Field(collection, name, caption, item.Size, flags); break; default: field = new StringField(collection, name, caption, item.Size, flags); break; } field.DefaultValue = item.DefaultValue.TrimToNull(); result.Add(field); if (initialize != null) initialize(field, item); } return result.ToArray(); }
public void TestAddInt64Field_FieldType() { Int64Field field = null; long value = 123; var fieldType = new FieldType { IsIndexed = true, IsTokenized = true, OmitNorms = false, IndexOptions = IndexOptions.DOCS_ONLY, NumericType = NumericType.INT64, IsStored = true }.Freeze(); AssertDocumentExtensionAddsToDocument(document => field = document.AddInt64Field("theName", value, fieldType)); Assert.AreEqual("theName", field.Name); Assert.AreEqual(value, field.GetInt64ValueOrDefault()); Assert.AreSame(fieldType, field.FieldType); }
internal Field GetNumericField(string name, NumericType type) { Field f; if (reuseFields) { numericFields.TryGetValue(name, out f); } else { f = null; } if (f == null) { switch (type) { case NumericType.INT32: f = new Int32Field(name, 0, Field.Store.NO); break; case NumericType.INT64: f = new Int64Field(name, 0L, Field.Store.NO); break; case NumericType.SINGLE: f = new SingleField(name, 0.0F, Field.Store.NO); break; case NumericType.DOUBLE: f = new DoubleField(name, 0.0, Field.Store.NO); break; default: throw new InvalidOperationException("Cannot get here"); } if (reuseFields) { numericFields[name] = f; } } return(f); }
public override void BeforeClass() { base.BeforeClass(); ANALYZER = new MockAnalyzer(Random()); qp = new StandardQueryParser(ANALYZER); HashMap <String, /*Number*/ object> randomNumberMap = new HashMap <string, object>(); /*SimpleDateFormat*/ string dateFormat; long randomDate; bool dateFormatSanityCheckPass; int count = 0; do { if (count > 100) { fail("This test has problems to find a sane random DateFormat/NumberFormat. Stopped trying after 100 iterations."); } dateFormatSanityCheckPass = true; LOCALE = RandomLocale(Random()); TIMEZONE = RandomTimeZone(Random()); DATE_STYLE = randomDateStyle(Random()); TIME_STYLE = randomDateStyle(Random()); //// assumes localized date pattern will have at least year, month, day, //// hour, minute //dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance( // DATE_STYLE, TIME_STYLE, LOCALE); //// not all date patterns includes era, full year, timezone and second, //// so we add them here //dateFormat.applyPattern(dateFormat.toPattern() + " G s Z yyyy"); //dateFormat.setTimeZone(TIMEZONE); // assumes localized date pattern will have at least year, month, day, // hour, minute DATE_FORMAT = new NumberDateFormat(DATE_STYLE, TIME_STYLE, LOCALE) { TimeZone = TIMEZONE }; // not all date patterns includes era, full year, timezone and second, // so we add them here DATE_FORMAT.SetDateFormat(DATE_FORMAT.GetDateFormat() + " g s z yyyy"); dateFormat = DATE_FORMAT.GetDateFormat(); do { randomDate = Random().nextLong(); // prune date value so it doesn't pass in insane values to some // calendars. randomDate = randomDate % 3400000000000L; // truncate to second randomDate = (randomDate / 1000L) * 1000L; // only positive values randomDate = Math.Abs(randomDate); } while (randomDate == 0L); dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, randomDate); dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, 0); dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, -randomDate); count++; } while (!dateFormatSanityCheckPass); //NUMBER_FORMAT = NumberFormat.getNumberInstance(LOCALE); //NUMBER_FORMAT.setMaximumFractionDigits((Random().nextInt() & 20) + 1); //NUMBER_FORMAT.setMinimumFractionDigits((Random().nextInt() & 20) + 1); //NUMBER_FORMAT.setMaximumIntegerDigits((Random().nextInt() & 20) + 1); //NUMBER_FORMAT.setMinimumIntegerDigits((Random().nextInt() & 20) + 1); NUMBER_FORMAT = new NumberFormat(LOCALE); double randomDouble; long randomLong; int randomInt; float randomFloat; while ((randomLong = Convert.ToInt64(NormalizeNumber(Math.Abs(Random().nextLong())) )) == 0L) { ; } while ((randomDouble = Convert.ToDouble(NormalizeNumber(Math.Abs(Random().NextDouble())) )) == 0.0) { ; } while ((randomFloat = Convert.ToSingle(NormalizeNumber(Math.Abs(Random().nextFloat())) )) == 0.0f) { ; } while ((randomInt = Convert.ToInt32(NormalizeNumber(Math.Abs(Random().nextInt())))) == 0) { ; } randomNumberMap.Put(NumericType.INT64.ToString(), randomLong); randomNumberMap.Put(NumericType.INT32.ToString(), randomInt); randomNumberMap.Put(NumericType.SINGLE.ToString(), randomFloat); randomNumberMap.Put(NumericType.DOUBLE.ToString(), randomDouble); randomNumberMap.Put(DATE_FIELD_NAME, randomDate); RANDOM_NUMBER_MAP = Collections.UnmodifiableMap(randomNumberMap); directory = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())) .SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000)) .SetMergePolicy(NewLogMergePolicy())); Document doc = new Document(); HashMap <String, NumericConfig> numericConfigMap = new HashMap <String, NumericConfig>(); HashMap <String, Field> numericFieldMap = new HashMap <String, Field>(); qp.NumericConfigMap = (numericConfigMap); foreach (NumericType type in Enum.GetValues(typeof(NumericType))) { if (type == NumericType.NONE) { continue; } numericConfigMap.Put(type.ToString(), new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, type)); FieldType ft2 = new FieldType(Int32Field.TYPE_NOT_STORED); ft2.NumericType = (type); ft2.IsStored = (true); ft2.NumericPrecisionStep = (PRECISION_STEP); ft2.Freeze(); Field field; switch (type) { case NumericType.INT32: field = new Int32Field(type.ToString(), 0, ft2); break; case NumericType.SINGLE: field = new SingleField(type.ToString(), 0.0f, ft2); break; case NumericType.INT64: field = new Int64Field(type.ToString(), 0L, ft2); break; case NumericType.DOUBLE: field = new DoubleField(type.ToString(), 0.0, ft2); break; default: fail(); field = null; break; } numericFieldMap.Put(type.ToString(), field); doc.Add(field); } numericConfigMap.Put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP, DATE_FORMAT, NumericType.INT64)); FieldType ft = new FieldType(Int64Field.TYPE_NOT_STORED); ft.IsStored = (true); ft.NumericPrecisionStep = (PRECISION_STEP); Int64Field dateField = new Int64Field(DATE_FIELD_NAME, 0L, ft); numericFieldMap.Put(DATE_FIELD_NAME, dateField); doc.Add(dateField); foreach (NumberType numberType in Enum.GetValues(typeof(NumberType))) { setFieldValues(numberType, numericFieldMap); if (VERBOSE) { Console.WriteLine("Indexing document: " + doc); } writer.AddDocument(doc); } reader = writer.Reader; searcher = NewSearcher(reader); writer.Dispose(); }
public void GetFieldSettings(List <FlattenedObject> props, Document doc, List <KeyValuePair <string, Analyzer> > analyzers) { foreach (var p in props) { if (p == null) { continue; } if (analyzers != null) { if (p.Analyzer != null) { analyzers.Add(new KeyValuePair <string, Analyzer>(p.Key, p.Analyzer)); } } if (doc != null) { if (p.Value is int || p.Value is int?) { var nf = new Int32Field(p.Key, int.Parse(p.Value.ToString()), p.FieldStoreSetting); doc.Add(nf); } else if (p.Value is long || p.Value is long?) { var nf = new Int64Field(p.Key, long.Parse(p.Value.ToString()), p.FieldStoreSetting); doc.Add(nf); } else if (p.Value is float || p.Value is float?) { var nf = new SingleField(p.Key, float.Parse(p.Value.ToString()), p.FieldStoreSetting); doc.Add(nf); } else if (p.Value is double || p.Value is double?) { var nf = new DoubleField(p.Key, double.Parse(p.Value.ToString()), p.FieldStoreSetting); doc.Add(nf); } else if (p.Spatial) { if (p.Value == null || string.IsNullOrEmpty(p.Value.ToString())) { continue; } var name = p.Key;// p.Key.IndexOf('.')>-1?p.Key.Substring(0,p.Key.LastIndexOf('.')):p.Key; int maxLevels = 11; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels); var strat = new RecursivePrefixTreeStrategy(grid, name); //var strat = new PointVectorStrategy(ctx,name); var xyArr = p.Value.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (xyArr.Length != 2) { continue; } double x; double y; if (!double.TryParse(xyArr[0], out x) || !double.TryParse(xyArr[1], out y)) { continue; } var point = ctx.MakePoint(x, y); //var point = ctx.ReadShape(p.Value.ToString()); var fields = strat.CreateIndexableFields(point); fields.ToList().ForEach(x => doc.Add(x)); IPoint pt = (IPoint)point; //doc.Add(new StoredField(strat.FieldName, pt.X.ToString(CultureInfo.InvariantCulture) + " " + pt.Y.ToString(CultureInfo.InvariantCulture))); } else { string value = p.Value == null ? null : (p.KeepValueCasing ? p.Value.ToString() : p.Value.ToString().ToLower()); Field f = null; if (p.FieldIndexSetting == Field.Index.ANALYZED || p.FieldIndexSetting == Field.Index.ANALYZED_NO_NORMS) { f = new TextField(p.Key, value ?? string.Empty, p.FieldStoreSetting); } else { f = new StringField(p.Key, value ?? string.Empty, p.FieldStoreSetting); } doc.Add(f); } } } }
protected virtual IList <IIndexableField> ConvertToProviderFields(IndexDocumentField field) { var result = new List <IIndexableField>(); var fieldName = LuceneSearchHelper.ToLuceneFieldName(field.Name); var store = field.IsRetrievable ? Field.Store.YES : Field.Store.NO; switch (field.Value) { case string _: foreach (var value in field.Values) { result.Add(new StringField(fieldName, (string)value, store)); if (field.IsSearchable) { result.Add(new StringField(LuceneSearchHelper.SearchableFieldName, (string)value, Field.Store.NO)); } } break; case bool _: var booleanFieldName = LuceneSearchHelper.GetBooleanFieldName(field.Name); foreach (var value in field.Values) { var stringValue = value.ToStringInvariant(); result.Add(new StringField(fieldName, stringValue, store)); result.Add(new StringField(booleanFieldName, stringValue, Field.Store.NO)); } break; case DateTime _: var dateTimeFieldName = LuceneSearchHelper.GetDateTimeFieldName(field.Name); foreach (var value in field.Values) { var numericField = new Int64Field(fieldName, ((DateTime)value).Ticks, store); result.Add(numericField); result.Add(new StringField(dateTimeFieldName, value.ToStringInvariant(), Field.Store.NO)); } break; case GeoPoint _: var geoPoint = (GeoPoint)field.Value; result.Add(new StringField(fieldName, geoPoint.ToString(), Field.Store.YES)); var shape = _spatialContext.MakePoint(geoPoint.Longitude, geoPoint.Latitude); var strategy = new PointVectorStrategy(_spatialContext, fieldName); result.AddRange(strategy.CreateIndexableFields(shape)); break; default: if (double.TryParse(field.Value.ToStringInvariant(), NumberStyles.Float, CultureInfo.InvariantCulture, out _)) { var facetableFieldName = LuceneSearchHelper.GetFacetableFieldName(field.Name); foreach (var value in field.Values) { var stringValue = value.ToStringInvariant(); var doubleField = new DoubleField(fieldName, double.Parse(stringValue, NumberStyles.Float, CultureInfo.InvariantCulture), store); result.Add(doubleField); result.Add(new StringField(facetableFieldName, stringValue, Field.Store.NO)); } } else { result.AddRange(field.Values.Select(value => new StringField(fieldName, value.ToStringInvariant(), store))); } break; } return(result); }
// [Test] // LUCENENET NOTE: For now, we are overriding this test in every subclass to pull it into the right context for the subclass public virtual void TestNumericField() { Directory dir = NewDirectory(); var w = new RandomIndexWriter(Random(), dir, ClassEnvRule.similarity, ClassEnvRule.timeZone); var numDocs = AtLeast(500); var answers = new object[numDocs]; NumericType[] typeAnswers = new NumericType[numDocs]; for (int id = 0; id < numDocs; id++) { Document doc = new Document(); Field nf; Field sf; object answer; NumericType typeAnswer; if (Random().NextBoolean()) { // float/double if (Random().NextBoolean()) { float f = Random().NextFloat(); answer = Convert.ToSingle(f, CultureInfo.InvariantCulture); nf = new SingleField("nf", f, Field.Store.NO); sf = new StoredField("nf", f); typeAnswer = NumericType.SINGLE; } else { double d = Random().NextDouble(); answer = Convert.ToDouble(d, CultureInfo.InvariantCulture); nf = new DoubleField("nf", d, Field.Store.NO); sf = new StoredField("nf", d); typeAnswer = NumericType.DOUBLE; } } else { // int/long if (Random().NextBoolean()) { int i = Random().Next(); answer = Convert.ToInt32(i, CultureInfo.InvariantCulture); nf = new Int32Field("nf", i, Field.Store.NO); sf = new StoredField("nf", i); typeAnswer = NumericType.INT32; } else { long l = Random().NextLong(); answer = Convert.ToInt64(l, CultureInfo.InvariantCulture); nf = new Int64Field("nf", l, Field.Store.NO); sf = new StoredField("nf", l); typeAnswer = NumericType.INT64; } } doc.Add(nf); doc.Add(sf); answers[id] = answer; typeAnswers[id] = typeAnswer; FieldType ft = new FieldType(Int32Field.TYPE_STORED); ft.NumericPrecisionStep = int.MaxValue; doc.Add(new Int32Field("id", id, ft)); w.AddDocument(doc); } DirectoryReader r = w.Reader; w.Dispose(); Assert.AreEqual(numDocs, r.NumDocs); foreach (AtomicReaderContext ctx in r.Leaves) { AtomicReader sub = (AtomicReader)ctx.Reader; FieldCache.Int32s ids = FieldCache.DEFAULT.GetInt32s(sub, "id", false); for (int docID = 0; docID < sub.NumDocs; docID++) { Document doc = sub.Document(docID); Field f = (Field)doc.GetField("nf"); Assert.IsTrue(f is StoredField, "got f=" + f); Assert.AreEqual(answers[ids.Get(docID)], f.GetNumericValue()); } } r.Dispose(); dir.Dispose(); }
private ObjectDataFieldControl CreateControl(long typeId, int member, ObjectInfo objInfo) { ObjectDataFieldControl c = null; Safir.Dob.Typesystem.MemberType memberType; long complexType; int typeSize; bool isArray; int arrLength; string memberName = Safir.Dob.Typesystem.Members.GetInfo(typeId, member, out memberType, out complexType, out typeSize, out isArray, out arrLength); switch (memberType) { case Safir.Dob.Typesystem.MemberType.EnumerationMemberType: { c = new EnumField(objInfo, member, complexType, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.BooleanMemberType: { c = new BoolField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.Int32MemberType: { c = new Int32Field(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.Int64MemberType: { c = new Int64Field(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.ChannelIdMemberType: { c = new ChannelIdField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.HandlerIdMemberType: { c = new HandlerIdField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.EntityIdMemberType: { c = new EntityIdField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.InstanceIdMemberType: { c = new InstanceIdField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.StringMemberType: { c = new StringField(objInfo, member, memberName, arrLength, typeSize); break; } case Safir.Dob.Typesystem.MemberType.TypeIdMemberType: { c = new TypeIdField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.ObjectMemberType: { c = new ObjectField(objInfo, member, complexType, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.BinaryMemberType: { c = new BinaryField(objInfo, member, memberName, arrLength); break; } case Safir.Dob.Typesystem.MemberType.Float32MemberType: case Safir.Dob.Typesystem.MemberType.Ampere32MemberType: case Safir.Dob.Typesystem.MemberType.CubicMeter32MemberType: case Safir.Dob.Typesystem.MemberType.Hertz32MemberType: case Safir.Dob.Typesystem.MemberType.Joule32MemberType: case Safir.Dob.Typesystem.MemberType.Kelvin32MemberType: case Safir.Dob.Typesystem.MemberType.Kilogram32MemberType: case Safir.Dob.Typesystem.MemberType.Meter32MemberType: case Safir.Dob.Typesystem.MemberType.MeterPerSecond32MemberType: case Safir.Dob.Typesystem.MemberType.MeterPerSecondSquared32MemberType: case Safir.Dob.Typesystem.MemberType.Newton32MemberType: case Safir.Dob.Typesystem.MemberType.Pascal32MemberType: case Safir.Dob.Typesystem.MemberType.Radian32MemberType: case Safir.Dob.Typesystem.MemberType.RadianPerSecond32MemberType: case Safir.Dob.Typesystem.MemberType.RadianPerSecondSquared32MemberType: case Safir.Dob.Typesystem.MemberType.Second32MemberType: case Safir.Dob.Typesystem.MemberType.SquareMeter32MemberType: case Safir.Dob.Typesystem.MemberType.Steradian32MemberType: case Safir.Dob.Typesystem.MemberType.Volt32MemberType: case Safir.Dob.Typesystem.MemberType.Watt32MemberType: { c = new Float32Field(objInfo, member, memberName, arrLength, Safir.Dob.Typesystem.Members.GetTypeName(typeId, member)); break; } case Safir.Dob.Typesystem.MemberType.Float64MemberType: case Safir.Dob.Typesystem.MemberType.Ampere64MemberType: case Safir.Dob.Typesystem.MemberType.CubicMeter64MemberType: case Safir.Dob.Typesystem.MemberType.Hertz64MemberType: case Safir.Dob.Typesystem.MemberType.Joule64MemberType: case Safir.Dob.Typesystem.MemberType.Kelvin64MemberType: case Safir.Dob.Typesystem.MemberType.Kilogram64MemberType: case Safir.Dob.Typesystem.MemberType.Meter64MemberType: case Safir.Dob.Typesystem.MemberType.MeterPerSecond64MemberType: case Safir.Dob.Typesystem.MemberType.MeterPerSecondSquared64MemberType: case Safir.Dob.Typesystem.MemberType.Newton64MemberType: case Safir.Dob.Typesystem.MemberType.Pascal64MemberType: case Safir.Dob.Typesystem.MemberType.Radian64MemberType: case Safir.Dob.Typesystem.MemberType.RadianPerSecond64MemberType: case Safir.Dob.Typesystem.MemberType.RadianPerSecondSquared64MemberType: case Safir.Dob.Typesystem.MemberType.Second64MemberType: case Safir.Dob.Typesystem.MemberType.SquareMeter64MemberType: case Safir.Dob.Typesystem.MemberType.Steradian64MemberType: case Safir.Dob.Typesystem.MemberType.Volt64MemberType: case Safir.Dob.Typesystem.MemberType.Watt64MemberType: { c = new Float64Field(objInfo, member, memberName, arrLength, Safir.Dob.Typesystem.Members.GetTypeName(typeId, member)); break; } } if (c != null) { c.ParentObjectEditPanel = this; } return(c); }
public override void BeforeClass() { base.BeforeClass(); NoDocs = AtLeast(4096); Distance = (1L << 60) / NoDocs; Directory = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random(), Directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(TestUtil.NextInt(Random(), 100, 1000)).SetMergePolicy(NewLogMergePolicy())); FieldType storedLong = new FieldType(Int64Field.TYPE_NOT_STORED); storedLong.IsStored = true; storedLong.Freeze(); FieldType storedLong8 = new FieldType(storedLong); storedLong8.NumericPrecisionStep = 8; FieldType storedLong4 = new FieldType(storedLong); storedLong4.NumericPrecisionStep = 4; FieldType storedLong6 = new FieldType(storedLong); storedLong6.NumericPrecisionStep = 6; FieldType storedLong2 = new FieldType(storedLong); storedLong2.NumericPrecisionStep = 2; FieldType storedLongNone = new FieldType(storedLong); storedLongNone.NumericPrecisionStep = int.MaxValue; FieldType unstoredLong = Int64Field.TYPE_NOT_STORED; FieldType unstoredLong8 = new FieldType(unstoredLong); unstoredLong8.NumericPrecisionStep = 8; FieldType unstoredLong6 = new FieldType(unstoredLong); unstoredLong6.NumericPrecisionStep = 6; FieldType unstoredLong4 = new FieldType(unstoredLong); unstoredLong4.NumericPrecisionStep = 4; FieldType unstoredLong2 = new FieldType(unstoredLong); unstoredLong2.NumericPrecisionStep = 2; Int64Field field8 = new Int64Field("field8", 0L, storedLong8), field6 = new Int64Field("field6", 0L, storedLong6), field4 = new Int64Field("field4", 0L, storedLong4), field2 = new Int64Field("field2", 0L, storedLong2), fieldNoTrie = new Int64Field("field" + int.MaxValue, 0L, storedLongNone), ascfield8 = new Int64Field("ascfield8", 0L, unstoredLong8), ascfield6 = new Int64Field("ascfield6", 0L, unstoredLong6), ascfield4 = new Int64Field("ascfield4", 0L, unstoredLong4), ascfield2 = new Int64Field("ascfield2", 0L, unstoredLong2); Document doc = new Document(); // add fields, that have a distance to test general functionality doc.Add(field8); doc.Add(field6); doc.Add(field4); doc.Add(field2); doc.Add(fieldNoTrie); // add ascending fields with a distance of 1, beginning at -noDocs/2 to test the correct splitting of range and inclusive/exclusive doc.Add(ascfield8); doc.Add(ascfield6); doc.Add(ascfield4); doc.Add(ascfield2); // Add a series of noDocs docs with increasing long values, by updating the fields for (int l = 0; l < NoDocs; l++) { long val = Distance * l + StartOffset; field8.SetInt64Value(val); field6.SetInt64Value(val); field4.SetInt64Value(val); field2.SetInt64Value(val); fieldNoTrie.SetInt64Value(val); val = l - (NoDocs / 2); ascfield8.SetInt64Value(val); ascfield6.SetInt64Value(val); ascfield4.SetInt64Value(val); ascfield2.SetInt64Value(val); writer.AddDocument(doc); } Reader = writer.Reader; Searcher = NewSearcher(Reader); writer.Dispose(); }
// NOTE: this is likely buggy, and cannot clone fields // with tokenStreamValues, etc. Use at your own risk!! // TODO: is there a pre-existing way to do this!!! public static Document CloneDocument(Document doc1) { Document doc2 = new Document(); foreach (IIndexableField f in doc1.Fields) { Field field1 = (Field)f; Field field2; DocValuesType dvType = field1.FieldType.DocValueType; NumericType numType = field1.FieldType.NumericType; if (dvType != DocValuesType.NONE) { switch (dvType) { case DocValuesType.NUMERIC: field2 = new NumericDocValuesField(field1.Name, field1.GetInt64Value().Value); break; case DocValuesType.BINARY: field2 = new BinaryDocValuesField(field1.Name, field1.GetBinaryValue()); break; case DocValuesType.SORTED: field2 = new SortedDocValuesField(field1.Name, field1.GetBinaryValue()); break; default: throw IllegalStateException.Create("unknown Type: " + dvType); } } else if (numType != NumericType.NONE) { switch (numType) { case NumericType.INT32: field2 = new Int32Field(field1.Name, field1.GetInt32Value().Value, field1.FieldType); break; case NumericType.SINGLE: field2 = new SingleField(field1.Name, field1.GetInt32Value().Value, field1.FieldType); break; case NumericType.INT64: field2 = new Int64Field(field1.Name, field1.GetInt32Value().Value, field1.FieldType); break; case NumericType.DOUBLE: field2 = new DoubleField(field1.Name, field1.GetInt32Value().Value, field1.FieldType); break; default: throw IllegalStateException.Create("unknown Type: " + numType); } } else { field2 = new Field(field1.Name, field1.GetStringValue(), field1.FieldType); } doc2.Add(field2); } return(doc2); }
public virtual void TestNumericField() { using Directory dir = NewDirectory(); DirectoryReader r = null; try { var numDocs = AtLeast(500); var answers = new Number[numDocs]; using (var w = new RandomIndexWriter(Random, dir)) { NumericType[] typeAnswers = new NumericType[numDocs]; for (int id = 0; id < numDocs; id++) { Document doc = new Document(); Field nf; Field sf; Number answer; NumericType typeAnswer; if (Random.NextBoolean()) { // float/double if (Random.NextBoolean()) { float f = Random.NextSingle(); answer = Single.GetInstance(f); nf = new SingleField("nf", f, Field.Store.NO); sf = new StoredField("nf", f); typeAnswer = NumericType.SINGLE; } else { double d = Random.NextDouble(); answer = Double.GetInstance(d); nf = new DoubleField("nf", d, Field.Store.NO); sf = new StoredField("nf", d); typeAnswer = NumericType.DOUBLE; } } else { // int/long if (Random.NextBoolean()) { int i = Random.Next(); answer = Int32.GetInstance(i); nf = new Int32Field("nf", i, Field.Store.NO); sf = new StoredField("nf", i); typeAnswer = NumericType.INT32; } else { long l = Random.NextInt64(); answer = Int64.GetInstance(l); nf = new Int64Field("nf", l, Field.Store.NO); sf = new StoredField("nf", l); typeAnswer = NumericType.INT64; } } doc.Add(nf); doc.Add(sf); answers[id] = answer; typeAnswers[id] = typeAnswer; FieldType ft = new FieldType(Int32Field.TYPE_STORED); ft.NumericPrecisionStep = int.MaxValue; doc.Add(new Int32Field("id", id, ft)); w.AddDocument(doc); } r = w.GetReader(); } // w.Dispose(); Assert.AreEqual(numDocs, r.NumDocs); foreach (AtomicReaderContext ctx in r.Leaves) { AtomicReader sub = ctx.AtomicReader; FieldCache.Int32s ids = FieldCache.DEFAULT.GetInt32s(sub, "id", false); for (int docID = 0; docID < sub.NumDocs; docID++) { Document doc = sub.Document(docID); Field f = doc.GetField <Field>("nf"); Assert.IsTrue(f is StoredField, "got f=" + f); #pragma warning disable 612, 618 Assert.AreEqual(answers[ids.Get(docID)], f.GetNumericValue()); #pragma warning restore 612, 618 } } } finally { r?.Dispose(); } }
private void CalcMomentary(List <Field> Fields, DateTime Now, ushort Raw) { Fields.Add(new Int32Field(this, Now, "Raw", Raw, FieldType.Momentary, FieldQoS.AutomaticReadout, typeof(Module).Namespace, 26)); if (this.exp is null && !string.IsNullOrEmpty(this.expression)) { this.exp = new Expression(this.expression); } if (this.exp != null) { Variables v = new Variables() { { "Raw", (double)Raw } }; object Value = this.exp.Evaluate(v); Field F; if (Value is double dbl) { F = new QuantityField(this, Now, this.fieldName, dbl, this.nrDecimals, this.unit, FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is PhysicalQuantity qty) { F = new QuantityField(this, Now, this.fieldName, qty.Magnitude, this.nrDecimals, qty.Unit.ToString(), FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is bool b) { F = new BooleanField(this, Now, this.fieldName, b, FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is DateTime DT) { F = new DateTimeField(this, Now, this.fieldName, DT, FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is Duration D) { F = new DurationField(this, Now, this.fieldName, D, FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is Enum E) { F = new EnumField(this, Now, this.fieldName, E, FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is int i32) { if (string.IsNullOrEmpty(this.unit)) { F = new Int32Field(this, Now, this.fieldName, i32, FieldType.Momentary, FieldQoS.AutomaticReadout); } else { F = new QuantityField(this, Now, this.fieldName, i32, 0, this.unit, FieldType.Momentary, FieldQoS.AutomaticReadout); } } else if (Value is long i64) { if (string.IsNullOrEmpty(this.unit)) { F = new Int64Field(this, Now, this.fieldName, i64, FieldType.Momentary, FieldQoS.AutomaticReadout); } else { F = new QuantityField(this, Now, this.fieldName, i64, 0, this.unit, FieldType.Momentary, FieldQoS.AutomaticReadout); } } else if (Value is string s) { F = new StringField(this, Now, this.fieldName, s, FieldType.Momentary, FieldQoS.AutomaticReadout); } else if (Value is TimeSpan TS) { F = new TimeField(this, Now, this.fieldName, TS, FieldType.Momentary, FieldQoS.AutomaticReadout); } else { F = new StringField(this, Now, this.fieldName, Value.ToString(), FieldType.Momentary, FieldQoS.AutomaticReadout); } if (this.fieldName == "Value") { F.Module = typeof(Module).Namespace; F.StringIdSteps = new LocalizationStep[] { new LocalizationStep(13) }; } Fields.Add(F); } }