3

Recently I've been experimenting with EPiServerFind, I'm trying to figure out how wildcard queries are used.

I am encountering the following difficulty:

One of my colleagues has set up a POC with EPiServerFind, sadly this only searches for the entire word. For example: If you search 'applepie' you will find the page but searching 'apple' or 'pie' won't find the page. I've looked into wildcard queries to solve this, however I get unexpected results when I use them.

Details Like I've pointed out earlier, whenever I query EPiServerFind I get only full word matches.

var basicSearch = _client.Search<IContent>()
    .For(q)
        .InFields(x => x.Name, x => x.SearchTitle(), x => x.SearchText())
        .InAllField()
    .ExcludeContainerPages()
    .ExcludeContentFolders()
    .ExcludeDeleted()
    .GetContentResult()
    .Select(CreateSearchHitViewModel)
    .Where(x => x != null);

I've used an article of Joel Abrahamsson to help me with the implementation of the wildcard query:

var wildcardSearch = _client.Search<IContent>()
    .WildCardQuery(String.Format("*{0}*", q), x => x.Name)
    .WildCardQuery(String.Format("*{0}*", q), x => x.SearchTitle())
    .WildCardQuery(String.Format("*{0}*", q), x => x.SearchText())
    .ExcludeContainerPages()
    .ExcludeContentFolders()
    .ExcludeDeleted()
    .GetContentResult()
    .Select(CreateSearchHitViewModel)
    .Where(x => x != null);

I've used this blog: http://joelabrahamsson.com/wildcard-queries-with-EPiServer-find/

Sadly I get unexpected results when I use this. I get a few unrelated results but more of the relevant results are completely ignored.

I have no clue as to where this is failing and I hope someone can tell me.

Thank you in advance.

Marvin Brouwer
  • 306
  • 3
  • 13

1 Answers1

8

As posted on EPiServer World it seems like you can do it by:

.For(searchTerm, q =>
{
q.Query = searchTerm + "*";
}).InField(x => x.Name)

And I guess you could add wildcard before the word as well.

erik_nw
  • 837
  • 5
  • 11
  • I've added this code to my Episerver Find query to try to match using a wildcard but I still only receive whole word results. Should this still work in newer versions? I am using v11.1.0.3965 – ScoobyDrew18 May 02 '17 at 14:05
  • Works for me as well in EPiServer.Find v13.0.5 – Vojta Jemelka Mar 01 '19 at 15:12