Example #1
0
 public Column(IDataTable <T> table)
 {
     Table             = table;
     SearchInstruction = new SearchInstruction <T> {
         NameFunc = () => Name
     };
 }
Example #2
0
        /// <summary>
        /// This is the method that put search pieces together, including constructing
        /// instructions, performing search, and attach search results on page request object.
        /// </summary>
        /// <param name="pageRequest"></param>
        protected void _GetSearchResults(CMSPageRequest pageRequest)
        {
            int               pagesize, page;
            bool              all;
            SiteSearch        siteSearch;
            SearchInstruction instructions = getSearchInstructions(pageRequest,
                                                                   out page,
                                                                   out pagesize,
                                                                   out all);

            Ingeniux.Search.Search search = new Ingeniux.Search.Search(Request);

            int count = 0;

            //use the SearchInstruction based overload method to achieve maxt flexibility
            pageRequest.Tag = search.QueryFinal(SiteSearch, out count, instructions,
                                                200, all, page, pagesize);
        }
Example #3
0
        /// <summary>
        /// This is the method that will construct the SearchInstruction object.
        /// This is the place to manipulate the SearchInstruction object in order to
        /// generate a query with custom logics
        /// </summary>
        /// <param name="pageRequest">CMS Page object</param>
        /// <param name="page">Page number, default to 1</param>
        /// <param name="pagesize">Page size, default to 10</param>
        /// <param name="all">All records or not</param>
        /// <returns>Customized search instructions</returns>
        private SearchInstruction getSearchInstructions(CMSPageRequest pageRequest,
                                                        out int page,
                                                        out int pagesize,
                                                        out bool all)
        {
            string[] termsA = pageRequest.QueryString["terms"]
                              .ToNullOrEmptyHelper()
                              .Propagate(
                s => s.Split(','))
                              .Return(new string[0]);

            //default to not categories filter
            string[] catsA = pageRequest.QueryString["catids"]
                             .ToNullOrEmptyHelper()
                             .Propagate(
                s => s.Split(','))
                             .Return(new string[0]);

            bool categoryById = pageRequest.QueryString["catsbyid"]
                                .ToNullOrEmptyHelper()
                                .Propagate(
                sa => sa.ToBoolean())
                                .Return(false);

            //default to no types filter
            string[] typesA = pageRequest.QueryString["types"]
                              .ToNullOrEmptyHelper()
                              .Propagate(
                s => s.Split(','))
                              .Return(new string[0]);

            string[] localesA = pageRequest.QueryString["locales"]
                                .ToNullOrEmptyHelper()
                                .Propagate(
                s => s.Split(','))
                                .Return(new string[0]);

            //default to first page instead of all records
            string pageStr = pageRequest.QueryString["page"]
                             .ToNullOrEmptyHelper()
                             .Return("1");

            //default page size to 10 records
            pagesize = pageRequest.QueryString["pagesize"]
                       .ToNullOrEmptyHelper()
                       .Propagate(
                ps => ps.ToInt())
                       .Propagate(
                ps => ps.Value)
                       .Return(10);

            string[] sourcesA = pageRequest.QueryString["sources"]
                                .ToNullOrEmptyHelper()
                                .Propagate(
                s => s.Split(','))
                                .Return(new string[0]);

            string sortby        = pageRequest.QueryString["sortby"] ?? string.Empty;
            bool   sortAscending = pageRequest.QueryString["sortasc"]
                                   .ToNullOrEmptyHelper()
                                   .Propagate(
                sa => sa.ToBoolean())
                                   .Return(false);

            all = false;

            if (!int.TryParse(pageStr, out page))
            {
                all = true;
            }
            else if (page < 1)
            {
                all = true;
            }

            //use the hiliter in configuration, or default hiliter with strong tags
            QueryBuilder.CategoryFilterOperator = Ingeniux.Search.Search.GetCategoryFilterOperator();

            SearchInstruction instructions = new SearchInstruction(SiteSearch.DefaultQueryAnalyzer);

            instructions.AddQuery(
                instructions.GetFullTextTermQuery(Occur.MUST, true, termsA));

            if (typesA.Length > 0)
            {
                instructions.AddQuery(
                    instructions.GetTypeQuery(Occur.MUST, typesA));
            }

            if (sourcesA.Length > 0)
            {
                instructions.AddQuery(
                    instructions.GetSourceQuery(Occur.MUST, sourcesA));
            }

            if (!string.IsNullOrWhiteSpace(sortby))
            {
                instructions.AddSort(new SortField(sortby, CultureInfo.InvariantCulture,
                                                   !sortAscending));
            }

            if (localesA.Length > 0)
            {
                instructions.AddQuery(
                    instructions.GetLocaleQuery(Occur.MUST, localesA));
            }

            if (catsA.Length > 0)
            {
                instructions.AddQuery(
                    (!categoryById) ?
                    instructions.GetCategoryQuery(Occur.MUST, QueryBuilder.CategoryFilterOperator,
                                                  catsA) :
                    instructions.GetCategoryIdQuery(Occur.MUST, QueryBuilder.CategoryFilterOperator,
                                                    catsA));
            }

            return(instructions);
        }
        protected void _GetSearchResults(CMSPageRequest pageRequest)
        {
            int  pagesize, page;
            bool all;

            Search.SiteSearch siteSearch;
            SearchInstruction instructions = getSearchInstructions(pageRequest,
                                                                   out page,
                                                                   out pagesize,
                                                                   out all,
                                                                   out siteSearch);

            //override pagesize from Schema
            var pgSize = pageRequest.GetElementValue("ResultsPageSize");

            if (pgSize != null)
            {
                pagesize = pgSize.ToInt() ?? 10;
            }

            Search.Search search = new Search.Search(Request);

            int count = 0;

            if (search != null)
            {
                //use the SearchInstruction based overload method to achieve max flexibility (non-paginated results)
                var pageResults = search.QueryFinal(siteSearch, out count, instructions, 200, true);

                //find matches for both member records and pages
                var    M           = new MembersWrapper();
                string termsString = pageRequest.QueryString["terms"] ?? "";
                //var memDic = M.Search(termsString);
                var memDic       = new List <KeyValuePair <string, Member> >();
                var pgCollection = pageResults
                                   .Select(r => new KeyValuePair <float, SearchResultItem>(r.Score, r));

                //apply sourceFilter and merge the two dictionaries
                string sourceFilter = pageRequest.QueryString["sourceFilter"] ?? "";
                IEnumerable <KeyValuePair <float, object> > mergedCollection = new KeyValuePair <float, object> [0];
                if (sourceFilter == "" || sourceFilter != "members")
                {
                    mergedCollection = pgCollection
                                       .Where(x =>
                    {
                        bool externalItem = (x.Value.Type == "ingeniux.search.htmlsitesource");
                        return(sourceFilter == "" ||
                               (sourceFilter == "local" && !externalItem) ||
                               (sourceFilter == "bni.com" && externalItem));
                    })
                                       .Select(x =>
                                               new KeyValuePair <float, object>(x.Key, x.Value));
                }

                if (sourceFilter == "" || sourceFilter == "members")
                {
                    mergedCollection = mergedCollection
                                       .Concat(memDic
                                               .Select(x => new KeyValuePair <float, object>(float.Parse(x.Key.SubstringBefore("_")), x.Value)));
                }

                //sort results
                var returnResults = mergedCollection.OrderByDescending(x => x.Key).Select(x => x.Value).ToList();

                //apply pagination
                ViewBag.totalResults = returnResults.Count;
                ViewBag.pageSize     = pagesize;
                pageRequest.Tag      = returnResults.Skip((page - 1) * pagesize).Take(pagesize).ToList();
                //pageRequest.Tag = mergedDic;  //no pagination
            }
        }