当前位置: 首页>>代码示例>>C#>>正文


C# AbstractViewGenerator.GetSpatialField方法代码示例

本文整理汇总了C#中Raven.Database.Linq.AbstractViewGenerator.GetSpatialField方法的典型用法代码示例。如果您正苦于以下问题:C# AbstractViewGenerator.GetSpatialField方法的具体用法?C# AbstractViewGenerator.GetSpatialField怎么用?C# AbstractViewGenerator.GetSpatialField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Database.Linq.AbstractViewGenerator的用法示例。


在下文中一共展示了AbstractViewGenerator.GetSpatialField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSort

		public static Sort GetSort(this IndexQuery self, IndexDefinition indexDefinition, AbstractViewGenerator viewGenerator)
		{
			var spatialQuery = self as SpatialIndexQuery;
			var sortedFields = self.SortedFields;
			if (sortedFields == null || sortedFields.Length <= 0)
			{
				if (spatialQuery == null || string.IsNullOrEmpty(self.Query) == false)
					return null;
				sortedFields = new[] { new SortedField(Constants.DistanceFieldName), };
			}

			return new Sort(sortedFields
							.Select(sortedField =>
							{
								if (sortedField.Field == Constants.TemporaryScoreValue)
								{
									return SortField.FIELD_SCORE;
								}
								if (sortedField.Field.StartsWith(Constants.RandomFieldName))
								{
									var parts = sortedField.Field.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
									if (parts.Length < 2) // truly random
										return new RandomSortField(Guid.NewGuid().ToString());
									return new RandomSortField(parts[1]);
								}
								if (spatialQuery != null && sortedField.Field == Constants.DistanceFieldName)
								{
									var spatialField = viewGenerator.GetSpatialField(spatialQuery.SpatialFieldName);
									var shape = spatialField.ReadShape(spatialQuery.QueryShape);
									var dsort = new SpatialDistanceFieldComparatorSource(spatialField, shape.GetCenter());
									return new SortField(Constants.DistanceFieldName, dsort, sortedField.Descending);
								}
								var sortOptions = GetSortOption(indexDefinition, sortedField.Field);
                                
								if (sortOptions == null || sortOptions == SortOptions.None)
									return new SortField(sortedField.Field, CultureInfo.InvariantCulture, sortedField.Descending);
							    
                                if (sortOptions.Value == SortOptions.Short)
							        sortOptions = SortOptions.Int;
							    return new SortField(sortedField.Field, (int)sortOptions.Value, sortedField.Descending);

							})
							.ToArray());
		}
开发者ID:925coder,项目名称:ravendb,代码行数:44,代码来源:IndexingExtensions.cs

示例2: GetSort

		public static Sort GetSort(this IndexQuery self, IndexDefinition indexDefinition, AbstractViewGenerator viewGenerator)
		{
			var spatialQuery = self as SpatialIndexQuery;
			var sortedFields = self.SortedFields;
			if (sortedFields == null || sortedFields.Length <= 0)
			{
				if (spatialQuery == null || string.IsNullOrEmpty(self.Query) == false)
					return null;
				sortedFields = new[] { new SortedField(Constants.DistanceFieldName), };
			}

			return new Sort(sortedFields
							.Select(sortedField =>
							{
								if (sortedField.Field == Constants.TemporaryScoreValue)
								{
									return SortField.FIELD_SCORE;
								}
								if (sortedField.Field.StartsWith(Constants.RandomFieldName))
								{
									var parts = sortedField.Field.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
									if (parts.Length < 2) // truly random
										return new RandomSortField(Guid.NewGuid().ToString());
									return new RandomSortField(parts[1]);
								}
								if (sortedField.Field.StartsWith(Constants.CustomSortFieldName))
								{
									var parts = sortedField.Field.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
									if (parts.Length < 2) // truly random
										throw new InvalidOperationException("Cannot figure out type for custom sort");
									return new CustomSortField(parts[1], self, parts[0][parts[0].Length-1] == '-');
								}
								if (sortedField.Field.StartsWith(Constants.DistanceFieldName))
								{
								    SpatialField spatialField = null;
								    Shape shape ;

                                    if (sortedField.Field.Length == Constants.DistanceFieldName.Length) 
                                    {
                                        if (spatialQuery == null)
                                            throw new InvalidOperationException("Illegal Spatial Sort Parameter: Blank Spatial sort cannot be used without a spatial query");

                                        spatialField = viewGenerator.GetSpatialField(spatialQuery.SpatialFieldName);

                                        shape = spatialField.ReadShape(spatialQuery.QueryShape);
                                    }
                                    else
                                    {
                                        var sortParams = sortedField.Field.Split(';');
                                        double lat, lng;

                                        if (sortParams.Length <3 || !double.TryParse(sortParams[1], out lat) || !double.TryParse(sortParams[2], out lng))
                                            throw new InvalidOperationException("Illegal Spatial Sort Parameter");


                                        string spatialFieldName;

                                        if (sortParams.Length >= 4)
                                        {
                                            spatialFieldName = sortParams[3];
                                        }
                                        else
                                        {
                                            if (spatialQuery == null)
                                            {
                                                spatialFieldName = Constants.DefaultSpatialFieldName;
                                            }
                                            else
                                            {
                                                spatialFieldName  = spatialQuery.SpatialFieldName;
                                            }
                                        }

                                        spatialField = viewGenerator.GetSpatialField(spatialFieldName);

                                        shape = new PointImpl(lng, lat, spatialField.GetContext());    
                                    }
									var dsort = new SpatialDistanceFieldComparatorSource(spatialField, shape.GetCenter());
                                    return new SortField(sortedField.Field, dsort, sortedField.Descending);
								}
								var sortOptions = GetSortOption(indexDefinition, sortedField.Field, self);
                                
								if (sortOptions == null || sortOptions == SortOptions.None)
									return new SortField(sortedField.Field, CultureInfo.InvariantCulture, sortedField.Descending);
							    
                                if (sortOptions.Value == SortOptions.Short)
							        sortOptions = SortOptions.Int;
							    return new SortField(sortedField.Field, (int)sortOptions.Value, sortedField.Descending);

							})
							.ToArray());
		}
开发者ID:jrusbatch,项目名称:ravendb,代码行数:92,代码来源:IndexingExtensions.cs


注:本文中的Raven.Database.Linq.AbstractViewGenerator.GetSpatialField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。