I have set up a search using examine and all works fine until you with the dreaded reserved words like 'is' 'and' etc. I put in a quick hack so any search term below 4 was ignored but this did not solve 'is and' not that it is a common search term but no my luck that what someone might test with that combo.
I saw something about it being caused by lucene but have not idea how to implment a fix this is what I have in the ExamineSettings.config:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Examine
@using Examine.SearchCriteria
@using Examine.LuceneEngine.SearchCriteria
@{
var searchString = Request["search"];
if (!string.IsNullOrEmpty(Request.QueryString["search"]))
{
//Fetching what eva searchterm some bloke is throwin' our way
var q = Request.QueryString["search"].Trim();
if (q.Length < 4)
{
q += " data";
}
//Fetching our SearchProvider by giving it the name of our searchprovider
var Searcher = Examine.ExamineManager.Instance.SearchProviderCollection["MySearchSearcher"];
var searchCriteria = Searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
var query = searchCriteria
.Field("nodeName", q.Boost(2)).Or()
.Field("nodeName", q.Fuzzy(0.5f)).Or()
.Field("bodyText", q.Boost(1)).Or()
.Field("bodyText", q.Fuzzy(0.5f)).Or()
.Field("tags", q.Fuzzy(0.8f));
//Searching and ordering the result by score, and we only want to get the results that has a minimum of 0.05(scale is up to 1.)
var searchResults = Searcher.Search(query.Compile()).OrderByDescending(x => x.Score).TakeWhile(x => x.Score > 0.05f);
//Printing the results
foreach (var item in searchResults)
{
var node = Umbraco.Content(item.Fields["id"]);
<h4>
<a href="@node.NiceUrl">
@node.Name
</a>
</h4>
@Html.Raw(node.bodyText)
}
}
}
I have read something about Lucene.Net.Analysis.StopAnalyzer.ENGLISHSTOPWORDS_SET but have been unable to get this to work andy suggestions would be welcome.
Should point out the error I get when searching if it helps:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 14:
Line 15: var searchCriteria = Searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
Line 16: var query = searchCriteria
Line 17: .Field("nodeName", q.Boost(2)).Or()
Line 18: .Field("nodeName", q.Fuzzy(0.5f)).Or()
Umbraco 7 examine search with reserved words
I have set up a search using examine and all works fine until you with the dreaded reserved words like 'is' 'and' etc. I put in a quick hack so any search term below 4 was ignored but this did not solve 'is and' not that it is a common search term but no my luck that what someone might test with that combo.
I saw something about it being caused by lucene but have not idea how to implment a fix this is what I have in the ExamineSettings.config:
And ExamineIndex.config:
Then on the search result partial:
I have read something about Lucene.Net.Analysis.StopAnalyzer.ENGLISHSTOPWORDS_SET but have been unable to get this to work andy suggestions would be welcome.
Should point out the error I get when searching if it helps:
is working on a reply...