Good discussion, as Examine was driving me a little nuts and the umbraco.tv videos are for older versions, not as easy to implement as the above. My version shown below, but TWO KEY steps that I discovered only through other forum articles:
My search results were erratic, found out it was case-sensitivity (as mentioned here). Edit the /config/ExamineSettings.config file to replace "WhitespaceAnalyzer" with "Standard.StandardAnalyzer" for both the ExternalSearcher provider and ExternalIndexer, then rebuild the External index (easiest by install the "Examine Index" Umbraco package). The two "analyzer" lines in the .config file should read: analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" Would be nice on next releases to have that be the default since case-sensitivity is rarely desired and hard to diagnose
The LUKE Java tool to analyze indexes is great, but the most current verison (4.0 ALPHA) doesn't work on Umbraco Examine indexes (at least not those generated in Umbraco 6); use LUKE 3.5, works like a charm. In LUKE you can also tell if turning off the case-sensitivity (step 1) worked, as all index words should appear in lower case. Also, I found it handy to compare the total document count in LUKE with the total node count in BackOffice just to ensure it completed its task (create macro of "<p>@Model.Descendants().Count()</p>" and run it at your Home page node).
Happy to continue this discussion :) My razor code below:
@using Examine
@using Examine.SearchCriteria
@using UmbracoExamine
@{
var searchString = Request["search"];
if (!String.IsNullOrEmpty(searchString))
{
var searchProvider = ExamineManager.Instance.DefaultSearchProvider.Name;
var searcher = ExamineManager.Instance.SearchProviderCollection[searchProvider];
@* BooleanOperation.Or per our.umbraco.org/forum/core/general/28187-Examine-with-Razor *@
var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
var query = searchCriteria.GroupedOr(new string[] { "nodeName", "pageTitle", "pageSummary", "pageContent"}, searchString).Compile();
foreach (var c in searcher.Search(query))
{
<h4>
<a href="@umbraco.library.NiceUrl(c.Id)">
@* For our purposes, pageTitle looks better in search results than nodeName,
so if there is one, use it by default *@
@(c.Fields.Keys.Contains("pageTitle") ? c.Fields["pageTitle"] : c.Fields["nodeName"])
</a>
</h4>
@* We also like to display a bit of the page content (stole code from somewhere, sorry
not cited well.) *@
if(c.Fields.Keys.Contains("pageContent"))
{
var snippet = c.Fields["pageContent"];
if (snippet.Length>240)
{
snippet = snippet.Substring(0,240)+"...";
}
<p>@Html.Raw(snippet)</p>
}
}
}
}
Examine with Razor
I'm trying to write an examine query with Razor (both are new to me).
This is what I have so far:
This feels like it is almost there, but the one bit I am not certain about is that I get an error...
The name 'BooleanOperation' does not exist in the current context
Firstly is this on the right track can I do this?
and also how do I get that to exist in the current context :) ?
Hey John!
Try adding
This should give you access to BooleanOperation.Or
See if that resolves your issue.
thanks Peter - that is absolutely brilliant - that works now
I did feel terribly guilty tweeting knowing that v5 is so near !
thank you again :)
Good discussion, as Examine was driving me a little nuts and the umbraco.tv videos are for older versions, not as easy to implement as the above. My version shown below, but TWO KEY steps that I discovered only through other forum articles:
analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
Would be nice on next releases to have that be the default since case-sensitivity is rarely desired and hard to diagnose
Happy to continue this discussion :) My razor code below:
is working on a reply...