private void UpdateFilters(FilterQueryCollection filterQueries)
 {
     rptFilters.Visible = filterQueries.Count > 0;
     hidFilterQueries.Value = filterQueries.ToString();
     if (FilterChanged != null)
         FilterChanged(this, new FilterChangedEventArgs(filterQueries));
 }
 protected void RemoveFilter_Click(object sender, EventArgs e)
 {
     FilterQueryCollection existingQueries = new FilterQueryCollection(hidFilterQueries.Value);
     FilterQuery fq = new FilterQuery(((LinkButton)sender).CommandArgument);
     existingQueries.Remove(fq);
     UpdateFilters(existingQueries);
 }
 protected void AddFilter_Click(object sender, EventArgs e)
 {
     FilterQuery fq = new FilterQuery(((LinkButton)sender).CommandArgument);
     FilterQueryCollection existingQueries = new FilterQueryCollection(hidFilterQueries.Value);
     existingQueries.Add(fq);
     Query(null, 0, hidLoggingId.Value, existingQueries);
 }
        protected void Query(string text, int start, string loggingId = null, FilterQueryCollection filterQueries = null, bool hideSuggestions = false)
        {
            if (text == null) text = txtSearch.Text.Trim();

            phSearchResults.Visible = true;
            lblQuery.Text = text;
            lblQueryNoResults.Text = text;

            FacetAndFilter.FilterDataSource = filterQueries;
            FacetAndFilter.DataBind();

            var search = new Search<MyResult>(new Settings(COLLECTION));
            QueryOptions options = new QueryOptions()
            {
                Highlighting = true,
                Start = start,
                Rows = ROWS,
                SpellCheck = true,
                FacetFields = new[] { "url", "title" },
                FilterQueries = filterQueries,
                LoggingId = loggingId,
                // Language = "en" });
            };
            var cpResults = search.Execute(text, options);

            phSearchResultsNoResults.Visible = cpResults.Count == 0 && (filterQueries == null || filterQueries.Count == 0);
            phSearchResultsResults.Visible = !phSearchResultsNoResults.Visible;

            lblCount.Text = cpResults.TotalCount.ToString();
            lblFrom.Text = (start + 1).ToString();
            lblTo.Text = (start + cpResults.Count).ToString();
            phResultFromTo.Visible = start + cpResults.Count > 1;

            phSuggestions.Visible = (cpResults.Suggestions.Count > 0 && cpResults.Start == 0 && !hideSuggestions);
            if (cpResults.Suggestions.Count > 0)
            {
                lbSuggestionCollation.Text = cpResults.Suggestions.Collation;
                lbSuggestionCollation.CommandArgument = cpResults.Suggestions.Collation;
            }

            if (cpResults.Facets != null && cpResults.Facets.Count > 0)
            {
                FacetAndFilter.FacetDataSource = cpResults.Facets;
                FacetAndFilter.DataBind();
            }

            var pages = Enumerable.Range(1, (int) Math.Ceiling((double) cpResults.TotalCount/ROWS));
            rptPager.LoggingId = "";
            if (cpResults.CrownPeak != null && cpResults.CrownPeak.Logging != null)
            {
                rptPager.LoggingId = cpResults.CrownPeak.Logging.Id;
            }
            rptPager.DataSource = pages;
            rptPager.DataBind();
            rptPager.Visible = cpResults.TotalCount > ROWS;

            rptResults.DataSource = cpResults;
            rptResults.DataBind();
        }
        protected void RemoveFilter_Click(object sender, EventArgs e)
        {
            FilterQueryCollection existingQueries = new FilterQueryCollection(hidFilterQueries.Value);
            FilterQuery           fq = new FilterQuery(((LinkButton)sender).CommandArgument);

            existingQueries.Remove(fq);
            Query(null, 0, hidLoggingId.Value, existingQueries);
        }
        protected void AddFilter_Click(object sender, EventArgs e)
        {
            FilterQueryCollection existingQueries = new FilterQueryCollection(hidFilterQueries.Value);
            FilterQuery           fq = new FilterQuery(((LinkButton)sender).CommandArgument);

            existingQueries.Add(fq);
            UpdateFilters(existingQueries);
        }
 private void UpdateFilters(FilterQueryCollection filterQueries)
 {
     rptFilters.Visible     = filterQueries.Count > 0;
     hidFilterQueries.Value = filterQueries.ToString();
     if (FilterChanged != null)
     {
         FilterChanged(this, new FilterChangedEventArgs(filterQueries));
     }
 }
 public void FilterQueriesLimitResults()
 {
     var fq = new FilterQueryCollection()
     {
         new FilterQuery("url", "blog")
     };
     var results = Search.Execute("crownpeak", new QueryOptions() { Rows = 10, FilterQueries = fq });
     Assert.IsTrue(results.TotalCount == 87, "Expected 87 results, found " + results.TotalCount);
 }
        public void FilterQueriesLimitResults()
        {
            var fq = new FilterQueryCollection();

            fq.Add(new FilterQuery("url", "blog"));
            var results = PlainSearch.Execute("crownpeak", new QueryOptions()
            {
                Rows = 10, FilterQueries = fq
            });

            Assert.IsTrue(results.TotalCount == 87, "Expected 87 results, found " + results.TotalCount);
        }
