I am currently developing "search as you type"-functionality for our client and I'm having trouble getting the .AnyWordBeginsWith to work. When I'm doing searches for "por" I want search hits for i.e. "pork" but it doesn't bring me those results other than when I search for "pork". I need help to see if I'm doing something wrong. Here's my the code for my search functionality:
var q = SearchClient.Instance.UnifiedSearchFor(query);
var queryStringQuery = (IQueriedSearch<ISearchContent, QueryStringQuery>)q;
q = queryStringQuery.WithAndAsDefaultOperator();
q = q.TermsFacetFor(x => x.SearchSection).TermsFacetFor(x => x.SearchFileExtension)
.FilterFacet("AllSections", x =>
.Filter(x => !x.MatchTypeHierarchy(typeof(ContainerPage)))
.OrFilter(x => x.MatchType(typeof(NewsPage)) & ((NewsPage)x).InCategory(3))
.OrFilter(x => x.MatchTypeHierarchy(startPageType))
.Filter(x => x.SearchTitle.AnyWordBeginsWith(query) | x.SearchText.AnyWordBeginsWith(query))
.Skip((PagingPage - 1) * searchPage.PageSize)
q = q.FilterHits(x => x.SearchSection.Match(SectionFilter));
q = q.FilterHits(x => x.SearchFileExtension.Match(FilesFilter));
var hitSpec = new HitSpecification
HighlightTitle = searchPage.HighlightTitles,
HighlightExcerpt = searchPage.HighlightExcerpts,
ExcerptLength = searchPage.ExcerptLength
Results = q.GetResult(hitSpec, true);
Have you checked out this post by Joel?
Hi, thanks for your answer.
Now I have read the post and that could be an alternative approach.
It seems that you can easily modify the extension in the post to do the expected work of an "AnyWordBeginsWith"
but now I'm really interested in how to get the anyWords..-extension to work (as per Find's own documentation)
I will try the suggestion out anyway and see if the warning about slow speed on large texts does apply to my case.
AnyWordBeginsWith was probably been added after that post. Are you sure all assemblies related to Find and Find CMS plugin are running as the latest version?
Hi,The AnyWordBeginsWith-filter should work as you describe but the issue is that you are only querying for documents that contain the complete word on line 1:var q = SearchClient.Instance.UnifiedSearchFor(query);(the For()-statement uses free text search to query for all hits that contain the words in the query.)If you want to use the AnyWordBeginsWith-filter you better use:var q = SearchClient.Instance.UnifiedSearch();and then filter all hits based on the filters.I also think you can remove the "AllSections" facet as it vill be equal to the total count./Henrik
Thanks. I'll try and work something out with the info you provided.
There's also an alternative to do:
SearchClient.Instance.UnifiedSearchFor(query).Include(x => x.Something.AnyWordBeginsWith("something"));
I'm not entirely sure the method is named "Include" and I'm not in a position to check at the moment, but it should be named something like that and will include things that match a filter even if they don't match a search query.