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();
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?
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>
}
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
is working on a reply...