Esempio n. 10
0
        public ActionResult Search(string queryText, int?page, string loggingId, string filterQueries, bool?hideSuggestions)
        {
            if (!page.HasValue || page < 1)
            {
                page = 1;
            }

            // We might have a leading ; from our concatenation
            if (filterQueries != null && filterQueries.StartsWith(";"))
            {
                filterQueries = filterQueries.Substring(1);
            }
            var fqCollection = new FilterQueryCollection(filterQueries);

            ViewBag.FilterQueryCollection = fqCollection;
            ViewBag.Query           = queryText;
            ViewBag.Page            = page.Value;
            ViewBag.HideSuggestions = hideSuggestions.HasValue && hideSuggestions.Value;

            var          search  = new Search <SearchResult>(new Settings("www.crownpeak.com"));
            QueryOptions options = new QueryOptions()
            {
                Highlighting  = true,
                Start         = (page.Value - 1) * ROWS,
                Rows          = ROWS,
                SpellCheck    = true,
                FacetFields   = new[] { "url", "title" },
                FilterQueries = new FilterQueryCollection(filterQueries),
                LoggingId     = loggingId,
                // Language = "en" });
            };
            var results = search.Execute(queryText, options);

            ViewBag.Pager     = null;
            ViewBag.LoggingId = "";
            if (results.CrownPeak != null && results.CrownPeak.Logging != null)
            {
                ViewBag.LoggingId = results.CrownPeak.Logging.Id;
            }
            if (results.TotalCount > ROWS)
            {
                // Make a simple pager
                ViewBag.Pager = Enumerable.Range(1, (int)Math.Ceiling((double)results.TotalCount / ROWS));
            }

            return(View(results));
        }
        protected void Query(string text, int start, FilterQueryCollection filterQueries = null)
        {
            var search = new Search<MyResult>(new Settings("www.crownpeak.com"));
            QueryOptions options = new QueryOptions()
            {
                Highlighting = false,
                Start = 0,
                Rows = 100000,
                SpellCheck = false,
                OrderBy = new[] { new SortOrder("date", CrownPeak.SearchG2.Query.SortDirection.Desc) },
                // Language = "en"
            };
            var cpResults = search.Execute(text, options);

            rptItems.DataSource = cpResults;
            rptItems.DataBind();
        }
Esempio n. 12
0
        protected void Query(string text, int start, FilterQueryCollection filterQueries = null)
        {
            var          search  = new Search <MyResult>(new Settings("www.crownpeak.com"));
            QueryOptions options = new QueryOptions()
            {
                Highlighting = false,
                Start        = 0,
                Rows         = 100000,
                SpellCheck   = false,
                OrderBy      = new[] { new SortOrder("date", CrownPeak.SearchG2.Query.SortDirection.Desc) },
                // Language = "en"
            };
            var cpResults = search.Execute(text, options);

            rptItems.DataSource = cpResults;
            rptItems.DataBind();
        }
        public ActionResult Search(string queryText, int? page, string loggingId, string filterQueries, bool? hideSuggestions)
        {
            if (!page.HasValue || page < 1) page = 1;

            // We might have a leading ; from our concatenation
            if (filterQueries != null && filterQueries.StartsWith(";")) filterQueries = filterQueries.Substring(1);
            var fqCollection = new FilterQueryCollection(filterQueries);
            ViewBag.FilterQueryCollection = fqCollection;
            ViewBag.Query = queryText;
            ViewBag.Page = page.Value;
            ViewBag.HideSuggestions = hideSuggestions.HasValue && hideSuggestions.Value;

            var search = new Search<SearchResult>(new Settings("www.crownpeak.com"));
            QueryOptions options = new QueryOptions()
            {
                Highlighting = true,
                Start = (page.Value - 1) * ROWS,
                Rows = ROWS,
                SpellCheck = true,
                FacetFields = new[] { "url", "title" },
                FilterQueries = new FilterQueryCollection(filterQueries),
                LoggingId = loggingId,
                // Language = "en" });
            };
            var results = search.Execute(queryText, options);

            ViewBag.Pager = null;
            ViewBag.LoggingId = "";
            if (results.CrownPeak != null && results.CrownPeak.Logging != null)
            {
                ViewBag.LoggingId = results.CrownPeak.Logging.Id;
            }
            if (results.TotalCount > ROWS)
            {
                // Make a simple pager
                ViewBag.Pager = Enumerable.Range(1, (int)Math.Ceiling((double)results.TotalCount / ROWS));
            }

            return View(results);
        }
        protected void Query(string text, int start, string loggingId = null, FilterQueryCollection filterQueries = null)
        {
            if (text == null)
            {
                text = txtSearch.Text.Trim();
            }

            phSearchResults.Visible = true;
            lblQuery.Text           = text;
            lblQueryNoResults.Text  = text;

            if (filterQueries == null)
            {
                hidFilterQueries.Value = "";
                rptFilters.Visible     = false;
            }
            else
            {
                hidFilterQueries.Value = filterQueries.ToString();
                rptFilters.Visible     = filterQueries.Count > 0;
                rptFilters.DataSource  = filterQueries;
                rptFilters.DataBind();
            }

            var          search  = new CrownPeak.SearchG2.PlainSearch(new Settings("www.crownpeak.com"));
            QueryOptions options = new QueryOptions()
            {
                Highlighting  = true,
                Start         = start,
                Rows          = ROWS,
                SpellCheck    = true,
                FacetFields   = new[] { "url", "title" },
                FilterQueries = filterQueries,
                LoggingId     = loggingId,
                // Language = "en" });
            };
            var resultSet = search.Execute(text, options);

            phSearchResultsNoResults.Visible = resultSet.Count == 0;
            phSearchResultsResults.Visible   = !phSearchResultsNoResults.Visible;

            lblCount.Text = resultSet.TotalCount.ToString();
            lblFrom.Text  = (start + 1).ToString();
            lblTo.Text    = (start + resultSet.Count).ToString();

            phSuggestions.Visible = (resultSet.Suggestions.Count > 0);
            if (resultSet.Suggestions.Count > 0)
            {
                lbSuggestionCollation.Text            = resultSet.Suggestions.Collation;
                lbSuggestionCollation.CommandArgument = resultSet.Suggestions.Collation;
            }

            if (resultSet.Facets != null && resultSet.Facets.Count > 0)
            {
                rptFacets.DataSource = resultSet.Facets;
                rptFacets.DataBind();
            }

            hidLoggingId.Value = "";
            var pages = Enumerable.Range(1, (int)Math.Ceiling((double)resultSet.TotalCount / ROWS));

            if (resultSet.CrownPeak != null && resultSet.CrownPeak.Logging != null)
            {
                hidLoggingId.Value = resultSet.CrownPeak.Logging.Id;
            }
            rptPager.DataSource = pages;
            rptPager.DataBind();
            rptPager.Visible = resultSet.TotalCount > ROWS;

            rptResults.DataSource = resultSet;
            rptResults.DataBind();
        }
 public FilterChangedEventArgs(FilterQueryCollection filters)
 {
     Filters = filters;
 }
 public FilterChangedEventArgs(FilterQueryCollection filters)
 {
     Filters = filters;
 }
        protected void Query(string text, int start, string loggingId = null, FilterQueryCollection filterQueries = null)
        {
            if (text == null) text = txtSearch.Text.Trim();

            phSearchResults.Visible = true;
            lblQuery.Text = text;
            lblQueryNoResults.Text = text;

            if (filterQueries == null)
            {
                hidFilterQueries.Value = "";
                rptFilters.Visible = false;
            }
            else
            {
                hidFilterQueries.Value = filterQueries.ToString();
                rptFilters.Visible = filterQueries.Count > 0;
                rptFilters.DataSource = filterQueries;
                rptFilters.DataBind();
            }

            var search = new CrownPeak.SearchG2.PlainSearch(new Settings("www.crownpeak.com"));
            QueryOptions options = new QueryOptions()
            {
                Highlighting = true,
                Start = start,
                Rows = ROWS,
                SpellCheck = true,
                FacetFields = new[] { "url", "title" },
                FilterQueries = filterQueries,
                LoggingId = loggingId,
                // Language = "en" });
            };
            var resultSet = search.Execute(text, options);

            phSearchResultsNoResults.Visible = resultSet.Count == 0;
            phSearchResultsResults.Visible = !phSearchResultsNoResults.Visible;

            lblCount.Text = resultSet.TotalCount.ToString();
            lblFrom.Text = (start + 1).ToString();
            lblTo.Text = (start + resultSet.Count).ToString();

            phSuggestions.Visible = (resultSet.Suggestions.Count > 0);
            if (resultSet.Suggestions.Count > 0)
            {
                lbSuggestionCollation.Text = resultSet.Suggestions.Collation;
                lbSuggestionCollation.CommandArgument = resultSet.Suggestions.Collation;
            }

            if (resultSet.Facets != null && resultSet.Facets.Count > 0)
            {
                rptFacets.DataSource = resultSet.Facets;
                rptFacets.DataBind();
            }

            hidLoggingId.Value = "";
            var pages = Enumerable.Range(1, (int)Math.Ceiling((double)resultSet.TotalCount / ROWS));
            if (resultSet.CrownPeak != null && resultSet.CrownPeak.Logging != null)
            {
                hidLoggingId.Value = resultSet.CrownPeak.Logging.Id;
            }
            rptPager.DataSource = pages;
            rptPager.DataBind();
            rptPager.Visible = resultSet.TotalCount > ROWS;

            rptResults.DataSource = resultSet;
            rptResults.DataBind();
        }
        protected void Query(string text, int start, string loggingId = null, FilterQueryCollection filterQueries = null, bool hideSuggestions = false)
        {
            if (text == null)
            {
                text = txtSearch.Text.Trim();
            }

            phSearchResults.Visible = true;
            lblQuery.Text           = text;
            lblQueryNoResults.Text  = text;

            FacetAndFilter.FilterDataSource = filterQueries;
            FacetAndFilter.DataBind();

            var          search  = new Search <MyResult>(new Settings(COLLECTION));
            QueryOptions options = new QueryOptions()
            {
                Highlighting  = true,
                Start         = start,
                Rows          = ROWS,
                SpellCheck    = true,
                FacetFields   = new[] { "url", "title" },
                FilterQueries = filterQueries,
                LoggingId     = loggingId,
                // Language = "en" });
            };
            var cpResults = search.Execute(text, options);

            phSearchResultsNoResults.Visible = cpResults.Count == 0 && (filterQueries == null || filterQueries.Count == 0);
            phSearchResultsResults.Visible   = !phSearchResultsNoResults.Visible;

            lblCount.Text          = cpResults.TotalCount.ToString();
            lblFrom.Text           = (start + 1).ToString();
            lblTo.Text             = (start + cpResults.Count).ToString();
            phResultFromTo.Visible = start + cpResults.Count > 1;

            phSuggestions.Visible = (cpResults.Suggestions.Count > 0 && cpResults.Start == 0 && !hideSuggestions);
            if (cpResults.Suggestions.Count > 0)
            {
                lbSuggestionCollation.Text            = cpResults.Suggestions.Collation;
                lbSuggestionCollation.CommandArgument = cpResults.Suggestions.Collation;
            }

            if (cpResults.Facets != null && cpResults.Facets.Count > 0)
            {
                FacetAndFilter.FacetDataSource = cpResults.Facets;
                FacetAndFilter.DataBind();
            }

            var pages = Enumerable.Range(1, (int)Math.Ceiling((double)cpResults.TotalCount / ROWS));

            rptPager.LoggingId = "";
            if (cpResults.CrownPeak != null && cpResults.CrownPeak.Logging != null)
            {
                rptPager.LoggingId = cpResults.CrownPeak.Logging.Id;
            }
            rptPager.DataSource = pages;
            rptPager.DataBind();
            rptPager.Visible = cpResults.TotalCount > ROWS;

            rptResults.DataSource = cpResults;
            rptResults.DataBind();
        }