Пример #1
0
        private async Task <IEnumerable <MetascoredAdvertisement> > FetchAds(string metaPhrase, GeoJsonPoint <GeoJson3DGeographicCoordinates> position = null)
        {
            var adProjectionBuilder = new ProjectionDefinitionBuilder <MetascoredAdvertisement>();
            var adProjection        = adProjectionBuilder
                                      .MetaTextScore(nameof(MetascoredAdvertisement.MetaScore).WithLowercaseFirstCharacter())
                                      .Include(ad => ad._id)
                                      .Include(ad => ad.Title)
                                      .Include(ad => ad.Text)
                                      .Include(ad => ad.Poster)
                                      .Include(ad => ad.FileReferences)
            ;

            return(await FetchEntities(metaPhrase, adProjection, MongoWrapper.Database.GetCollection <MetascoredAdvertisement>(nameof(Models.Advertisement)), 100, 5, position));
        }
Пример #2
0
        private async Task <IEnumerable <MetascoredPost> > FetchPosts(string metaPhrase, GeoJsonPoint <GeoJson3DGeographicCoordinates> position = null)
        {
            var postProjectionBuilder = new ProjectionDefinitionBuilder <MetascoredPost>();
            var postProjection        = postProjectionBuilder
                                        .MetaTextScore(nameof(MetascoredPost.MetaScore).WithLowercaseFirstCharacter())
                                        .Include(post => post._id)
                                        .Include(post => post.Title)
                                        .Include(post => post.Text)
                                        .Include(post => post.Poster)
                                        .Include(post => post.Likes)
                                        .Include(post => post.FileReferences)
                                        .Include(post => post.Comments)
            ;

            return(await FetchEntities(metaPhrase, postProjection, MongoWrapper.Database.GetCollection <MetascoredPost>(nameof(Models.Post)), 30, 10, position));
        }
Пример #3
0
        public async Task <dynamic> Get([FromQuery] string search)
        {
            var userCollection = MongoWrapper.Database.GetCollection <Models.User>(nameof(Models.User));

            var userProjectionBuilder = new ProjectionDefinitionBuilder <Models.User>();
            var userProjection        = userProjectionBuilder
                                        .MetaTextScore("MetaScore".WithLowercaseFirstCharacter())
                                        .Include(user => user._id)
                                        .Include(user => user.FullName)
                                        .Include(user => user.Avatar)
                                        .Include(user => user.About)
                                        .Include("_t");

            var userFilterBuilder = new FilterDefinitionBuilder <Models.User>();
            var userFilter        = userFilterBuilder.And
                                    (
                userFilterBuilder.Text(search, new TextSearchOptions
            {
                CaseSensitive      = false,
                DiacriticSensitive = false,
            }),
                GeneralUtils.NotDeactivated(userFilterBuilder)
                                    );

            var userSortBuilder = new SortDefinitionBuilder <Models.User>();
            var userSort        = userSortBuilder.MetaTextScore("MetaScore".WithLowercaseFirstCharacter());

            var users = (await userCollection.FindAsync(userFilter, new FindOptions <Models.User>
            {
                Sort = userSort,
                Limit = 50,
                AllowPartialResults = true,
                Projection = userProjection,
            }));

            return(new ResponseBody
            {
                Code = ResponseCode.GenericSuccess,
                Success = true,
                Data = users.ToEnumerable().Select(u => u.BuildUserResponse()),
                Message = "Usuários encontrados com sucesso!",
            });
        }
Пример #4
0
 public IDocumentProjectionBuilder IncludeTextScore(string property = DocumentStorageExtensions.DefaultTextScoreProperty)
 {
     _projections.Add(InternalBuilder.MetaTextScore(property));
     return(this);
 }