Copied to clipboard

Flag this post as spam?

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


  • Andrew Bright 84 posts 244 karma points
    Dec 21, 2016 @ 14:54
    Andrew Bright
    0

    ez Search examine price Range Valuessold [email protected] stcsold stc

    Hi,

    I am building a property site with search functionality, I have a parent node 'Property Portfolio' with childs nodes 'properties', the child nodes have been populated using the CMS Import tool which is essentially grabbing an xml feed and mapping the values to the relevant document property values and this is working fine.

    However I need to search on these properties and have started with the ez search plugin as this does most of what I need however I also need to search on a price range i.e minPrice to maxPrice and this is where I am struggling any advise appricaited.

    Heres what I have so far:

    @using System.Globalization @using System.Text @using System.Text.RegularExpressions @using Examine @using Umbraco.Core.Logging @using Umbraco.Web.Models @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var statusTypes = new List

    int parsedInt;
    
    // Parse querystring / macro parameter
    var model = new SearchViewModel
    {
        // SearchPropertyStatuses = statusTypes,
    
        //SearchTerm = CleanseSearchTerm(("" + Request["q"]).ToLower(CultureInfo.InvariantCulture)),
        SearchTerms = new Dictionary<string, string>(),
        Location = Request["Location"],//.ToLower(CultureInfo.InvariantCulture),
    
        MinPrice = Convert.ToInt32(Request["MinPrice"]) ,
        MaxPrice = Convert.ToInt32(Request["MaxPrice"]),
        SearchTerm = "(Location=" + Request["Location"] + ")" + "(MinPrice=" + Request["MinPrice"] + ")" + "(MaxPrice=" + Request["MaxPrice"] + ")",
        //+ " " + Request["type"] + " " 
        //+ Request["status"],
    
        CurrentPage = int.TryParse(Request["p"], out parsedInt) ? parsedInt : 1,
    
        PageSize = GetMacroParam(Model, "pageSize", s => int.Parse(s), 10),
        RootContentNodeId = GetMacroParam(Model, "rootContentNodeId", s => int.Parse(s), -1),
        RootMediaNodeId = GetMacroParam(Model, "rootMediaNodeId", s => int.Parse(s), -1),
        IndexType = GetMacroParam(Model, "indexType", s => s.ToLower(CultureInfo.InvariantCulture), ""),
        SearchFields = GetMacroParam(Model, "searchFields", s => SplitToList(s), new List<string> { "nodeName", "metaTitle", "metaDescription", "metaKeywords", "bodyText" }),
        PreviewFields = GetMacroParam(Model, "previewFields", s => SplitToList(s), new List<string> { "bodyText" }),
        PreviewLength = GetMacroParam(Model, "previewLength", s => int.Parse(s), 250),
        HideFromSearchField = GetMacroParam(Model, "hideFromSearchField", "umbracoNaviHide"),
        SearchFormLocation = GetMacroParam(Model, "searchFormLocation", s => s.ToLower(), "bottom")
    };
    
    // Validate values
    if (model.IndexType != UmbracoExamine.IndexTypes.Content &&
        model.IndexType != UmbracoExamine.IndexTypes.Media)
    {
        model.IndexType = "";
    }
    
    if (model.SearchFormLocation != "top"
        && model.SearchFormLocation != "bottom"
        && model.SearchFormLocation != "both"
        && model.SearchFormLocation != "none")
    {
        model.SearchFormLocation = "bottom";
    }
    
    // ====================================================
    // Comment the next if statement out if you want a root
    // node id of -1 to search content across all sites
    // and not just the current site.
    // ====================================================
    if (model.RootContentNodeId <= 0)
    {
        model.RootContentNodeId = Model.Content.AncestorOrSelf(1).Id;
    }
    
    // If searching on umbracoFile, also search on umbracoFileName
    if (model.SearchFields.Contains("umbracoFile") && !model.SearchFields.Contains("umbracoFileName"))
    {
        model.SearchFields.Add("umbracoFileName");
    }
    
    // Check the search term isn't empty
    var items = model.SearchTerm.Split(new[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries)
        .Select(s => s.Split(new[] { '=' }));
    
    //if (!string.IsNullOrWhiteSpace(model.SearchTerm))
    if(items.Any())
    {
        foreach (var item in items)
        {
            model.SearchTerms.Add(item[0], item[1]);
        }
        // Tokenize the search term
        //model.SearchTerms = Tokenize(model.SearchTerm);
        //model.SearchTerms.Add("Location", model.Location);
    
    
        // Perform the search
        var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        //var searcher = ExamineManager.Instance.CreateSearchCriteria();
        var criteria = searcher.CreateSearchCriteria();
    
        var query = criteria.NodeTypeAlias("umbPropertyDetails");
        //var query = new StringBuilder();
        //query.AppendFormat("-{0}:1 ", model.HideFromSearchField);
    
        // Set search path
        var contentPathFilter = model.RootContentNodeId > 0
            ? string.Format("__IndexType:{0} +searchPath:{1} -template:0", UmbracoExamine.IndexTypes.Content, model.RootContentNodeId)
            : string.Format("__IndexType:{0} -template:0", UmbracoExamine.IndexTypes.Content);
    
        var mediaPathFilter = model.RootMediaNodeId > 0
            ? string.Format("__IndexType:{0} +searchPath:{1}", UmbracoExamine.IndexTypes.Media, model.RootMediaNodeId)
            : string.Format("__IndexType:{0}", UmbracoExamine.IndexTypes.Media);
    
        //switch (model.IndexType)
        //{
        //    case UmbracoExamine.IndexTypes.Content:
        //        query.AppendFormat("+({0}) ", contentPathFilter);
        //        break;
        //    case UmbracoExamine.IndexTypes.Media:
        //        query.AppendFormat("+({0}) ", mediaPathFilter);
        //        break;
        //    default:
        //        query.AppendFormat("+(({0}) ({1})) ", contentPathFilter, mediaPathFilter);
        //        break;
        //}
    
        //if (model.SearchTermsPriceLower != String.Empty && PriceHigher != String.Empty)
        //{
        //    var paddedLower = int.Parse(PriceLower).ToString("D6");
        //    var paddedHigher = int.Parse(PriceHigher).ToString("D6");
    
        //    query = query.And().Range("price", paddedLower, paddedHigher, true, true);
        //}
    
        // Ensure page contains all search terms in some way
        //foreach (var term in model.SearchTerms)
        //{
    
        //var groupedOr = new StringBuilder();
        //foreach (var searchField in model.SearchFields)
        //{
        //    groupedOr.AppendFormat("{0}:{1}* ", searchField, term.Value);
        //}
        query.And().Field("regionID", model.Location.ToString()); //.Append("+(" + groupedOr.ToString() + ") ");
    
        if (model.MinPrice >= 0 && model.MaxPrice >= 0)
        {
    
            //if (PriceLower != String.Empty && PriceHigher != String.Empty)
            //{
                var paddedLower = model.MinPrice.ToString("D6");
                var paddedHigher = model.MaxPrice.ToString("D6");
    
                query = query.And().Range("price", paddedLower, paddedHigher, true, true);
            //}
            //query = query.And().Range("price", model.MinPrice, model.MaxPrice, true, true);
        }
    
        //query.Not().Field("umbracoNaviHide", "1");
        //}
    
        // Rank content based on positon of search terms in fields
        //for (var i = 0; i < model.SearchFields.Count; i++)
        //{
        //    foreach (var term in model.SearchTerms)
        //    {
        //        query.AppendFormat("{0}:{1}*^{2} ", model.SearchFields[i], term.Value, model.SearchFields.Count - i);
        //        //query = query.whe.Range("price", paddedLower, paddedHigher, true, true);
        //    }
        //}
    
        //var criteria2 = criteria.RawQuery(query.ToString());
        //ExamineManager.Instance.Search(query.Compile());
        var results = searcher.Search(query.Compile())//criteria2)
                            .Where(x => (
                                !Umbraco.IsProtected(int.Parse(x.Fields["id"]), x.Fields["path"]) ||
                                (
                                    Umbraco.IsProtected(int.Parse(x.Fields["id"]), x.Fields["path"]) &&
                                    Umbraco.MemberHasAccess(int.Parse(x.Fields["id"]), x.Fields["path"])
                                )) && (
                                    (x.Fields["__IndexType"] == UmbracoExamine.IndexTypes.Content && Umbraco.TypedContent(int.Parse(x.Fields["id"])) != null) ||
                                    (x.Fields["__IndexType"] == UmbracoExamine.IndexTypes.Media && Umbraco.TypedMedia(int.Parse(x.Fields["id"])) != null)
             //{ SearchIndexType: , LuceneQuery: +__NodeTypeAlias:propertydetail +paddedprice:[0 TO 300000] }
             )).ToList();
    
        model.AllResults = results;
    
        model.TotalResults = results.Count;
        model.TotalPages = (int)Math.Ceiling((decimal)model.TotalResults / model.PageSize);
        model.CurrentPage = Math.Max(1, Math.Min(model.TotalPages, model.CurrentPage));
    
        // Page the results
        model.PagedResults = model.AllResults.Skip(model.PageSize * (model.CurrentPage - 1)).Take(model.PageSize);
    
        LogHelper.Debug<string>("[ezSearch] Searching Lucene with the following query: " + query);
    
        if (!model.PagedResults.Any())
        {
            // No results found, so render no results view
            if (model.SearchFormLocation != "none")
            {
                @RenderForm(model)
            }
            @RenderNoResults(model)
        }
        else
        {
            // Render out the results
            if (model.SearchFormLocation == "top" || model.SearchFormLocation == "both")
            {
                @RenderForm(model)
            }
            @RenderSummary(model)
            @RenderResultsRange(model)
            @RenderResults(model)
            if (model.TotalPages > 1)
            {
                @RenderPager(model)
            }
            if (model.SearchFormLocation == "bottom" || model.SearchFormLocation == "both")
            {
                @RenderForm(model)
            }
        }
    }
    else
    {
        // Empty search term so just render the form
        if (model.SearchFormLocation != "none")
        {
            @RenderForm(model)
        }
    }
    }
    
    @*
        ==================================================
         Render Functions
        ==================================================
    *@
    
    @helper RenderForm(SearchViewModel model)
    {
    <form action="" method="GET" class="property-search-form ezsearch-form">
    
        <div class="col-xs-12 col-sm-4 col-md-3 form-group select">
            <select name="Location" class="selectpicker">
                <option value="0">Any Location</option>
                <option value="1">
                    Benwick
                </option>
                <option value="2">
                    Cambridge
                </option>
                <option value="3" selected="selected">
                    Chatteris
                </option>
                <option value="4">
                    Doddington
                </option>
                <option value="4">
                    Ely
                </option>
            </select>
        </div>
        <div class="col-xs-12 col-sm-4 col-md-3 form-group dropdown-double">
            <select name="MinPrice" class="selectpicker">
                <option value="0">Min Price</option>
                <option value="50000">£50,000</option>
                <option value="60000">£60,000</option>
                <option value="70000">£70,000</option>
                <option value="80000">£80,000</option>
                <option value="90000">£90,000</option>
                <option value="100000">£100,000</option>
                <option value="110000">£110,000</option>
                <option value="120000">£120,000</option>
                <option value="125000">£125,000</option>
                <option value="130000">£130,000</option>
                <option value="140000">£140,000</option>
                <option value="150000">£150,000</option>
                <option value="160000">£160,000</option>
                <option value="170000">£170,000</option>
                <option value="175000">£175,000</option>
                <option value="180000">£180,000</option>
                <option value="190000">£190,000</option>
                <option value="200000">£200,000</option>
                <option value="210000">£210,000</option>
                <option value="220000">£220,000</option>
                <option value="230000">£230,000</option>
                <option value="240000">£240,000</option>
                <option value="250000">£250,000</option>
                <option value="260000">£260,000</option>
                <option value="270000">£270,000</option>
                <option value="280000">£280,000</option>
                <option value="290000">£290,000</option>
                <option value="300000">£300,000</option>
                <option value="325000">£325,000</option>
                <option value="350000">£350,000</option>
                <option value="375000">£375,000</option>
                <option value="400000">£400,000</option>
                <option value="425000">£425,000</option>
                <option value="450000">£450,000</option>
                <option value="475000">£475,000</option>
                <option value="500000">£500,000</option>
                <option value="550000">£550,000</option>
                <option value="600000">£600,000</option>
                <option value="650000">£650,000</option>
                <option value="700000">£700,000</option>
                <option value="800000">£800,000</option>
                <option value="900000">£900,000</option>
                <option value="1000000">£1,000,000</option>
                <option value="1250000">£1,250,000</option>
                <option value="1500000">£1,500,000</option>
                <option value="1750000">£1,750,000</option>
                <option value="2000000">£2,000,000</option>
                <option value="2500000">£2,500,000</option>
                <option value="3000000">£3,000,000</option>
                <option value="4000000">£4,000,000</option>
                <option value="5000000">£5,000,000</option>
                <option value="7500000">£7,500,000</option>
                <option value="10000000">£10,000,000</option>
                <option value="15000000">£15,000,000</option>
                <option value="20000000">£20,000,000</option>
                <option value="">Min Price</option>
            </select>
            <div class="search-form divider">to</div>
            <select name="MaxPrice" class="selectpicker">
                <option value="0">Max Price</option>
                <option value="50000">£50,000</option>
                <option value="60000">£60,000</option>
                <option value="70000">£70,000</option>
                <option value="80000">£80,000</option>
                <option value="90000">£90,000</option>
                <option value="100000">£100,000</option>
                <option value="110000">£110,000</option>
                <option value="120000">£120,000</option>
                <option value="125000">£125,000</option>
                <option value="130000">£130,000</option>
                <option value="140000">£140,000</option>
                <option value="150000">£150,000</option>
                <option value="160000">£160,000</option>
                <option value="170000">£170,000</option>
                <option value="175000">£175,000</option>
                <option value="180000">£180,000</option>
                <option value="190000">£190,000</option>
                <option value="200000">£200,000</option>
                <option value="210000">£210,000</option>
                <option value="220000">£220,000</option>
                <option value="230000">£230,000</option>
                <option value="240000">£240,000</option>
                <option value="250000">£250,000</option>
                <option value="260000">£260,000</option>
                <option value="270000">£270,000</option>
                <option value="280000">£280,000</option>
                <option value="290000">£290,000</option>
                <option value="300000">£300,000</option>
                <option value="325000">£325,000</option>
                <option value="350000">£350,000</option>
                <option value="375000">£375,000</option>
                <option value="400000">£400,000</option>
                <option value="425000">£425,000</option>
                <option value="450000">£450,000</option>
                <option value="475000">£475,000</option>
                <option value="500000">£500,000</option>
                <option value="550000">£550,000</option>
                <option value="600000">£600,000</option>
                <option value="650000">£650,000</option>
                <option value="700000">£700,000</option>
                <option value="800000">£800,000</option>
                <option value="900000">£900,000</option>
                <option value="1000000">£1,000,000</option>
                <option value="1250000">£1,250,000</option>
                <option value="1500000">£1,500,000</option>
                <option value="1750000">£1,750,000</option>
                <option value="2000000">£2,000,000</option>
                <option value="2500000">£2,500,000</option>
                <option value="3000000">£3,000,000</option>
                <option value="4000000">£4,000,000</option>
                <option value="5000000">£5,000,000</option>
                <option value="7500000">£7,500,000</option>
                <option value="10000000">£10,000,000</option>
                <option value="15000000">£15,000,000</option>
                <option value="20000000">£20,000,000</option>
                <option value="">Max Price</option>
            </select>
        </div>
        <div class="col-xs-12 col-sm-4 col-md-3 form-group select">
            <select name="Type" id="PropertyType" class="form-control">
                <option value="all">Any Type</option>
                <option value="bungalow">
                    Bungalow
                </option>
                <option value="cottage">
                    Cottage
                </option>
                <option value="detached-barn-conversion">
                    Detached Barn Conversion
                </option>
                <option value="detached-bungalow">
                    Detached bungalow
                </option>
                <option value="detached-chalet-bungalow">
                    Detached Chalet Bungalow
                </option>
                <option value="detached-house">
                    Detached House
                </option>
                <option value="en-suite">
                    En-suite
                </option>
                <option value="end-terrace">
                    End Terrace
                </option>
                <option value="flats-apartments">
                    Flats / Apartments
                </option>
                <option value="house">
                    Houses
                </option>
                <option value="land">
                    Land
                </option>
                <option value="mid-terrace">
                    Mid terrace
                </option>
                <option value="q-type">
                    Q type
                </option>
                <option value="semi-detached">
                    Semi detached
                </option>
                <option value="semi-detached-barn-conversion">
                    Semi Detached Barn Conversion
                </option>
                <option value="semi-detached-bungalow">
                    Semi Detached Bungalow
                </option>
                <option value="shop">
                    Shop
                </option>
            </select>
        </div>
    
        <div class="col-xs-12 col-sm-4 col-md-3 form-group select">
            <select name="Status" id="PropertyStatus" class="selectpicker form-control">
                <option value="all">Any Status</option>
                <option value="for-sale">
                    For Sale
                </option>
                <option value="sold">
                    Sold!
                </option>
                <option value="to-let">
                    To Let
                </option>
            </select>
    
        </div>
        @*<div class="row">*@
        <div class="col-xs-12 col-sm-4 col-md-3 form-group">
            <input type="submit" value="@(GetDictionaryValue("[ezSearch] Search", "Search"))" class="btn btn-primary form-control" />
        </div>
    
        @*</div>*@
        @*<div class="col-xs-12 col-sm-4 col-md-3 form-group select">
               <select name="q" id="" class="form-control">
                @foreach (var status in model.SearchPropertyStatuses)
                {
                    <option selected="@(status.Value == model.SearchPropertyStatus ? "selected" : " ")" value="@status.Value">@status.Text</option>
                }
                </select>
    
            </div>*@
        @*<input type="text" name="q" placeholder="@(GetDictionaryValue("[ezSearch] Search", "Search"))" value="@(model.SearchTerm)" />*@
    
    </form>
    

    }

    @helper RenderSummary(SearchViewModel model) {

    @FormatHtml(GetDictionaryValue("[ezSearch] Summary", "Your search for \"{0}\" matched {1} page(s)."), model.SearchTerm, model.TotalResults)

    }

    @helper RenderResultsRange(SearchViewModel model) { var startRecord = ((model.CurrentPage - 1) * model.PageSize) + 1; var endRecord = Math.Min(model.TotalResults, (startRecord - 1) + model.PageSize);

    <div class="ezsearch-result-count">
        <p>@FormatHtml(GetDictionaryValue("[ezSearch] Results Range", "Showing results <strong>{0}</strong> to <strong>{1}</strong>."), startRecord, endRecord)</p>
    </div>
    

    }

    @helper RenderResults(SearchViewModel model) {

    @foreach (var result in model.PagedResults) { switch (result.Fields["__IndexType"]) { case UmbracoExamine.IndexTypes.Content: var contentItem = Umbraco.TypedContent(result.Fields["id"]); @RenderContentResult(model, contentItem) break; case UmbracoExamine.IndexTypes.Media: var mediaItem = Umbraco.TypedMedia(result.Fields["id"]); @RenderMediaResult(model, mediaItem) break; } }
    }

    @helper RenderContentResult(SearchViewModel model, IPublishedContent result) {

    @foreach (var field in model.PreviewFields.Where(field => result.HasValue(field))) {

    @result.Name

    We are delighted to offer for sale this immaculately presented and imaginatively extended attractive…

    1
    @result.GetPropertyValue("propertyBedrooms") Bedrooms
    1 Bathroom
    1
    Sold STC @ @
    £2100000

                    </div>
                </section>
            }
        </div>
        @*<h2><a href="@result.Url">@result.Name</a></h2>
            @foreach (var field in model.PreviewFields.Where(field => result.HasValue(field)))
            {
                <p>@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)</p>
                break;
            }*@
    </div>
    }
    
    @helper RenderMediaResult(SearchViewModel model, IPublishedContent result)
    {
    <div class="ezsearch-result">
        <h2><a href="@(result.GetPropertyValue<string>("umbracoFile"))" class="@(result.GetPropertyValue<string>("umbracoExtension"))">@result.Name</a></h2>
        @foreach (var field in model.PreviewFields.Where(field => result.HasValue(field)))
        {
            <p>@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)</p>
            break;
        }
    </div>
    

    }

    @helper RenderPager(SearchViewModel model)
    {
        <div class="ezsearch-pager">
            <p>
                @if (model.CurrentPage > 1)
                {
                    <a class="prev" href="?q=@(model.SearchTerm)&p=@(model.CurrentPage-1)">@(GetDictionaryValue("[ezSearch] Previous", "Previous"))</a>
                }
                else
                {
                    <span class="prev">@(GetDictionaryValue("[ezSearch] Previous", "Previous"))</span>
                }
            @for (var i = 1; i <= model.TotalPages; i++)
            {
                if (i == model.CurrentPage)
                {
                    <span class="page">@i</span>
                }
                else
                {
                    <a class="page" href="?q=@(model.SearchTerm)&p=@(i)">@i</a>
                }
            }
    
            @if (model.CurrentPage < model.TotalPages)
            {
                <a class="next" href="?q=@(model.SearchTerm)&p=@(model.CurrentPage + 1)">@(GetDictionaryValue("[ezSearch] Next", "Next"))</a>
            }
            else
            {
                <span class="next">@(GetDictionaryValue("[ezSearch] Next", "Next"))</span>
            }
        </p>
    </div>
    }
    
    @helper RenderNoResults(SearchViewModel model)
    {
        <div class="ezsearch-no-results">
            <p>@FormatHtml(GetDictionaryValue("[ezSearch] No Results", "No results found for search term <strong>{0}</strong>."), model.SearchTerm)</p>
        </div>
    
    
      }
    
    @functions
    {
        // ==================================================
        //  Helper Functions
        //==================================================
    // Cleanse the search term
    public string CleanseSearchTerm(string input)
    {
        return Umbraco.StripHtml(input).ToString();
    }
    
    // Splits a string on space, except where enclosed in quotes
    public IEnumerable<string> Tokenize(string input)
    {
        return Regex.Matches(input, @"[\""].+?[\""]|[^ ]+")
            .Cast<Match>()
            .Select(m => m.Value.Trim('\"'))
            .ToList();
    }
    
    // Highlights all occurances of the search terms in a body of text
    public IHtmlString Highlight(IHtmlString input, Dictionary<string,string> searchTerms)
    {
        return Highlight(input.ToString(), searchTerms);
    }
    
    // Highlights all occurances of the search terms in a body of text
    public IHtmlString Highlight(string input, Dictionary<string,string> searchTerms)
    {
        input = HttpUtility.HtmlDecode(input);
    
        foreach (var searchTerm in searchTerms)
        {
            input = Regex.Replace(input, Regex.Escape(searchTerm.Value), @"<strong>$0</strong>", RegexOptions.IgnoreCase);
        }
    
        return new HtmlString(input);
    }
    
    // Formats a string and returns as HTML
    public IHtmlString FormatHtml(string input, params object[] args)
    {
        return Html.Raw(string.Format(input, args));
    }
    
    // Gets a dictionary value with a fallback
    public string GetDictionaryValue(string key, string fallback)
    {
        var value = Umbraco.GetDictionaryValue(key);
    
        return !string.IsNullOrEmpty(value)
            ? value
            : fallback;
    }
    
    // Truncates a string on word breaks
    public string Truncate(IHtmlString input, int maxLength)
    {
        return Truncate(input.ToString(), maxLength);
    }
    
    // Truncates a string on word breaks
    public string Truncate(string input, int maxLength)
    {
        var truncated = Umbraco.Truncate(input, maxLength, true).ToString();
        if (truncated.EndsWith("&hellip;"))
        {
            var lastSpaceIndex = truncated.LastIndexOf(' ');
            if (lastSpaceIndex > 0)
            {
                truncated = truncated.Substring(0, lastSpaceIndex) + "&hellip;";
            }
        }
    
        return truncated;
    }
    
    // Gets a macro parameter in a safe manner with fallback
    public string GetMacroParam(PartialViewMacroModel model, string key, string fallback)
    {
        return GetMacroParam(model, key, s => s, fallback);
    }
    
    // Gets a macro parameter in a safe manner with fallback
    public TType GetMacroParam<TType>(PartialViewMacroModel model, string key, Func<string, TType> convert, TType fallback)
    {
        if (!model.MacroParameters.ContainsKey(key))
        {
            return fallback;
        }
    
        var value = model.MacroParameters[key];
        if (value == null || value.ToString().Trim() == "")
        {
            return fallback;
        }
    
        try
        {
            return convert(value.ToString());
        }
        catch (Exception)
        {
            return fallback;
        }
    }
    
    // Splits a coma seperated string into a list
    public IList<string> SplitToList(string input)
    {
        return input.Split(',')
            .Select(f => f.Trim())
            .Where(f => !string.IsNullOrEmpty(f))
            .ToList();
    }
    
    // ==================================================
    //  Helper Classes
    //==================================================
    
    public class SearchViewModel
    {
        // Query Parameters
        //public string SearchPropertyStatus { get; set; }
        //public List<SelectListItem> SearchPropertyStatuses { get; set; }
        public string Location { get; set; }
        public int MinPrice { get; set; }
        public int MaxPrice { get; set; }
    
        public string SearchTerm { get; set; }
        public Dictionary<string, string> SearchTerms { get; set;}
        //public IEnumerable<string> SearchTerms { get; set; }
        public int CurrentPage { get; set; }
    
        // Options
        public int RootContentNodeId { get; set; }
        public int RootMediaNodeId { get; set; }
        public string IndexType { get; set; }
        public IList<string> SearchFields { get; set; }
        public IList<string> PreviewFields { get; set; }
        public int PreviewLength { get; set; }
        public int PageSize { get; set; }
        public string HideFromSearchField { get; set; }
        public string SearchFormLocation { get; set; }
    
        // Results
        public int TotalResults { get; set; }
        public int TotalPages { get; set; }
    
        public IEnumerable<SearchResult> AllResults { get; set; }
        public IEnumerable<SearchResult> PagedResults { get; set; }
    }
    }
    
  • Andrew Bright 84 posts 244 karma points
    Jan 11, 2017 @ 13:53
    Andrew Bright
    100

    Managed to get this resolved by implementing the below:

       if (model.MinPrice >= 0 && model.MaxPrice > 0)
        {
            var paddedLower = model.MinPrice.ToString("D6");
            var paddedHigher = model.MaxPrice.ToString("D6");
            //groupedOr.AppendFormat(String.Format(searchField + ":[{0} TO {1}]", model.MinPrice, model.MaxPrice));
            query.And().Range("price", paddedLower, paddedHigher, true, true);
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft