.AnyWordBeginsWith

Vote:
 

Hi.

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);

if (searchPage.UseAndForMultipleSearchTerms)
{
var queryStringQuery = (IQueriedSearch<ISearchContent, QueryStringQuery>)q;
q = queryStringQuery.WithAndAsDefaultOperator();
}

q = q.TermsFacetFor(x => x.SearchSection).TermsFacetFor(x => x.SearchFileExtension)

.FilterFacet("AllSections", x =>
x.SearchTitle.Exists()
| !x.SearchTitle.Exists())

.Filter(x => !x.MatchTypeHierarchy(typeof(ContainerPage)))
.Filter(
x =>
!x.MatchTypeHierarchy(typeof(SitePageData)) |
((SitePageData)x).CurrentStartPageId.Match(currentStartPage))
.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)
.Take(searchPage.PageSize)

.ApplyBestBets();

if (!string.IsNullOrWhiteSpace(SectionFilter))
{
q = q.FilterHits(x => x.SearchSection.Match(SectionFilter));
}

if (!string.IsNullOrWhiteSpace(FilesFilter))
{
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);

    

#70954
May 06, 2013 11:24
Vote:
 
#70963
Edited, May 06, 2013 13:55
Vote:
 

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.

#70972
May 06, 2013 15:04
Vote:
 

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?

#70973
May 06, 2013 15:09
Vote:
 

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


#70974
Edited, May 06, 2013 15:36
Vote:
 

Thanks. I'll try and work something out with the info you provided.

/Alex

#71142
May 10, 2013 15:36
Vote:
 

Hi!

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.

#71204
May 14, 2013 10:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.