Beispiel #1
0
        private PropertiesDescriptor <object> CreateInterpretedFieldsPropertyDescriptor()
        {
            //have to put limit on this field because if term/string is longer than the 32766 bytes it can't be stored in Lucene
            var propDesc = new PropertiesDescriptor <object>();

            propDesc.String(desc => desc
                            .Name("raw")
                            .Index(FieldIndexOption.NotAnalyzed).IgnoreAbove(10000).IncludeInAll(false));
            var analyzerName = string.Format("{0}{1}", _analyzerPrefix, 1);

            propDesc.String(desc => desc
                            .Name("1")
                            .Analyzer(analyzerName)
                            .SearchAnalyzer(analyzerName)
                            .TermVector(TermVectorOption.WithPositionsOffsetsPayloads));

            // we only store the count for unigrams, because it's easy to calculate the others from this
            propDesc.TokenCount(desc => desc
                                .Name("1" + _tokenCountSuffix)
                                .Analyzer(analyzerName)
                                .DocValues(true)
                                .Store(true));

            return(propDesc);
        }
Beispiel #2
0
        public static PropertiesDescriptor <T> SetupDefaults <T>(this PropertiesDescriptor <T> pd) where T : class
        {
            var hasIdentity         = typeof(IIdentity).IsAssignableFrom(typeof(T));
            var hasDates            = typeof(IHaveDates).IsAssignableFrom(typeof(T));
            var hasCreatedDate      = typeof(IHaveCreatedDate).IsAssignableFrom(typeof(T));
            var supportsSoftDeletes = typeof(ISupportSoftDeletes).IsAssignableFrom(typeof(T));

            if (hasIdentity)
            {
                pd.String(p => p.Name(d => (d as IIdentity).Id).IndexName("id").Index(FieldIndexOption.NotAnalyzed));
            }

            if (supportsSoftDeletes)
            {
                pd.Boolean(p => p.Name(d => (d as ISupportSoftDeletes).IsDeleted).IndexName(SoftDeletesQueryBuilder.Fields.Deleted));
            }

            if (hasCreatedDate)
            {
                pd.Date(p => p.Name(d => (d as IHaveCreatedDate).CreatedUtc).IndexName("created"));
            }

            if (hasDates)
            {
                pd.Date(p => p.Name(d => (d as IHaveDates).UpdatedUtc).IndexName("updated"));
            }

            return(pd);
        }
Beispiel #3
0
        private static PropertiesDescriptor <ErrorDocument> CreateMultiFieldsForAllStrings(PropertiesDescriptor <ErrorDocument> props)
        {
            var members = typeof(ErrorDocument)
                          .GetProperties()
                          .Where(x => x.PropertyType == typeof(string) &&
                                 x.Name != "Id" && //id field is obviously excluded
                                 x.Name != "ErrorXml"//errorXML field is so long it has no indexer on it at all
                                 );

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var m in members)
            {
                var name = m.Name;
                name = char.ToLowerInvariant(name[0]) + name.Substring(1);//lowercase the first character
                props
                .String(s => s
                        .Name(name)
                        .Fields(pprops => pprops
                                .String(ps => ps.Name(name).Index(FieldIndexOption.Analyzed))
                                .String(ps => ps.Name(MultiFieldSuffix).Index(FieldIndexOption.NotAnalyzed))
                                )
                        );
            }
            return(props);
        }
Beispiel #4
0
        private PropertiesDescriptor <object> CreateAnalyzerPropertiesDescriptor(int shingleCount)
        {
            var multiPropDesc = new PropertiesDescriptor <object>();

            for (var i = 1; i <= shingleCount; i++)
            {
                var actualIndex  = i;
                var analyzerName = string.Format("{0}{1}", _analyzerPrefix, actualIndex);
                multiPropDesc.String(desc => desc
                                     .Name(actualIndex.ToString())
                                     .Analyzer(analyzerName)
                                     .SearchAnalyzer(analyzerName)
                                     .TermVector(TermVectorOption.WithPositionsOffsetsPayloads));
            }

            return(multiPropDesc);
        }
Beispiel #5
0
        public static IPromise <IProperties> SetInterpretedFields(PropertiesDescriptor <object> descriptor, PropertiesDescriptor <object> fieldsDescriptor, IEnumerable <string> segmentList)
        {
            var segment      = segmentList.First();
            var restSegments = segmentList.Skip(1);

            if (restSegments.Count() == 0)
            {
                descriptor.String(strDesc => strDesc
                                  .Name(segment)
                                  .Fields(f => fieldsDescriptor));
                return(descriptor);
            }

            descriptor.Object <object>(desc => desc
                                       .Name(segment)
                                       .Properties(pDesc => SetInterpretedFields(pDesc, fieldsDescriptor, restSegments)));

            return(descriptor);
        }
Beispiel #6
0
 private static PropertiesDescriptor <Developer> DeveloperProperties(PropertiesDescriptor <Developer> props) => props
 .String(s => s.Name(p => p.OnlineHandle).NotAnalyzed())
 .String(s => s.Name(p => p.Gender).NotAnalyzed())
 .String(s => s.Name(p => p.FirstName).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))
 .Ip(s => s.Name(p => p.IPAddress))
 //.GeoPoint(g=>g.Name(p=>p.Location))
 ;
Beispiel #7
0
 private static PropertiesDescriptor <Tag> TagProperties(PropertiesDescriptor <Tag> props) => props
 .String(s => s
         .Name(p => p.Name).NotAnalyzed()
         .Fields(f => f
                 .String(st => st.Name("vectors").TermVector(TermVectorOption.WithPositionsOffsetsPayloads))
                 )
         );
