Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom Chance 20 posts 101 karma points
    Aug 12, 2016 @ 09:11
    Tom Chance
    0

    Creating a Multi Input Examine Search

    Hi All,

    I am in the midst of creating a Multi-input examine search which will take from 1 to 4 inputs, Generate a query and then return the results to the user.

    Currently I have setup the view, controller and model for this but I am having issues on rendering out the results for the user. Originally I did this through taking the RenderModel and storing it as "searchModel" and then performing a return CurrentTemplate(searchModel); As mentioned by Sebastiaan though - This is bad practice.

    I have pasted my code below if anyone could help :)

    P.S (Excuse the class names on the view! Re-using what we had styled for our Umbraco forms - form)

    View:

     @using (Html.BeginUmbracoForm("AdvancedSearch", "Search"))
                    {
                        <div class="contourField textarea">
                            <label>Product Code</label>
                            <input class="search" type="text" placeholder="Product Code..." name="ProductCode" />
                        </div>
    
                        <div class="contourField textarea">
                            <label>Description</label>
                            <input class="search" type="text" placeholder="Description..." name="Description" />
                        </div>
    
                        <div class="contourField textarea">
                            <label>Details</label>
                            <input class="search" type="text" placeholder="Details..." name="Details" />
                        </div>
    
                        <div class="contourField textarea">
                            <label>Specification</label>
                            <input class="search" type="text" placeholder="Specification..." name="Specification" />
                        </div>
                        <input type="hidden" name="term" />
                        <div class="contourField">
                            <input class="searchbutton" type="submit" value="AdvancedSearch" />
                        </div>
                    }  
    

    Controller:

    public ActionResult AdvancedSearch(string productCode, string description, string details, string specification)
        {
    
            var sc = ExamineManager.Instance.SearchProviderCollection["CategoriesSearcher"].CreateSearchCriteria();
            IBooleanOperation query = null;
            if (!string.IsNullOrEmpty(productCode))
            {
                query = sc.Field("productCode", productCode.Escape());
            }
            if (!string.IsNullOrEmpty(description))
            {
                query = query == null
                    ? sc.Field("description", description.Escape())
                    : query.Or().Field("description", description.Escape());
            }
            if (!string.IsNullOrEmpty(details))
            {
                query = query == null
                    ? sc.Field("details", details.Escape())
                    : query.Or().Field("details", details.Escape());
            }
            if (!string.IsNullOrEmpty(specification))
            {
                query = query == null
                    ? sc.Field("specification", specification.Escape())
                    : query.Or().Field("specification", specification.Escape());
            }
            if (query != null)
            {
                var results = ExamineManager.Instance.SearchProviderCollection["CategoriesSearcher"].Search(query.Compile());
            }
    
            //return CurrentTemplate(searchModel);
        }
    

    Model:

     public partial class Search
    {
        public Search(IPublishedContent content)
            : base(content)
        {
            SearchResults = new List<IPublishedContent>();
        }
    
        #region Non DocType Properties
    
        public string Term { get; set; }
    
    
        public IEnumerable<IPublishedContent> SearchResults { get; set; }
    
        public Pager Pager { get; set; }
    
        #endregion
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft