Copied to clipboard

Flag this post as spam?

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


  • UmbracoNewb 6 posts 26 karma points
    Nov 06, 2012 @ 19:48
    UmbracoNewb
    0

    Examine Querystring if value is null

    Im using two check boxes one called eftervaern and one called kriminalitet. If one of the two checkbox's is not checked the script won't run. Is it not possible to use a variable in searchCriteria that potentially could be equal null? Is there a way around this? im lost for ideas atm.

    @using Examine

    @using Examine.SearchCriteria

    @{

        //Get the values posted from the form

    var eftervaern = Request.QueryString["eftervaern"];

    var kriminalitet = Request.QueryString["kriminalitet"];

        var searcher = ExamineManager.Instance.SearchProviderCollection["RazorSiteSearcher"];

        var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);

     

    var query = searchCriteria.Field("eftervaern", @eftervaern).Or().Field("kriminalitet", @kriminalitet).Compile();

        var searchResults   = searcher.Search(query);

        var noResults       = searchResults.Count();

     

        <ul class="search-results">

            @foreach (var result in searchResults)

            {

                <li>

                    <a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["nodeName"]</a>

                </li>

            }

        </ul>

    }

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 07, 2012 @ 11:44
    Ismail Mayat
    0

    UmbracoNewb,

    Examine is an abstraction around lucene and in lucene you cannot do a query where a field you are querying on has no value.  So you would need to refactor your query so that if only eftervaern checked saerch on that and if only kriminalitet search on that. If both checked then do or. If nothing selected then you need to same? Unless you want to display message saying select one option?

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft