Episerver Find autocomplete slow

Vote:
 

Hi All,

We have a very basic service setup to search and return the top 5 items from our Find index:

        [HttpGet]
        [AllowAnonymous]
        public JsonResult AutoComplete(string term)
        {
            
            var totalHits = SearchClient.Instance.Search<ContentPage>()
                .For(term)
              
                .GetContentResult()
                .Take(5).Select(x=>new  SearchAutoCompleteItems
                {
                    PageTitle = x.PageTitle,
                    Url = ContentService.Instance.GetExternalurl(x.PageLink)
                });


            return Json(totalHits, JsonRequestBehavior.AllowGet);
            
        }

The problem is that this is taking about 2 seconds to respond, it is a large index, any suggestions to speed it up?

Thanks in advance!

Paul

#253341
Apr 16, 2021 4:47
Vote:
 

Hi Paul,

Please try to apply the "Take" before you call the "GetContentResult" method

var totalHits = SearchClient.Instance.Search<ContentPage>()
                .For(term)
                .Take(5)
                .GetContentResult()
                .Select(x=>new  SearchAutoCompleteItems
                {
                    PageTitle = x.PageTitle,
                    Url = ContentService.Instance.GetExternalurl(x.PageLink)
                });
#253344
Apr 16, 2021 7:37
Vote:
 

Unfortunately moving the take up didn't resolve the speed issues, any other thoughts?

#253521
Apr 19, 2021 5:49
Vote:
 

Try using GetResult() instead of GetContentResult().

https://world.episerver.com/blogs/scott-reed/dates/2019/3/episerver-find---performance-reloading-custom-data-and-getcontent-vs-getcontentresult/

#253526
Apr 19, 2021 7:41
Vote:
 

Exactly what Tomas said.  Projections would be the first thing I would try.  Also, you could try caching your queries for a short duration to see if this improves overall site performance.

#253533
Apr 19, 2021 9:49
Vote:
 

This is not "autocomplete" - if you want to use the autocomplete feature by Find, take a look at IStatisticsClient.GetAutocomplete

Replies above are good practices:

It's unclear from your question what 2 seconds is for. I'd suggest to profile to see where it's slowest - the request to Find server, or GetContentResult, or something else. If you don't know what is slow, you can't effectively optimize it.

#253535
Apr 19, 2021 10:03
* 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.