예제 #1
0
        public static IQueryOver <T, T> ApplySorting <T>(this IQueryOver <T, T> query, SearchSortOrder sortOrder, bool sortAscending) where T : ISortable
        {
            IQueryOverOrderBuilder <T, T> orderBuilder = null;

            if (sortOrder == SearchSortOrder.Newest)
            {
                orderBuilder = query.OrderBy(x => x.CreationDate);
            }
            else if (sortOrder == SearchSortOrder.HighestRating)
            {
                orderBuilder = query.OrderBy(x => x.Rating);
            }
            else
            {
                orderBuilder = query.OrderBy(x => x.Name);
            }

            if (sortAscending)
            {
                query = orderBuilder.Asc;
            }
            else
            {
                query = orderBuilder.Desc;
            }
            return(query);
        }
예제 #2
0
 private IQueryOver <BookVersion, BookVersion> SetOrderDirection(
     IQueryOverOrderBuilder <BookVersion, BookVersion> queryOrder,
     ListSortDirection direction)
 {
     return(direction == ListSortDirection.Descending
         ? queryOrder.Desc
         : queryOrder.Asc);
 }
        private PagedResult <EntryRevision> FullTextSearch(ISession session, int skip, int take)
        {
            var searchTerms = SearchText.Split(' ', '-', '_').Where(x => !string.IsNullOrEmpty(x)).Select(x => "\"" + x + "*\"");
            var searchQuery = string.Join(" OR ", searchTerms.ToArray());

            var query = session.QueryOver <Entry>()
                        .Where(Expression.Sql("CONTAINS(*, ?)", searchQuery, NHibernateUtil.String))
                        .And(e => e.Status != EntryStatus.Private);

            var total =
                query
                .ToRowCountQuery()
                .FutureValue <int>();

            query
            .SelectList(EntryRevisionProjections.FromEntry())
            .TransformUsing(Transformers.AliasToBean <EntryRevision>());

            IQueryOverOrderBuilder <Entry, Entry> orderBy = null;

            switch (sortColumn)
            {
            case EntriesSortColumn.Slug:
                orderBy = query.OrderBy(e => e.Name);
                break;

            case EntriesSortColumn.Title:
                orderBy = query.OrderBy(e => e.Title);
                break;

            case EntriesSortColumn.Comments:
                orderBy = query.OrderBy(e => e.CommentCount);
                break;

            case EntriesSortColumn.Published:
                orderBy = query.OrderBy(e => e.Published);
                break;
            }

            if (orderBy != null)
            {
                if (asc)
                {
                    orderBy.Asc();
                }
                else
                {
                    orderBy.Desc();
                }
            }

            var entries = query
                          .Skip(skip)
                          .Take(take)
                          .List <EntryRevision>();

            return(new PagedResult <EntryRevision>(entries, total.Value, skip, take));
        }
예제 #4
0
        protected IQueryOver <Entry, Entry> Query(ISession session)
        {
            var entrySummaryAlias = new EntrySummary();

            var entries = session
                          .QueryOver <Entry>()
                          .SelectList(EntrySummaryProjections.FromEntry(entrySummaryAlias))
                          .TransformUsing(Transformers.AliasToBean <EntrySummary>());

            IQueryOverOrderBuilder <Entry, Entry> orderBy = null;

            switch (sortColumn)
            {
            case EntriesSortColumn.Slug:
                orderBy = entries.OrderBy(e => e.Name);
                break;

            case EntriesSortColumn.Title:
                orderBy = entries.OrderBy(e => e.Title);
                break;

            case EntriesSortColumn.Comments:
                orderBy = entries.OrderBy(e => e.CommentCount);
                break;

            case EntriesSortColumn.Published:
                orderBy = entries.OrderBy(e => e.Published);
                break;
            }
            if (orderBy != null)
            {
                entries = asc ? orderBy.Asc : orderBy.Desc;
            }

            return(entries);
        }
예제 #5
0
        public PagedResult <EntryRevision> Execute(ISession session, IDatabaseProvider databaseProvider, int skip, int take)
        {
            if (string.IsNullOrEmpty(SearchText) || SearchText.Trim().Length == 0)
            {
                return(new PagedResult <EntryRevision>(new List <EntryRevision>(), 0, skip, take));
            }

            var searchTerms = new string(SearchText.Where(x => char.IsLetterOrDigit(x) || x == ' ' || x == '-').ToArray());

            searchTerms = searchTerms.Replace(" ", "%");

            var query = session.QueryOver <Entry>()
                        .Where
                        (
                Restrictions.On <Entry>(e => e.LatestRevision.Body).IsLike(searchTerms, MatchMode.Anywhere)
                ||
                Restrictions.On <Entry>(e => e.Title).IsLike(searchTerms, MatchMode.Anywhere)
                        )
                        .And(e => e.Status != EntryStatus.Private);

            var total =
                query
                .ToRowCountQuery()
                .FutureValue <int>();

            query
            .SelectList(EntryRevisionProjections.FromEntry())
            .TransformUsing(Transformers.AliasToBean <EntryRevision>());

            IQueryOverOrderBuilder <Entry, Entry> orderBy = null;

            switch (sortColumn)
            {
            case EntriesSortColumn.Slug:
                orderBy = query.OrderBy(e => e.Name);
                break;

            case EntriesSortColumn.Title:
                orderBy = query.OrderBy(e => e.Title);
                break;

            case EntriesSortColumn.Comments:
                orderBy = query.OrderBy(e => e.CommentCount);
                break;

            case EntriesSortColumn.Published:
                orderBy = query.OrderBy(e => e.Published);
                break;
            }

            if (orderBy != null)
            {
                if (asc)
                {
                    orderBy.Asc();
                }
                else
                {
                    orderBy.Desc();
                }
            }

            var entries = query
                          .Skip(skip)
                          .Take(take)
                          .List <EntryRevision>();

            return(new PagedResult <EntryRevision>(entries, total.Value, skip, take));
        }