Am trying to create a product search on length, height and depth but am really struggling with the basics here. I am a Razor noob too. I'm using Umbraco 4.7.1 on IIS6 + SQL Server 2005
I have the following code but get and 'Object reference not set to an instance of an object' error. I thought i'd start by getting it to search on length only as it shouldn't be too difficult to add the others later.
@using Examine
@using Examine.SearchCriteria
@using UmbracoExamine
@{
var searchString = Request.QueryString["l"];
var searcher = ExamineManager.Instance.SearchProviderCollection["ProductSearchIndexSet"];
var searchCriteria = searcher.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
var filter = searchCriteria
.Field("productLength", searchString)
.And()
.Field("parentID", "1107")
.Not()
.Field("umbracoNaviHide", "1")
.Compile();
var searchResults = searcher.Search(filter);
}
<ul>
@foreach (var c in searchResults)
{
<li><a href="@umbraco.library.NiceUrl(c.Id)">@c.Fields["nodeName"]</a></li>
}
</ul>
Can someone help me out and show me the error of my ways?
Error Loading Razor Script (file: Search Results) Object reference not set to an instance of an object. at ASP._Page_macroScripts_Search_cshtml.Execute() in d:\Inetpub\wwwroot\myproj\macroScripts\Search.cshtml:line 9 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
var searchCriteria = searcher.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content);
I have tried removing the Index Type but this doesn't help. Is there somewhere with proper documentation on how to set this up in either Razor or as a usercontrol? I have watched the video on UmbracoTV but couldn't get that working and can't find a guide that i can get working.
I set the parameters wide enough to begin with so that it should find everything if they don't provide a parameter but i'm not sure why they aren't returning any results as the products do have these values in the correct fields.
This is my first examine/razor project and i am struggling badly. I wouldn't mind a usercontrol to do it in but i haven't been able to get one working in a way that i can understand.
Try outputting the actual Lucene query that is run in your macro, like so:
@searchCriteria.ToString()
put it after you do the compile().
If you are getting results in Luke then you can compare the queries in this way. I don't know anything about range queries so not able to help specifically on your query. Sounds like you are getting there through.
The reason the range doesn't work is because it's a text search rather than a numerical one so what need to happen is that the number needs to be padded out with zero's so i can do a proper comparison.
No worries glad I could help. NB If any of the responses answered your original question, don't forget to mark the solution to assist others that end up on this thread.
Examine Search
Hi,
Am trying to create a product search on length, height and depth but am really struggling with the basics here. I am a Razor noob too. I'm using Umbraco 4.7.1 on IIS6 + SQL Server 2005
I have the following code but get and 'Object reference not set to an instance of an object' error. I thought i'd start by getting it to search on length only as it shouldn't be too difficult to add the others later.
Can someone help me out and show me the error of my ways?
Thanks
Chris
What is the REAL error you're getting?? (add ?umbDebugShowTrace=true to the URL and scroll down to the red error in the trace).
Seb,
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Is this helpful?
Thanks
Chris
Sort of.. have a look at what is going on at line 9 of your code, it's the filter, right?
So what I'd do is start with an empty filter and add criteria 1 by 1.
Line 9 is
I have tried removing the Index Type but this doesn't help. Is there somewhere with proper documentation on how to set this up in either Razor or as a usercontrol? I have watched the video on UmbracoTV but couldn't get that working and can't find a guide that i can get working.
Thanks
Chris
Doesnt seem to be a problem with the searcher.
Try a simpler query like
and try to get that to work. If so refer to http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx for information on how to build up queries. It is also useful to download the Luke tool http://code.google.com/p/luke/ to ensure your indexes are all populated and you can return results from there first.
FYI I have my searcher and criteria set up as follows (simplified - some query building steps removed):
Not sure if this will help but something else to try perhaps
Barry,
I have downloaded luke and get some interesting results, i need to do a range search on 3 fields, my current code is as follows:
I set the parameters wide enough to begin with so that it should find everything if they don't provide a parameter but i'm not sure why they aren't returning any results as the products do have these values in the correct fields.
This is my first examine/razor project and i am struggling badly. I wouldn't mind a usercontrol to do it in but i haven't been able to get one working in a way that i can understand.
Thank you for your help so far.
Chris
Try outputting the actual Lucene query that is run in your macro, like so:
@searchCriteria.ToString()
put it after you do the compile().
If you are getting results in Luke then you can compare the queries in this way. I don't know anything about range queries so not able to help specifically on your query. Sounds like you are getting there through.
Barry,
The reason the range doesn't work is because it's a text search rather than a numerical one so what need to happen is that the number needs to be padded out with zero's so i can do a proper comparison.
Thanks for your all your help.
Chris
No worries glad I could help. NB If any of the responses answered your original question, don't forget to mark the solution to assist others that end up on this thread.
I followed this post and got the answer working in the end - http://our.umbraco.org/forum/using/ui-questions/16888-Examine-Search-Range-Values
Thanks
is working on a reply...