protected void grdIndexFields_InsertCommand(object sender, GridCommandEventArgs e)
    {
        var editableItem = ((GridEditableItem)e.Item);
        //populate its properties
        Hashtable values = new Hashtable();
        editableItem.ExtractValues(values);

        RadComboBox combo = editableItem.FindControl("ddlFormFields") as RadComboBox;
        string ffID = combo.SelectedValue;

        GRASPEntities db = new GRASPEntities();

        //create new entity
        IndexField idx = new IndexField();
        idx.FormFieldID = Convert.ToDecimal(ffID);
        idx.IndexID = Convert.ToInt32(grdIndex.SelectedValue.ToString());

        db.IndexFields.Add(idx);
        try
        {
            //submit chanages to Db
            db.SaveChanges();
        }
        catch(System.Exception ex)
        {
            SetMessage(ex.Message);
        }
    }
        private IEnumerable <AbstractField> GetOrCreateNumericField(IndexField field, object value, Field.Store storage, Field.TermVector termVector = Field.TermVector.NO)
        {
            var fieldNameDouble = field.Name + Constants.Documents.Indexing.Fields.RangeFieldSuffixDouble;
            var fieldNameLong   = field.Name + Constants.Documents.Indexing.Fields.RangeFieldSuffixLong;

            var numericFieldDouble = GetNumericFieldFromCache(fieldNameDouble, null, storage, termVector);
            var numericFieldLong   = GetNumericFieldFromCache(fieldNameLong, null, storage, termVector);

            switch (BlittableNumber.Parse(value, out double doubleValue, out long longValue))
            {
Beispiel #3
0
        public void Convert_select_many_will_keep_doc_id()
        {
            var indexDefinition = new IndexDefinitionBuilder <Order>
            {
                Map = orders => from order in orders
                      from line in order.OrderLines
                      select new { line.ProductId }
#pragma warning disable CS0618 // Type or member is obsolete
            }.ToIndexDefinition(new DocumentConventions {
                PrettifyGeneratedLinqExpressions = false
            });

#pragma warning restore CS0618 // Type or member is obsolete

            indexDefinition.Name = "Index1";
            var index = IndexCompiler.Compile(indexDefinition);

            var map = index.Maps.Values.First().First();

            using (var context = JsonOperationContext.ShortTermSingleUse())
            {
                var results = map(new[]
                {
                    GetDocumentFromString(
                        @"
                {
                    '@metadata': {'@collection': 'Orders', '@id': 1},
                    'OrderLines': [{'ProductId': 2}, {'ProductId': 3}]
                }".Replace("\r\n", Environment.NewLine), context),
                    GetDocumentFromString(
                        @"
                {
                    '@metadata': {'@collection': 'Orders', '@id': 2},
                    'OrderLines': [{'ProductId': 5}, {'ProductId': 4}]
                }".Replace("\r\n", Environment.NewLine), context)
                }).Cast <object>().ToArray();

                var fields = index.OutputFields
                             .Select(x => IndexField.Create(x, new IndexFieldOptions(), null))
                             .ToList();

                var converter = new AnonymousLuceneDocumentConverter(fields, false);

                foreach (var result in results)
                {
                    using (var lazyStringValue = context.GetLazyString("docs/1"))
                    {
                        bool shouldSkip;
                        converter.SetDocument(lazyStringValue, result, context, out shouldSkip);
                        Assert.Equal("docs/1", converter.Document.Get(Constants.Documents.Indexing.Fields.DocumentIdFieldName, null));
                    }
                }
            }
        }
        private IEnumerable <AbstractField> GetOrCreateNumericField(IndexField field, object value, Field.Store storage, Field.TermVector termVector = Field.TermVector.NO)
        {
            var fieldName = field.Name + Constants.Indexing.Fields.RangeFieldSuffix;

            var cacheKey = new FieldCacheKey(field.Name, null, storage, termVector,
                                             _multipleItemsSameFieldCount.ToArray());

            NumericField numericField;
            CachedFieldItem <NumericField> cached;

            if (_numericFieldsCache.TryGetValue(cacheKey, out cached) == false)
            {
                _numericFieldsCache[cacheKey] = cached = new CachedFieldItem <NumericField>
                {
                    Field = numericField = new NumericField(CreateFieldName(fieldName), storage, true)
                };
            }
            else
            {
                numericField = cached.Field;
            }

            double doubleValue;
            long   longValue;

            switch (BlittableNumber.Parse(value, out doubleValue, out longValue))
            {
            case NumberParseResult.Double:
                if (field.SortOption == SortOptions.NumericLong)
                {
                    yield return(numericField.SetLongValue((long)doubleValue));
                }
                else
                {
                    yield return(numericField.SetDoubleValue(doubleValue));
                }
                break;

            case NumberParseResult.Long:
                if (field.SortOption == SortOptions.NumericDouble)
                {
                    yield return(numericField.SetDoubleValue(longValue));
                }
                else
                {
                    yield return(numericField.SetLongValue(longValue));
                }
                break;
            }
        }
        public void IndexDoc_Security_CannotAddPasswordHash()
        {
            var passwordHashFieldName = "PasswordHash";
            var passwordHashField     = new IndexField(passwordHashFieldName, "31275491872354956198543",
                                                       IndexingMode.NotAnalyzed, IndexStoringMode.No, IndexTermVector.No);
            var indexDoc = new IndexDocument {
                passwordHashField
            };

            Assert.IsFalse(indexDoc.Any(f => f.Name == passwordHashFieldName));
            Assert.IsNull(indexDoc.GetStringValue(passwordHashFieldName));

            Assert.IsFalse(indexDoc.Fields.ContainsKey(passwordHashFieldName));
        }
Beispiel #6
0
        protected override void OnProcessOutputSchema(MutableObject newSchema)
        {
            // We don't modify the input schema in adapters... We may derive values from input schemas, but adapters always send a novel schema...

            var oneMutable = TurnSubmissionIntoMutable(new SubmissionScore(), new TeamScores(), Color.magenta);

            var mutableCollection = new List <MutableObject> {
                oneMutable
            };

            ScoreTarget.SetValue(mutableCollection, newSchema);
            IndexField.SetValue(1, newSchema);

            Router.TransmitAllSchema(newSchema);
        }
Beispiel #7
0
        public bool ContainsField(string field)
        {
            if (field == Constants.Indexing.Fields.DocumentIdFieldName)
            {
                return(_index.Type.IsMap());
            }

            if (field.EndsWith(Constants.Indexing.Fields.RangeFieldSuffix))
            {
                field = field.Substring(0, field.Length - 6);
            }

            field = IndexField.ReplaceInvalidCharactersInFieldName(field);

            return(_fields.ContainsKey(field));
        }
Beispiel #8
0
        public void InMemoryDatabaseGenerator_IndexField_DefaultFlags()
        {
            var field = new IndexField("FieldName", "value", IndexingMode.Analyzed, IndexStoringMode.No,
                                       IndexTermVector.No);

            Assert.AreEqual("FieldName:value:S", field.ToString());

            var parsed = IndexField.Parse(field.ToString(), false);

            Assert.AreEqual(field.Name, parsed.Name);
            Assert.AreEqual(field.Type, parsed.Type);
            Assert.AreEqual(field.ValueAsString, parsed.ValueAsString);
            Assert.AreEqual(IndexingMode.Default, parsed.Mode);
            Assert.AreEqual(IndexStoringMode.Default, parsed.Store);
            Assert.AreEqual(IndexTermVector.Default, parsed.TermVector);
        }
Beispiel #9
0
        public void InMemoryDatabaseGenerator_IndexField_AllFlags_Stored()
        {
            var field = new IndexField("FieldName", "value", IndexingMode.No, IndexStoringMode.Yes,
                                       IndexTermVector.WithPositions);

            Assert.AreEqual("IM3,TV3,FieldName:value:S", field.ToString(true));

            var parsed = IndexField.Parse(field.ToString(), true);

            Assert.AreEqual(field.Name, parsed.Name);
            Assert.AreEqual(field.Type, parsed.Type);
            Assert.AreEqual(field.ValueAsString, parsed.ValueAsString);
            Assert.AreEqual(field.Mode, parsed.Mode);
            Assert.AreEqual(field.Store, parsed.Store);
            Assert.AreEqual(field.TermVector, parsed.TermVector);
        }
Beispiel #10
0
        private static Sort GetSort(SortedField[] sortedFields)
        {
            if (sortedFields == null || sortedFields.Length == 0)
            {
                return(null);
            }

            return(new Sort(sortedFields.Select(x =>
            {
                var sortOptions = SortOptions.String;

                if (x.Field == Constants.Indexing.Fields.IndexFieldScoreName)
                {
                    return SortField.FIELD_SCORE;
                }

                if (InvariantCompare.IsPrefix(x.Field, Constants.Indexing.Fields.AlphaNumericFieldName, CompareOptions.None))
                {
                    var customFieldName = SortFieldHelper.ExtractName(x.Field);
                    if (customFieldName.IsNullOrWhiteSpace())
                    {
                        throw new InvalidOperationException("Alphanumeric sort: cannot figure out what field to sort on!");
                    }

                    var anSort = new AlphaNumericComparatorSource();
                    return new SortField(customFieldName, anSort, x.Descending);
                }

                if (InvariantCompare.IsPrefix(x.Field, Constants.Indexing.Fields.RandomFieldName, CompareOptions.None))
                {
                    var customFieldName = SortFieldHelper.ExtractName(x.Field);
                    if (customFieldName.IsNullOrWhiteSpace()) // truly random
                    {
                        return new RandomSortField(Guid.NewGuid().ToString());
                    }

                    return new RandomSortField(customFieldName);
                }

                if (InvariantCompare.IsSuffix(x.Field, Constants.Indexing.Fields.RangeFieldSuffix, CompareOptions.None))
                {
                    sortOptions = SortOptions.NumericDouble; // TODO arek - it seems to be working fine with long values as well however needs to be verified
                }

                return new SortField(IndexField.ReplaceInvalidCharactersInFieldName(x.Field), (int)sortOptions, x.Descending);
            }).ToArray()));
        }
Beispiel #11
0
        public void IndexDoc_Security_CannotAddPassword()
        {
            var passwordFieldName = "Password";
            var passwordField     = new IndexField(passwordFieldName, "password123",
                                                   IndexingMode.NotAnalyzed, IndexStoringMode.No, IndexTermVector.No);
            var indexDoc = new IndexDocument {
                passwordField
            };

            Assert.IsFalse(indexDoc.Any(f => f.Name == passwordFieldName));
            Assert.IsNull(indexDoc.GetStringValue(passwordFieldName));

            var indexDocAcc = new ObjectAccessor(indexDoc);
            var fields      = (Dictionary <string, IndexField>)indexDocAcc.GetFieldOrProperty("_fields");

            Assert.IsFalse(fields.ContainsKey(passwordFieldName));
        }
Beispiel #12
0
        public void IndexDoc_Security_CannotAddPasswordHash()
        {
            var passwordHashFieldName = "PasswordHash";
            var passwordHashField     = new IndexField(passwordHashFieldName, "31275491872354956198543",
                                                       IndexingMode.NotAnalyzed, IndexStoringMode.No, IndexTermVector.No);
            var indexDoc = new IndexDocument {
                passwordHashField
            };

            Assert.IsFalse(indexDoc.Any(f => f.Name == passwordHashFieldName));
            Assert.IsNull(indexDoc.GetStringValue(passwordHashFieldName));

            var indexDocAcc = new PrivateObject(indexDoc);
            var fields      = (Dictionary <string, IndexField>)indexDocAcc.GetFieldOrProperty("_fields");

            Assert.IsFalse(fields.ContainsKey(passwordHashFieldName));
        }
        public CreateIndexParams(string indexName, DbDoc indexDefinition)
        {
            this._indexName = indexName;

            if (indexDefinition.values.ContainsKey("type"))
            {
                this._type = indexDefinition.values["type"].ToString();
            }

            // Read fields from the indexDefinition object.
            foreach (var item in indexDefinition.values["fields"] as Object[])
            {
                var field = item as Dictionary <string, object>;
                if (field == null)
                {
                    continue;
                }

                var fieldValue = field["field"] is MySqlExpression ? ((MySqlExpression)field["field"]).value : field["field"].ToString();
                var indexField = new IndexField()
                {
                    Field = fieldValue
                };
                if (field.ContainsKey("type"))
                {
                    indexField.Type = field["type"].ToString();
                }

                if (field.ContainsKey("required"))
                {
                    indexField.Required = Convert.ToBoolean(field["required"]);
                }

                if (field.ContainsKey("options"))
                {
                    indexField.Options = Convert.ToUInt32(field["options"]);
                }

                if (field.ContainsKey("srid"))
                {
                    indexField.Srid = Convert.ToUInt32(field["srid"]);
                }

                _fields.Add(indexField);
            }
        }
Beispiel #14
0
        //[TestMethod]
        //[TestCategory("CloudSearch")]
        public void TestIndexDocuments()
        {
            var domainName = generateDomainName();
            var indexName  = "netsdkindex" + DateTime.Now.Ticks.ToString();

            Client.CreateDomain(new CreateDomainRequest {
                DomainName = domainName
            });

            var indexField = new IndexField
            {
                IndexFieldName = indexName,
                IndexFieldType = IndexFieldType.Literal
            };

            try
            {
                Client.DefineIndexField(new DefineIndexFieldRequest {
                    DomainName = domainName, IndexField = indexField
                });

                var status = Client.DescribeDomains(new DescribeDomainsRequest {
                    DomainNames = { domainName }
                }).DomainStatusList[0].RequiresIndexDocuments;
                Assert.IsTrue(status);

                Client.IndexDocuments(new IndexDocumentsRequest {
                    DomainName = domainName
                });

                var req = new DescribeDomainsRequest {
                    DomainNames = { domainName }
                };

                Assert.IsTrue(Client.DescribeDomains(req).DomainStatusList[0].Processing);
            }
            finally
            {
                Client.DeleteDomain(new DeleteDomainRequest {
                    DomainName = domainName
                });
            }
        }
            /// <summary>Returns with a parseable value.</summary>
            private string GetFieldValueAsString(IndexField field)
            {
                if (field == null)
                {
                    return(null);
                }

                switch (field.Type)
                {
                case IndexValueType.String:
                    return(field.StringValue);

                case IndexValueType.StringArray:
                    throw new NotImplementedException();

                case IndexValueType.Bool:
                    return(field.BooleanValue ? IndexValue.Yes : IndexValue.No);

                case IndexValueType.Int:
                    return(field.IntegerValue.ToString(CultureInfo.InvariantCulture));

                case IndexValueType.IntArray:
                    throw new NotImplementedException();

                case IndexValueType.Long:
                    return(field.LongValue.ToString(CultureInfo.InvariantCulture));

                case IndexValueType.Float:
                    return(field.SingleValue.ToString(CultureInfo.InvariantCulture));

                case IndexValueType.Double:
                    return(field.DoubleValue.ToString(CultureInfo.InvariantCulture));

                case IndexValueType.DateTime:
                    return(field.DateTimeValue.ToString("yyyy-MM-dd HH:mm:ss.ffff"));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        private static IndexField[] GetFields(IndexDefinition definition, string[] outputFields)
        {
            IndexFieldOptions allFields;

            definition.Fields.TryGetValue(Constants.Indexing.Fields.AllFields, out allFields);

            var result = definition.Fields
                         .Where(x => x.Key != Constants.Indexing.Fields.AllFields)
                         .Select(x => IndexField.Create(x.Key, x.Value, allFields)).ToList();

            foreach (var outputField in outputFields)
            {
                if (definition.Fields.ContainsKey(outputField))
                {
                    continue;
                }

                result.Add(IndexField.Create(outputField, new IndexFieldOptions(), allFields));
            }

            return(result.ToArray());
        }
Beispiel #17
0
        protected LuceneDocumentConverterBase(ICollection <IndexField> fields, bool reduceOutput = false)
        {
            var dictionary = new Dictionary <string, IndexField>(fields.Count, default(OrdinalStringStructComparer));

            foreach (var field in fields)
            {
                dictionary[field.Name] = field;
            }
            _fields = dictionary;

            if (_fields.TryGetValue(Constants.Documents.Indexing.Fields.AllFields, out _allFields) == false)
            {
                _allFields = new IndexField();
            }

            _reduceOutput = reduceOutput;

            if (reduceOutput)
            {
                _reduceValueBuffer = new byte[0];
            }
        }
Beispiel #18
0
        protected IEnumerable <AbstractField> CreateField(string name, object value, CreateFieldOptions options)
        {
            // IMPORTANT: Do not delete this method, it is used by the indexes code when using CreateField

            options = options ?? CreateFieldOptions.Default;

            IndexFieldOptions allFields = null;
            var scope = CurrentIndexingScope.Current;

            if (scope.IndexDefinition is MapIndexDefinition mapIndexDefinition)
            {
                mapIndexDefinition.IndexDefinition.Fields.TryGetValue(Constants.Documents.Indexing.Fields.AllFields, out allFields);
            }

            var field = IndexField.Create(name, new IndexFieldOptions
            {
                Storage    = options.Storage,
                TermVector = options.TermVector,
                Indexing   = options.Indexing
            }, allFields);

            if (scope.DynamicFields == null)
            {
                scope.DynamicFields = new Dictionary <string, FieldIndexing>();
            }

            scope.DynamicFields[name] = field.Indexing;

            if (scope.CreateFieldConverter == null)
            {
                scope.CreateFieldConverter = new LuceneDocumentConverter(new IndexField[] { });
            }

            using var i = scope.CreateFieldConverter.NestedField(scope.CreatedFieldsCount++);
            var result = new List <AbstractField>();

            scope.CreateFieldConverter.GetRegularFields(new StaticIndexLuceneDocumentWrapper(result), field, value, CurrentIndexingScope.Current.IndexContext, out _);
            return(result);
        }
Beispiel #19
0
        protected IEnumerable <AbstractField> CreateField(string name, object value, bool stored = false, bool?analyzed = null)
        {
            // IMPORTANT: Do not delete this method, it is used by the indexes code when using LoadDocument
            FieldIndexing?index;

            switch (analyzed)
            {
            case true:
                index = FieldIndexing.Search;
                break;

            case false:
                index = FieldIndexing.Exact;
                break;

            default:
                index = null;
                break;
            }

            var field = IndexField.Create(name, new IndexFieldOptions
            {
                Storage    = stored ? FieldStorage.Yes : FieldStorage.No,
                TermVector = FieldTermVector.No,
                Indexing   = index
            }, null);

            if (_createFieldsConverter == null)
            {
                _createFieldsConverter = new LuceneDocumentConverter(new IndexField[] { });
            }

            var result = new List <AbstractField>();

            _createFieldsConverter.GetRegularFields(new StaticIndexLuceneDocumentWrapper(result), field, value, CurrentIndexingScope.Current.IndexContext);
            return(result);
        }
Beispiel #20
0
        private VisualPayload ParseData()
        {
            //var randomGen = new Random(1337);

            var mutablesList = new List <MutableObject>();

            foreach (var team in ScoreFromJsonFilter.LoadedTeams)
            {
                //var teamColor = ColorUtility.HsvtoRgb((float)randomGen.NextDouble(), .8f, 1f);

                var teamColor = TeamColorPalette.ColorFromIndex(team.TeamID);

                foreach (var entry in team.SubmissionScores)
                {
                    var newMutable = TurnSubmissionIntoMutable(entry, team, teamColor);

                    mutablesList.Add(newMutable);
                }
            }

            ScoreTarget.SetValue(mutablesList, Payload.Data);

            var groupId = GroupId.GetFirstValue(Payload.Data);

            var index = (DataShare.ContainsKey(groupId)
                ? DataShare[groupId]
                : 0);

            if (groupId != "")
            {
                DataShare[groupId] = index + 1;
            }

            IndexField.SetValue(index, Payload.Data);

            return(Payload);
        }
Beispiel #21
0
        /// <summary>
        /// Creates an <see cref="IIndexCriteria"/>.
        /// </summary>
        /// <param name="set">
        /// The set.
        /// </param>
        /// <param name="indexFieldNames">
        /// The index field names.
        /// </param>
        /// <param name="indexFieldPolicies">
        /// The index field policies.
        /// </param>
        /// <returns>
        /// The <see cref="IIndexCriteria"/>.
        /// </returns>
        internal static IIndexCriteria ToIndexCriteria(this IndexSet set, IEnumerable<string> indexFieldNames, IEnumerable<StaticField> indexFieldPolicies)
        {
            if (set.IndexAttributeFields.Count == 0)
            {
                foreach (var fn in indexFieldNames)
                {
                    var field = new IndexField() {Name = fn};
                    var policy = indexFieldPolicies.FirstOrDefault(x => x.Name == fn);
                    if (policy != null)
                    {
                        field.Type = policy.Type;
                        field.EnableSorting = policy.EnableSorting;
                    }
                    set.IndexAttributeFields.Add(field);
                }
            }

            return new IndexCriteria(
                set.IndexAttributeFields.Cast<IIndexField>().ToArray(),
                set.IndexUserFields.Cast<IIndexField>().ToArray(),
                set.IncludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                set.ExcludeNodeTypes.ToList().Select(x => x.Name).ToArray(),
                set.IndexParentId);
        }
        private static Analyzer GetAnalyzer(string name, IndexField field, bool forQuerying)
        {
            if (string.IsNullOrWhiteSpace(field.Analyzer))
            {
                return(null);
            }

            var analyzerInstance = IndexingExtensions.CreateAnalyzerInstance(name, field.Analyzer);

            if (forQuerying)
            {
                var analyzerType = analyzerInstance.GetType();

                var notForQuerying = NotForQuerying
                                     .GetOrAdd(analyzerType, t => analyzerInstance.GetType().GetTypeInfo().GetCustomAttributes <NotForQueryingAttribute>(false).Any());

                if (notForQuerying)
                {
                    return(null);
                }
            }

            return(analyzerInstance);
        }
        /// <summary>
        /// Ensures that the'_searchEmail' is added to the user fields so that it is indexed - without having to modify the config
        /// </summary>
        /// <param name="indexSet"></param>
        /// <returns></returns>
        protected override IIndexCriteria GetIndexerData(IndexSet indexSet)
        {
            if (CanInitialize())
            {
                //Add a custom _searchEmail to the index criteria no matter what is in config
                var field = new IndexField {
                    Name = "_searchEmail"
                };
                StaticField policy;
                if (IndexFieldPolicies.TryGetValue("_searchEmail", out policy))
                {
                    field.Type          = policy.Type;
                    field.EnableSorting = policy.EnableSorting;
                }

                return(indexSet.ToIndexCriteria(DataService, IndexFieldPolicies,
                                                //add additional explicit fields
                                                new [] { field }));
            }
            else
            {
                return(base.GetIndexerData(indexSet));
            }
        }
 public static IndexField IsRetrievable(this IndexField field, bool value = true)
 {
     field.Retrievable = value;
     return(field);
 }
 public static IndexField IsKey(this IndexField field, bool value = true)
 {
     field.Key = value;
     return(field);
 }
 public static IndexField IsFacetable(this IndexField field, bool value = true)
 {
     field.Facetable = value;
     return(field);
 }
Beispiel #27
0
        private static JsValue TryDetectDynamicFieldCreation(string property, ObjectInstance valueAsObject, IndexField field)
        {
            //We have a field creation here _ = {"$value":val, "$name","$options":{...}}
            if (!valueAsObject.HasOwnProperty(CreatedFieldValuePropertyName) ||
                !valueAsObject.HasOwnProperty(CreatedFieldNamePropertyName))
            {
                return(null);
            }

            var value        = valueAsObject.GetOwnProperty(CreatedFieldValuePropertyName).Value;
            var fieldNameObj = valueAsObject.GetOwnProperty(CreatedFieldNamePropertyName).Value;

            if (fieldNameObj.IsString() == false)
            {
                throw new ArgumentException($"Dynamic field {property} is expected to have a string {CreatedFieldNamePropertyName} property but got {fieldNameObj}");
            }


            field.Name = fieldNameObj.AsString();

            if (valueAsObject.HasOwnProperty(CreatedFieldOptionsPropertyName))
            {
                var options = valueAsObject.GetOwnProperty(CreatedFieldOptionsPropertyName).Value;
                if (options.IsObject() == false)
                {
                    throw new ArgumentException($"Dynamic field {property} is expected to contain an object with three properties " +
                                                $"{CreatedFieldOptionsPropertyName}, {CreatedFieldNamePropertyName} and {CreatedFieldOptionsPropertyName} the later should be a valid IndexFieldOptions object.");
                }

                var optionObj = options.AsObject();
                foreach (var kvp in optionObj.GetOwnProperties())
                {
                    var optionValue = kvp.Value.Value;
                    if (optionValue.IsUndefined() || optionValue.IsNull())
                    {
                        continue;
                    }

                    var propertyName = kvp.Key;
                    if (string.Equals(propertyName, nameof(CreateFieldOptions.Indexing), StringComparison.OrdinalIgnoreCase))
                    {
                        field.Indexing = GetEnum <FieldIndexing>(optionValue, propertyName);

                        continue;
                    }

                    if (string.Equals(propertyName, nameof(CreateFieldOptions.Storage), StringComparison.OrdinalIgnoreCase))
                    {
                        if (optionValue.IsBoolean())
                        {
                            field.Storage = optionValue.AsBoolean()
                                ? FieldStorage.Yes
                                : FieldStorage.No;
                        }
                        else
                        {
                            field.Storage = GetEnum <FieldStorage>(optionValue, propertyName);
                        }

                        continue;
                    }

                    if (string.Equals(propertyName, nameof(CreateFieldOptions.TermVector), StringComparison.OrdinalIgnoreCase))
                    {
                        field.TermVector = GetEnum <FieldTermVector>(optionValue, propertyName);

                        continue;
                    }
                }
            }

            return(value);

            TEnum GetEnum <TEnum>(JsValue optionValue, string propertyName)
            {
                if (optionValue.IsString() == false)
                {
                    throw new ArgumentException($"Could not parse dynamic field option property '{propertyName}' value ('{optionValue}') because it is not a string.");
                }

                var optionValueAsString = optionValue.AsString();

                if (Enum.TryParse(typeof(TEnum), optionValueAsString, true, out var enumValue) == false)
                {
                    throw new ArgumentException($"Could not parse dynamic field option property '{propertyName}' value ('{optionValueAsString}') into '{typeof(TEnum).Name}' enum.");
                }

                return((TEnum)enumValue);
            }
        }
Beispiel #28
0
        protected override int GetFields <T>(T instance, LazyStringValue key, object document, JsonOperationContext indexContext, IWriteOperationBuffer writeBuffer)
        {
            if (!(document is ObjectInstance documentToProcess))
            {
                return(0);
            }

            int newFields = 0;

            if (key != null)
            {
                instance.Add(GetOrCreateKeyField(key));
                newFields++;
            }

            if (_reduceOutput)
            {
                var reduceResult = JsBlittableBridge.Translate(indexContext,
                                                               documentToProcess.Engine,
                                                               documentToProcess);

                instance.Add(GetReduceResultValueField(reduceResult, writeBuffer));
                newFields++;
            }

            foreach (var(property, propertyDescriptor) in documentToProcess.GetOwnProperties())
            {
                if (_fields.TryGetValue(property, out var field) == false)
                {
                    field = _fields[property] = IndexField.Create(property, new IndexFieldOptions(), _allFields);
                }

                object value;
                var    actualValue = propertyDescriptor.Value;
                if (actualValue.IsObject() && actualValue.IsArray() == false)
                {
                    //In case TryDetectDynamicFieldCreation finds a dynamic field it will populate 'field.Name' with the actual property name
                    //so we must use field.Name and not property from this point on.
                    var val = TryDetectDynamicFieldCreation(property, actualValue.AsObject(), field);
                    if (val != null)
                    {
                        if (val.IsObject() && val.AsObject().TryGetValue("$spatial", out _))
                        {
                            actualValue = val; //Here we populate the dynamic spatial field that will be handled below.
                        }
                        else
                        {
                            value      = TypeConverter.ToBlittableSupportedType(val, flattenArrays: false, forIndexing: true, engine: documentToProcess.Engine, context: indexContext);
                            newFields += GetRegularFields(instance, field, value, indexContext, out _);
                            continue;
                        }
                    }

                    var objectValue = actualValue.AsObject();
                    if (objectValue.HasOwnProperty("$spatial") && objectValue.TryGetValue("$spatial", out var inner))
                    {
                        SpatialField spatialField;
                        IEnumerable <AbstractField> spatial;
                        if (inner.IsString())
                        {
                            spatialField = StaticIndexBase.GetOrCreateSpatialField(field.Name);
                            spatial      = StaticIndexBase.CreateSpatialField(spatialField, inner.AsString());
                        }
                        else if (inner.IsObject())
                        {
                            var innerObject = inner.AsObject();
                            if (innerObject.HasOwnProperty("Lat") && innerObject.HasOwnProperty("Lng") && innerObject.TryGetValue("Lat", out var lat) &&
                                lat.IsNumber() && innerObject.TryGetValue("Lng", out var lng) && lng.IsNumber())
                            {
                                spatialField = StaticIndexBase.GetOrCreateSpatialField(field.Name);
                                spatial      = StaticIndexBase.CreateSpatialField(spatialField, lat.AsNumber(), lng.AsNumber());
                            }
                            else
                            {
                                continue; //Ignoring bad spatial field
                            }
                        }
                        else
                        {
                            continue; //Ignoring bad spatial field
                        }
                        newFields += GetRegularFields(instance, field, spatial, indexContext, out _);

                        continue;
                    }
                }

                value      = TypeConverter.ToBlittableSupportedType(propertyDescriptor.Value, flattenArrays: false, forIndexing: true, engine: documentToProcess.Engine, context: indexContext);
                newFields += GetRegularFields(instance, field, value, indexContext, out _);

                if (value is IDisposable toDispose)
                {
                    // the value was converted to a lucene field and isn't needed anymore
                    toDispose.Dispose();
                }
            }

            return(newFields);
        }
        /// <summary>
        /// This method generate the fields for indexing documents in lucene from the values.
        /// Given a name and a value, it has the following behavior:
        /// * If the value is enumerable, index all the items in the enumerable under the same field name
        /// * If the value is null, create a single field with the supplied name with the unanalyzed value 'NULL_VALUE'
        /// * If the value is string or was set to not analyzed, create a single field with the supplied name
        /// * If the value is date, create a single field with millisecond precision with the supplied name
        /// * If the value is numeric (int, long, double, decimal, or float) will create two fields:
        ///		1. with the supplied name, containing the numeric value as an unanalyzed string - useful for direct queries
        ///		2. with the name: name +'_Range', containing the numeric value in a form that allows range queries
        /// </summary>
        public int GetRegularFields<T>(T instance, IndexField field, object value, JsonOperationContext indexContext, out bool shouldSkip, bool nestedArray = false) where T : ILuceneDocumentWrapper
        {
            var path = field.Name;

            var valueType = GetValueType(value);

            Field.Index defaultIndexing;
            switch (valueType)
            {
                case ValueType.LazyString:
                case ValueType.LazyCompressedString:
                case ValueType.String:
                case ValueType.Enum:
                    defaultIndexing = Field.Index.ANALYZED;
                    break;

                case ValueType.DateTime:
                case ValueType.DateTimeOffset:
                case ValueType.TimeSpan:
                case ValueType.Boolean:
                case ValueType.Double:
                case ValueType.Null:
                case ValueType.DynamicNull:
                case ValueType.EmptyString:
                case ValueType.Numeric:
                case ValueType.BlittableJsonObject:
                case ValueType.DynamicJsonObject:
                    defaultIndexing = Field.Index.NOT_ANALYZED_NO_NORMS;
                    break;

                default:
                    defaultIndexing = Field.Index.ANALYZED_NO_NORMS;
                    break;
            }

            var indexing = field.Indexing.GetLuceneValue(field.Analyzer, @default: defaultIndexing);
            var storage = field.Storage.GetLuceneValue();
            var termVector = field.TermVector.GetLuceneValue();

            shouldSkip = false;
            int newFields = 0;

            if (_reduceOutput && indexing == Field.Index.NO && storage == Field.Store.NO)
                return newFields;

            if (valueType == ValueType.Null)
            {
                instance.Add(GetOrCreateField(path, Constants.Documents.Indexing.Fields.NullValue, null, null, storage, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                newFields++;

                return newFields;
            }

            if (valueType == ValueType.DynamicNull)
            {
                var dynamicNull = (DynamicNullObject)value;
                if (dynamicNull.IsExplicitNull || _indexImplicitNull)
                {
                    instance.Add(GetOrCreateField(path, Constants.Documents.Indexing.Fields.NullValue, null, null, storage, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                    newFields++;
                }

                shouldSkip = newFields == 0;
                return newFields;
            }

            if (valueType == ValueType.EmptyString)
            {
                instance.Add(GetOrCreateField(path, Constants.Documents.Indexing.Fields.EmptyString, null, null, storage, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.String)
            {
                string stringValue = value as string ?? value.ToString();

                instance.Add(GetOrCreateField(path, stringValue, null, null, storage, indexing, termVector));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.LazyString || valueType == ValueType.LazyCompressedString)
            {
                LazyStringValue lazyStringValue;
                if (valueType == ValueType.LazyCompressedString)
                    lazyStringValue = ((LazyCompressedStringValue)value).ToLazyStringValue();
                else
                    lazyStringValue = (LazyStringValue)value;

                instance.Add(GetOrCreateField(path, null, lazyStringValue, null, storage, indexing, termVector));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.Enum)
            {
                instance.Add(GetOrCreateField(path, value.ToString(), null, null, storage, indexing, termVector));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.Boolean)
            {
                instance.Add(GetOrCreateField(path, (bool)value ? TrueString : FalseString, null, null, storage, indexing, termVector));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.DateTime)
            {
                var dateTime = (DateTime)value;
                var dateAsString = dateTime.GetDefaultRavenFormat(isUtc: dateTime.Kind == DateTimeKind.Utc);

                instance.Add(GetOrCreateField(path, dateAsString, null, null, storage, indexing, termVector));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.DateTimeOffset)
            {
                var dateTimeOffset = (DateTimeOffset)value;

                string dateAsString;
                if (field.Indexing != FieldIndexing.Default && (indexing == Field.Index.NOT_ANALYZED || indexing == Field.Index.NOT_ANALYZED_NO_NORMS))
                    dateAsString = dateTimeOffset.ToString(DefaultFormat.DateTimeOffsetFormatsToWrite, CultureInfo.InvariantCulture);
                else
                    dateAsString = dateTimeOffset.UtcDateTime.GetDefaultRavenFormat(isUtc: true);

                instance.Add(GetOrCreateField(path, dateAsString, null, null, storage, indexing, termVector));
                newFields++;
                return newFields;
            }

            if (valueType == ValueType.TimeSpan)
            {
                var timeSpan = (TimeSpan)value;
                instance.Add(GetOrCreateField(path, timeSpan.ToString("c", CultureInfo.InvariantCulture), null, null, storage, indexing, termVector));

                foreach (var numericField in GetOrCreateNumericField(field, timeSpan.Ticks, storage, termVector))
                {
                    instance.Add(numericField);
                    newFields++;
                }

                return newFields;
            }

            if (valueType == ValueType.BoostedValue)
            {
                var boostedValue = (BoostedValue)value;

                int boostedFields = GetRegularFields(instance, field, boostedValue.Value, indexContext, out _);
                newFields += boostedFields;

                var fields = instance.GetFields();
                for (int idx = fields.Count - 1; boostedFields > 0; boostedFields--, idx--)
                {
                    var fieldFromCollection = fields[idx];
                    fieldFromCollection.Boost = boostedValue.Boost;
                    fieldFromCollection.OmitNorms = false;
                }

                return newFields;
            }

            int HandleArray(IEnumerable itemsToIndex)
            {
                int count = 1;

                if (nestedArray == false)
                {
                    instance.Add(GetOrCreateField(path + IsArrayFieldSuffix, TrueString, null, null, storage, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                    newFields++;
                }

                foreach (var itemToIndex in itemsToIndex)
                {
                    if (CanCreateFieldsForNestedArray(itemToIndex, field.Indexing) == false)
                        continue;

                    using var i = NestedField(count++);

                    newFields += GetRegularFields(instance, field, itemToIndex, indexContext, out _, nestedArray: true);
                }

                return newFields;
            }

            if (valueType == ValueType.Enumerable)
            {
                return HandleArray((IEnumerable)value);
            }

            int HandleObject(BlittableJsonReaderObject val)
            {
                if (val.TryGetMember("$values", out var values) &&
                    IsArrayOfTypeValueObject(val))
                {
                    return HandleArray((IEnumerable)values);
                }

                foreach (var complexObjectField in GetComplexObjectFields(path, val, storage, indexing, termVector))
                {
                    instance.Add(complexObjectField);
                    newFields++;
                }

                return newFields;
            }

            if (valueType == ValueType.DynamicJsonObject)
            {
                var dynamicJson = (DynamicBlittableJson)value;
                return HandleObject(dynamicJson.BlittableJson);
            }

            if (valueType == ValueType.BlittableJsonObject)
            {
                return HandleObject((BlittableJsonReaderObject)value);
            }

            if (valueType == ValueType.Lucene)
            {
                instance.Add((AbstractField)value);
                newFields++;

                return newFields;
            }

            if (valueType == ValueType.ConvertToJson)
            {
                var val = TypeConverter.ToBlittableSupportedType(value);
                if (!(val is DynamicJsonValue json))
                {
                    return GetRegularFields(instance, field, val, indexContext, out _, nestedArray);
                }

                foreach (var jsonField in GetComplexObjectFields(path, Scope.CreateJson(json, indexContext), storage, indexing, termVector))
                {
                    instance.Add(jsonField);
                    newFields++;
                }

                return newFields;
            }

            if (valueType == ValueType.Double)
            {
                var ldv = value as LazyNumberValue;
                if (ldv != null)
                {
                    if (TryToTrimTrailingZeros(ldv, indexContext, out var doubleAsString) == false)
                        doubleAsString = ldv.Inner;

                    instance.Add(GetOrCreateField(path, null, doubleAsString, null, storage, indexing, termVector));
                    newFields++;
                }
                else
                {
                    string s = null;
                    switch (value)
                    {
                        case double d:
                            s = d.ToString("G");
                            break;

                        case decimal dm:
                            s = dm.ToString("G");
                            break;

                        case float f:
                            s = f.ToString("G");
                            break;
                    }

                    instance.Add(GetOrCreateField(path, s, null, null, storage, indexing, termVector));
                    newFields++;
                }
            }
            else if (valueType == ValueType.Convertible) // we need this to store numbers in invariant format, so JSON could read them
            {
                instance.Add(GetOrCreateField(path, ((IConvertible)value).ToString(CultureInfo.InvariantCulture), null, null, storage, indexing, termVector));
                newFields++;
            }

            foreach (var numericField in GetOrCreateNumericField(field, value, storage))
            {
                instance.Add(numericField);
                newFields++;
            }

            return newFields;
        }
Beispiel #30
0
		public void AutoFillLinks(DataSource ds)
		{
			// Create Object's
			Link oLink;
			DataView dbLinkSchemas;
			Entity oTargetEntity = null;
			Index oTargetIndex = null;
			IndexField oTargetIndexField = null;
			LinkField oSourceLinkField = null;
			Boolean bIndexExists = false;

			Trace.Unindent();
				Trace.WriteLine(String.Format("Create Links from Entity \"{0}\"", this.Name));
			Trace.Indent();

			// Get Schemas
			dbLinkSchemas = GetDBLinkSchema(ds);

			// Lopping on Fields
			foreach (EntityField tmpField in this.Fields)
			{
				// Clear Flag
				bIndexExists = false;

				if (tmpField.KeyField) // PK
				{
					Trace.WriteLine(String.Format("Parsing PK \"{0}\"", tmpField.Name));

					// Filter Indexes
					dbLinkSchemas.RowFilter = String.Format("PK_COLUMN_NAME = '{0}' AND PK_TABLE_NAME = '{1}'", tmpField.DBColumn, this.DBEntityName);

					// Looping on FK's
					foreach (DataRowView tmpDataRowView in dbLinkSchemas)
					{
						Trace.WriteLine(String.Format("Parsing FK \"{0}\"", tmpDataRowView["FK_NAME"]));

						// Get Target Entity
						oTargetEntity = Project.CurrentProject.GetEntity(tmpDataRowView["FK_TABLE_NAME"].ToString());

						if (oTargetEntity == null)
						{
							Trace.WriteLine(String.Format("Entity for Table \"{0}\" not Found.", tmpDataRowView["FK_TABLE_NAME"]));
							continue;
						}

						// Check if the Link Alread Exists
						foreach (Link tmpLink in this.Links)
						{
							if (tmpLink.Fields.Count.Equals(1) && tmpLink.Fields[0].Name.Equals(tmpDataRowView["FK_COLUMN_NAME"].ToString()))
							{
								Trace.WriteLine(String.Format("Link por Field \"{0}\" Alread Exists", tmpField.Name));
								bIndexExists = true;
								break;
							}
						}

						if (bIndexExists) { break; }

						// Lopping on TargetEntity to Find the Correct Index
						foreach (Index tmpIndex in oTargetEntity.Indexes)
						{
							if (tmpIndex.Fields.Count.Equals(1) && tmpIndex.Fields[0].Name.EndsWith(tmpDataRowView["FK_COLUMN_NAME"].ToString()))
							{
								oTargetIndex = tmpIndex;
								break;
							}
						}

						// Check if Exists
						if (oTargetIndex == null)
						{
							Trace.WriteLine(String.Format("Creating Target Index for FK \"{0}\"", tmpDataRowView["FK_NAME"]));

							// Create Target Index
							oTargetIndex = new Index();
								oTargetIndex.SelectBy = true;
								oTargetIndex.DeleteBy = false;
								oTargetIndex.Name = tmpDataRowView["FK_COLUMN_NAME"].ToString();
								oTargetIndex.Unique = false;
								oTargetIndex.DBName = tmpDataRowView["FK_COLUMN_NAME"].ToString();
								oTargetIndex.PrimaryKey = false;

							// Create Target Index Field
							oTargetIndexField = new IndexField();
								oTargetIndexField.Name = tmpDataRowView["FK_COLUMN_NAME"].ToString();
								oTargetIndexField.PartialTextMatch = false;

							// Add Target Index Field on Target Index
							oTargetIndex.Fields.Add(oTargetIndexField);

							// Add Target Index on Target Entity
							oTargetEntity.Indexes.Add(oTargetIndex);
						}

						// Create Link
						oLink = new Link();
							oLink.TargetEntityName = oTargetEntity.Name;
							oLink.TargetIndexName = oTargetIndex.Name;
							oLink.IsCollection = true;
							oLink.IsProperty = true;
							oLink.ReadOnly = true;

						// Check if the Target Index is Unique
						if (oTargetIndex.Unique) // 1-N Relation
						{
							oLink.Name = oTargetEntity.Name; // N-M Relation
						}
						else { oLink.Name = oTargetEntity.PluralName; }
							
						// Check Delete Relation Action
						if (tmpDataRowView["DELETE_RULE"].ToString().Equals("NO ACTION"))
						{
							oLink.CascadeDelete = false;
						}
						else { oLink.CascadeUpdate = true; }

						// Check Update Relation Action
						if (tmpDataRowView["UPDATE_RULE"].ToString().Equals("NO ACTION"))
						{
							oLink.CascadeDelete = false;
						}
						else { oLink.CascadeUpdate = true; }

						// Create Link Field
						oSourceLinkField = new LinkField();
							oSourceLinkField.SourceFieldName = this.Fields.GetFieldFromDBColumn(tmpDataRowView["PK_COLUMN_NAME"].ToString()).Name;
							oSourceLinkField.TargetFieldName = oTargetEntity.Fields.GetFieldFromDBColumn(tmpDataRowView["FK_COLUMN_NAME"].ToString()).Name;

						// Add Link Field on Link
						oLink.Fields.Add(oSourceLinkField);

						// Add Link on Entity
						this.Links.Add(oLink);
					}

					if (bIndexExists) { continue; }
				}
			}
		}
Beispiel #31
0
 private void btnConfim_Click(object sender, EventArgs e)
 {
     IndexField fp = new IndexField();
     fp.Name = txtName.Text;
     fp.Caption = txtCaption.Text;
     fp.Boost = (float)numBoost.Value;
     fp.IsTitle = radioTitle.Checked;
     if (txtName.Enabled ==false)
        fpList.RemoveAt(lbFields.SelectedIndex);
     fpList.Insert(lbFields.SelectedIndex, fp);
     UpdateListData(true);
     EnableControls(btnAdd, btnEdit, btnDel, btnConfim, btnCancel);
     EnableControls(false);
 }
Beispiel #32
0
 public static Dictionary<IndexSet,Source> GetExcelSettings(string path)
 {
     if (SupportClass.FileUtil.IsFileExists(path) == false)
         throw new ArgumentException("path is not valid.", "path");
     DataTable table = ExcelLinker.GetDataTableFromFile(path);
     List<Source> sourceList = new Dictionary<IndexSet, Source>();
     string tableName = "",currentTableName;
     Source source=null;
     IndexSet indexSet=null;
     List<IndexField> fpList=new List<IndexField>();
     bool change=false;
     foreach (DataRow row in table.Rows)
     {
         IndexField fp=new IndexField();
         fp.Visible = true;
         fp.Order = 0;
         foreach (DataColumn column in table.Columns)
         {
             System.Console.Write(row[column] + "\t");
             if (column.ColumnName.Equals("Table"))
             {
                 currentTableName = row[column].ToString();
                 if (currentTableName != tableName)
                 {
                     if (source != null && indexSet != null)
                     {
                         source.Fields=fpList;
                         if (dict.ContainsKey(indexSet) == false)
                         {
                             dict.Add(indexSet, source);
                             IndexSet newIndexSet =new IndexSet(indexSet);
                             Source newSource = new Source(source);
                             newIndexSet.IndexName = Config.IndexPrefix + newIndexSet.IndexName;
                             newIndexSet.SourceName = Config.SourcePrefix + newIndexSet.SourceName;
                             newIndexSet.Type = IndexTypeEnum.Increment;
                             newSource.SourceName = Config.SourcePrefix + newSource.SourceName;
                             newSource.Query = newSource.Query + " where SearchLabel=1";
                             dict.Add(newIndexSet, newSource);
                         }
                     }
                     tableName = currentTableName;
                     fpList = new List<IndexField>();
                     source = new Source();
                     indexSet = new IndexSet();
                     source.SourceName = row[column].ToString();
                     source.Query = "select * from " + row[column].ToString();
                     indexSet.IndexName = row[column].ToString();
                     indexSet.SourceName = row[column].ToString();
                     indexSet.Path = @"D:\IndexData\" + indexSet.IndexName;
                     change =true;
                 }
                 else
                 {
                     change =false;
                 }
             }
             else if (column.ColumnName.Equals("TableCaption"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     indexSet.Caption = row[column].ToString();
             }
             else if (column.ColumnName.Equals("DbType"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.DBType = ISUtils.Common.DbType.GetDbType(row[column].ToString());
             }
             else if (column.ColumnName.Equals("HostName"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.HostName = row[column].ToString();
             }
             else if (column.ColumnName.Equals("DataBase"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.DataBase = row[column].ToString();
             }
             else if (column.ColumnName.Equals("UserName"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.UserName = row[column].ToString();
             }
             else if (column.ColumnName.Equals("Password"))
             {
                 if (change && string.IsNullOrEmpty(row[column].ToString()) == false)
                     source.Password = row[column].ToString();
             }
             else if (column.ColumnName.Equals("Field"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                     fp.Name = row[column].ToString();
             }
             else if (column.ColumnName.Equals("Caption"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                     fp.Caption = row[column].ToString();
             }
             else if (column.ColumnName.Equals("IsTitle"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     if (row[column].Equals("标题"))
                     {
                         fp.IsTitle=true;
                     }
                     else if (row[column].Equals("内容"))
                     {
                         fp.IsTitle =false;
                     }
                     else 
                     {
                         try
                         {
                             fp.IsTitle =bool.Parse(row[column].ToString());
                         }
                         catch(Exception)
                         {
                             fp.IsTitle =false;
                         }
                     }
                 }
             }
             else if (column.ColumnName.Equals("Boost"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     try
                     {
                         fp.Boost = float.Parse(row[column].ToString());
                     }
                     catch (Exception)
                     {
                         fp.Boost = 1.0f;
                     }
                 }
             }
             else if (column.ColumnName.Equals("Order"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     try
                     {
                         fp.Order = int.Parse(row[column].ToString());
                     }
                     catch (Exception)
                     {
                         fp.Order = 0;
                     }
                 }
             }
             else if (column.ColumnName.Equals("PK"))
             {
                 if (string.IsNullOrEmpty(row[column].ToString()) == false)
                 {
                     try
                     {
                         source.PrimaryKey=row[column].ToString();
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
             else
             { 
             }
         }
         fpList.Add(fp);
         System.Console.WriteLine();
     }
     if (source != null && indexSet != null)
     {
         source.Fields = fpList;
         if (dict.ContainsKey(indexSet) == false)
         {
             dict.Add(indexSet, source);
             IndexSet newIndexSet = new IndexSet(indexSet);
             Source newSource = new Source(source);
             newIndexSet.IndexName = Config.IndexPrefix + newIndexSet.IndexName;
             newIndexSet.SourceName = Config.SourcePrefix + newIndexSet.SourceName;
             newIndexSet.Type = IndexTypeEnum.Increment;
             newSource.SourceName = Config.SourcePrefix + newSource.SourceName;
             newSource.Query = newSource.Query + " where SearchLabel=1";
             dict.Add(newIndexSet, newSource);
         }
     }
     return dict;
 }
Beispiel #33
0
 public override DateTime GetDateValue(IndexField field)
 {
     DateTime date = DateTime.MinValue;
     try
     {
         date = DateField.StringToDate(field.Value.ToString());
     }
     catch { }
     return date;
 }
		private void RefreshIndexDBInfo(DataRowView schema, Index index, EntityField field) 
		{
			IndexField indexField = null;
			foreach (IndexField f in index.Fields) 
			{
				if (f.Name == field.Name) 
				{
					indexField = f;
					break;
				}
			}
			if (indexField == null) 
			{
				indexField = new IndexField();
				indexField.Name = field.Name;
				index.Fields.Add(indexField);
			}
			index.DBName = (string)schema["INDEX_NAME"];
			index.PrimaryKey = (bool)schema["PRIMARY_KEY"];
			index.ForeignKey = (((string)schema["INDEX_NAME"]).Substring(0, 3) == "FK_");
			index.Unique = (bool)schema["UNIQUE"];
			if (index.Name == string.Empty) 
			{
				if (index.PrimaryKey) 
				{
					index.IsExcluded = !this.OrmConfiguration.AutoEnableMappedIndexes && !this.OrmConfiguration.AutoEnablePrimaryIndex;
					if (this.OrmConfiguration.RenamePrimaryIndex && this.OrmConfiguration.PrimaryIndexName != "") 
					{
						index.Name = this.OrmConfiguration.PrimaryIndexName;
					}
					else 
					{
						index.Name = index.DBName;
					}
					index.DeleteBy = true;
				}
				else 
				{
					index.IsExcluded = !this.OrmConfiguration.AutoEnableMappedIndexes;
					index.Name = index.DBName;
				}
			}
		}
		private bool SchemaContainsField(DataView schema, IndexField field, Index index) 
		{
			string dbColumn = string.Empty;
			foreach (EntityField f in index.Entity.Fields) 
			{
				if (f.Name == field.Name) 
				{
					dbColumn = f.DBColumn;
					break;
				}
			}
			if (dbColumn == string.Empty) 
			{
				dbColumn = field.Name;
			}
			foreach (DataRowView row in schema) 
			{
				if ((string)row["TABLE_NAME"] == index.Entity.DBEntityName 
					&& (string)row["INDEX_NAME"] == index.DBName 
					&& (string)row["COLUMN_NAME"] == dbColumn) 
				{
					return true;
				}
			}
			return false;
		}
 public static IndexField IsSearchable(this IndexField field, bool value = true)
 {
     field.Searchable = value;
     return(field);
 }
Beispiel #37
0
        public IRequest Marshall(DefineIndexFieldRequest defineIndexFieldRequest)
        {
            IRequest request = new DefaultRequest(defineIndexFieldRequest, "AmazonCloudSearch");

            request.Parameters.Add("Action", "DefineIndexField");
            request.Parameters.Add("Version", "2011-02-01");
            if (defineIndexFieldRequest != null && defineIndexFieldRequest.IsSetDomainName())
            {
                request.Parameters.Add("DomainName", StringUtils.FromString(defineIndexFieldRequest.DomainName));
            }
            if (defineIndexFieldRequest != null)
            {
                IndexField indexField = defineIndexFieldRequest.IndexField;
                if (indexField != null && indexField.IsSetIndexFieldName())
                {
                    request.Parameters.Add("IndexField.IndexFieldName", StringUtils.FromString(indexField.IndexFieldName));
                }
                if (indexField != null && indexField.IsSetIndexFieldType())
                {
                    request.Parameters.Add("IndexField.IndexFieldType", StringUtils.FromString(indexField.IndexFieldType));
                }
                if (indexField != null)
                {
                    UIntOptions uIntOptions = indexField.UIntOptions;
                    if (uIntOptions != null && uIntOptions.IsSetDefaultValue())
                    {
                        request.Parameters.Add("IndexField.UIntOptions.DefaultValue", StringUtils.FromInt(uIntOptions.DefaultValue));
                    }
                }
                if (indexField != null)
                {
                    LiteralOptions literalOptions = indexField.LiteralOptions;
                    if (literalOptions != null && literalOptions.IsSetDefaultValue())
                    {
                        request.Parameters.Add("IndexField.LiteralOptions.DefaultValue", StringUtils.FromString(literalOptions.DefaultValue));
                    }
                    if (literalOptions != null && literalOptions.IsSetSearchEnabled())
                    {
                        request.Parameters.Add("IndexField.LiteralOptions.SearchEnabled", StringUtils.FromBool(literalOptions.SearchEnabled));
                    }
                    if (literalOptions != null && literalOptions.IsSetFacetEnabled())
                    {
                        request.Parameters.Add("IndexField.LiteralOptions.FacetEnabled", StringUtils.FromBool(literalOptions.FacetEnabled));
                    }
                    if (literalOptions != null && literalOptions.IsSetResultEnabled())
                    {
                        request.Parameters.Add("IndexField.LiteralOptions.ResultEnabled", StringUtils.FromBool(literalOptions.ResultEnabled));
                    }
                }
                if (indexField != null)
                {
                    TextOptions textOptions = indexField.TextOptions;
                    if (textOptions != null && textOptions.IsSetDefaultValue())
                    {
                        request.Parameters.Add("IndexField.TextOptions.DefaultValue", StringUtils.FromString(textOptions.DefaultValue));
                    }
                    if (textOptions != null && textOptions.IsSetFacetEnabled())
                    {
                        request.Parameters.Add("IndexField.TextOptions.FacetEnabled", StringUtils.FromBool(textOptions.FacetEnabled));
                    }
                    if (textOptions != null && textOptions.IsSetResultEnabled())
                    {
                        request.Parameters.Add("IndexField.TextOptions.ResultEnabled", StringUtils.FromBool(textOptions.ResultEnabled));
                    }
                }

                if (indexField != null)
                {
                    List <SourceAttribute> sourceAttributesList = indexField.SourceAttributes;
                    int sourceAttributesListIndex = 1;
                    foreach (SourceAttribute sourceAttributesListValue in sourceAttributesList)
                    {
                        if (sourceAttributesListValue != null && sourceAttributesListValue.IsSetSourceDataFunction())
                        {
                            request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataFunction", StringUtils.FromString(sourceAttributesListValue.SourceDataFunction));
                        }
                        if (sourceAttributesListValue != null)
                        {
                            SourceData sourceDataCopy = sourceAttributesListValue.SourceDataCopy;
                            if (sourceDataCopy != null && sourceDataCopy.IsSetSourceName())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataCopy.SourceName", StringUtils.FromString(sourceDataCopy.SourceName));
                            }
                            if (sourceDataCopy != null && sourceDataCopy.IsSetDefaultValue())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataCopy.DefaultValue", StringUtils.FromString(sourceDataCopy.DefaultValue));
                            }
                        }
                        if (sourceAttributesListValue != null)
                        {
                            SourceDataTrimTitle sourceDataTrimTitle = sourceAttributesListValue.SourceDataTrimTitle;
                            if (sourceDataTrimTitle != null && sourceDataTrimTitle.IsSetSourceName())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataTrimTitle.SourceName", StringUtils.FromString(sourceDataTrimTitle.SourceName));
                            }
                            if (sourceDataTrimTitle != null && sourceDataTrimTitle.IsSetDefaultValue())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataTrimTitle.DefaultValue", StringUtils.FromString(sourceDataTrimTitle.DefaultValue));
                            }
                            if (sourceDataTrimTitle != null && sourceDataTrimTitle.IsSetSeparator())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataTrimTitle.Separator", StringUtils.FromString(sourceDataTrimTitle.Separator));
                            }
                            if (sourceDataTrimTitle != null && sourceDataTrimTitle.IsSetLanguage())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataTrimTitle.Language", StringUtils.FromString(sourceDataTrimTitle.Language));
                            }
                        }
                        if (sourceAttributesListValue != null)
                        {
                            SourceDataMap sourceDataMap = sourceAttributesListValue.SourceDataMap;
                            if (sourceDataMap != null && sourceDataMap.IsSetSourceName())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataMap.SourceName", StringUtils.FromString(sourceDataMap.SourceName));
                            }
                            if (sourceDataMap != null && sourceDataMap.IsSetDefaultValue())
                            {
                                request.Parameters.Add("IndexField.SourceAttributes.member." + sourceAttributesListIndex + ".SourceDataMap.DefaultValue", StringUtils.FromString(sourceDataMap.DefaultValue));
                            }
                            if (sourceDataMap != null)
                            {
                                if (sourceDataMap.Cases != null)
                                {
                                    int casesListIndex = 1;
                                    foreach (string key in sourceDataMap.Cases.Keys)
                                    {
                                        string value;
                                        bool   hasValue = sourceDataMap.Cases.TryGetValue(key, out value);
                                        request.Parameters.Add("sourceDataMap.entry." + casesListIndex + ".key", StringUtils.FromString(key));
                                        if (hasValue)
                                        {
                                            request.Parameters.Add("sourceDataMap.entry." + casesListIndex + ".value", StringUtils.FromString(value));
                                        }
                                        ++casesListIndex;
                                    }
                                }
                            }
                        }

                        sourceAttributesListIndex++;
                    }
                }
            }

            return(request);
        }
 public static IndexField SupportSuggestions(this IndexField field, bool value = true)
 {
     field.Suggestions = value;
     return(field);
 }
Beispiel #39
0
		public void RefreshDBInfo(DataRowView schema, EntityField entityField) {
			IndexField indexField = null;
			foreach (IndexField f in this.Fields) {
				if (f.Name == entityField.Name) {
					indexField = f;
					break;
				}
			}
			if (indexField == null) {
				indexField = new IndexField();
				indexField.Name = entityField.Name;
				this.Fields.Add(indexField);
			}
			this.DBName = (string)schema["INDEX_NAME"];
			this.PrimaryKey = (bool)schema["PRIMARY_KEY"];
			this.Unique = (bool)schema["UNIQUE"];
			if (this.Name == string.Empty) {
				if (this.PrimaryKey) {
					this.Name = "PK";
					this.DeleteBy = true;
				}
				else {
					this.Name = this.DBName;
				}
			}
		}