Beispiel #8
0
 private PropertiesDescriptor <TRoyal> RoyalProps <TRoyal>(PropertiesDescriptor <TRoyal> props) where TRoyal : class, IRoyal =>
 props.String(s => s.Name(p => p.Name).NotAnalyzed());
Beispiel #9
0
        public static IPromise <IProperties> MapProperties(JToken node, PropertiesDescriptor <object> descriptor, PropertiesDescriptor <object> analyzers, List <string> interpretedFields, string path)
        {
            var properties = node.Children <JProperty>().ToList();

            foreach (JProperty property in properties)
            {
                var name          = property.Name;
                var fullPath      = path.AppendSeparator(".") + name;
                var isInterpreted = interpretedFields.Contains(fullPath, StringComparer.OrdinalIgnoreCase);
                Func <PropertiesDescriptor <object>, IPromise <IProperties> > applyAnalyzerFields = field => isInterpreted ? analyzers : field;
                var tokenPrefix = string.Empty;

                var type   = property.Value.SelectToken(SchemaHelper.Elements.Type)?.Value <string>();
                var format = property.Value.SelectToken(SchemaHelper.Elements.Format)?.Value <string>();

                if (string.IsNullOrEmpty(type))
                {
                    // Json schema validator should catch this
                    throw new ArgumentNullException($"Elastic type is not provided");
                }

                // Elastic nem kezel külön array-t, ezért ha így tartalmazza a schema az eleme típusát használjuk fel
                if (type == SchemaHelper.Types.Array)
                {
                    tokenPrefix = $"{SchemaHelper.Elements.Items}.";
                    type        = property.Value.SelectToken($"{tokenPrefix}{SchemaHelper.Elements.Type}")?.Value <string>();
                    format      = property.Value.SelectToken($"{tokenPrefix}{SchemaHelper.Elements.Format}")?.Value <string>();
                }

                switch (type)
                {
                case SchemaHelper.Types.String:
                {
                    descriptor.String(desc => desc
                                      .Name(name)
                                      .Fields(applyAnalyzerFields));
                    break;
                }

                case SchemaHelper.Types.Long:
                case SchemaHelper.Types.Integer:
                case SchemaHelper.Types.Short:
                case SchemaHelper.Types.Byte:
                case SchemaHelper.Types.Double:
                case SchemaHelper.Types.Float:
                {
                    var numberType = (NumberType)Enum.Parse(typeof(NumberType), type, true);
                    descriptor.Number(desc => desc
                                      .Name(name)
                                      .Type(numberType)
                                      .Fields(applyAnalyzerFields));
                    break;
                }

                case SchemaHelper.Types.Boolean:
                {
                    descriptor.Boolean(desc => desc
                                       .Name(name)
                                       .Fields(applyAnalyzerFields));
                    break;
                }

                case SchemaHelper.Types.Date:
                {
                    if (string.IsNullOrWhiteSpace(format))
                    {
                        format = "strict_date_optional_time||epoch_millis";
                    }

                    descriptor.Date(desc => desc
                                    .Name(name)
                                    .Format(format)
                                    .Fields(applyAnalyzerFields));
                }
                break;

                case SchemaHelper.Types.Attachment:
                {
                    descriptor.Attachment(desc => desc
                                          .Name(name)
                                          .FileField(d => d //ContentField
                                                     .Store(true)
                                                     .Fields(applyAnalyzerFields))
                                          .ContentTypeField(d => d.Store(true))
                                          .ContentLengthField(d => (d as NumberPropertyDescriptor <object>).Store(true))
                                          .LanguageField(d => (d as StringPropertyDescriptor <object>).Store(true))
                                          .KeywordsField(d => d.Store(true))
                                          .AuthorField(d => d.Store(true))
                                          .DateField(d => d.Store(true))
                                          .TitleField(d => d.Store(true))
                                          );
                    break;
                }

                case SchemaHelper.Types.Object:
                {
                    descriptor.Object <object>(desc => desc
                                               .Name(name)
                                               .Properties(propDesc =>
                                                           MapProperties(property.Value.SelectToken($"{tokenPrefix}{SchemaHelper.Elements.Properties}"),
                                                                         propDesc,
                                                                         analyzers,
                                                                         interpretedFields,
                                                                         fullPath)));
                    break;
                }

                default:
                {
                    throw new NotImplementedException($"Elastic type '{type}' is not implemented");
                }
                }
            }

            return(descriptor);
        }
		private static PropertiesDescriptor<Developer> DeveloperProperties(PropertiesDescriptor<Developer> props) => props
			.String(s => s.Name(p => p.OnlineHandle).NotAnalyzed())
			.String(s => s.Name(p => p.Gender).NotAnalyzed())
			.String(s => s.Name(p => p.FirstName).TermVector(TermVectorOption.WithPositionsOffsetsPayloads))
			.Ip(s => s.Name(p => p.IPAddress))
			.GeoPoint(g => g.Name(p => p.Location).LatLon())
			;
		private static PropertiesDescriptor<Tag> TagProperties(PropertiesDescriptor<Tag> props) => props
			.String(s => s
				.Name(p => p.Name).NotAnalyzed()
				.Fields(f => f
					.String(st => st.Name("vectors").TermVector(TermVectorOption.WithPositionsOffsetsPayloads))
				)
			);