Try our conversational search powered by Generative AI!

Console Application for testing Find - no results

Vote:
 

Hello,

I've been trying to setup a little test console application for Episerver Search & Navigation.  This is something that the training course does.

We already have an index that we use for development, and have crawled content in there.  I can get results back from within Episerver, so I'm doing something wrong in the console app.

I have a reference to the Episerver.Find.Framework package in Nuget, and this setup in the app.config:

<section name="episerver.find" type="EPiServer.Find.Configuration, EPiServer.Find" requirePermission="false" />


<episerver.find serviceUrl="https://usea02.find.episerver.net/[client secret]" defaultIndex="[Index reference]" />

It's a barebones program (see below), but not returning results.  I've even tried using fiddler to glean the differences between what's happening in Epi vs. the console.  I've tried using Typed vs. Unified as well.  

Would someone kindly point me in the right direction please?

			var client = Client.CreateFromConfig();

			//var hit = new HitSpecification();
			//hit.HighlightTitle = true;			

			var setup = client.UnifiedSearch(Language.English).ApplyBestBets().For("covid");
			//var setup = client.Search<LayoutPageData>().ApplyBestBets().For("covid");
				//.ExcludeDeleted().CurrentlyPublished()
			
			if(setup != null)
			{
				var results = setup.Take(30).GetResult();

				//client.Output();

				Console.WriteLine($"Results Count={results.TotalMatching}");
				foreach (var result in results)
				{
					Console.WriteLine($"Name = {result.Filename}");
				}
			}
			else
			{
				Console.WriteLine("Setup is null");
				
			}
#246540
Jan 08, 2021 14:23
Vote:
 

Hi Mark,

How are you creating the client? I guess Epi find can't use the standard way to create. What I would have tried is to put the find settings in the appsettings and create the client myself

<appSettings>
	<add key="find:service:url" value="yourserviceurl"/>
	<add key="find:index" value="yourindex"/>
</appSettings>

And use it in code

//get serviceUrl and indexName values from appSettings
var serviceUrl = ConfigurationManager.AppSettings["find:service:url"];
var indexName = ConfigurationManager.AppSettings["find:index"];
var remoteSearchClient = new Client(serviceUrl, indexName); 
var remoteSiteSearchResult = remoteSearchClient.UnifiedSearchFor(query).GetResult();

This is taken from a blog post from Mari Jørgensen https://getadigital.com/no/blogg/episerver-find-and-multiple-indexes/

-Sebastian

#246572
Jan 09, 2021 13:08
Vote:
 

Sebastian,

Thank you for the response, but it seems the client is being created properly with var client = Client.CreateFromConfig(); .  I've used fiddler and see the requests going to https://usea02.find.episerver.net/

The request is very basic in comparison to the one used directly from EPiServer though.  

{
    "query": {
        "filtered": {
            "query": {
                "query_string": {
                    "query": "covid",
                    "analyzer": "standard"
                }
            },
            "filter": {
                "term": {
                    "___types": "EpiSearchConsole.LayoutPageData"
                }
            }
        }
    },
    "facets": {
        "SearchCategories": {
            "terms": {
                "field": "SearchCategories$$string",
                "size": 100
            }
        }
    },
    "fields": [
        "___types",
        "ContentLink.ID$$number",
        "ContentLink.ProviderName$$string",
        "Language.Name$$string"
    ]
}
#246596
Jan 10, 2021 15:35
Vote:
 

Hi Mark,

Below code worked for me, maybe you can give a try. :) 

Just add required references in project and  you are good to go. What is important here is projection, refer below article for the same. 

https://world.episerver.com/documentation/developer-guides/search-navigation/NET-Client-API/searching/Projections/

    public class Program
    {
        static void Main(string[] args)
        {
            var client = new Client("Service_Url", "defaultIndex_willBeHere");
            var query = client.Search<IProductVariant>(Language.English)
                        .For(searchTerm)
                        .InField(x => x.DisplayName)
                        .InField(x => x.Summary)
                        .Select(x => new ProjectionModel
                        {
                            DisplayName = x.DisplayName,
                            Summary = x.Summary

                        }).Take(10);

            var searchResults = query.GetResult();
            if (searchResults.Count() == 0)
            {
                Console.WriteLine("No result found");
            }
            else
            {
                foreach (var item in searchResults)
                {
                    Console.WriteLine(item.DisplayName);
                    Console.WriteLine(item.Summary);
                    Console.WriteLine("-----------------------------------------------------");
                }
            }

        }
    }
    class ProjectionModel : IProductVariant
    {
        public string DisplayName { get; set; }
        public string Summary { get; set; }

    }
#247321
Edited, Jan 20, 2021 9:47
Vote:
 

@Mark: Did you solve this one?

#248126
Feb 04, 2021 7:27
Vote:
 

@Mari,

Thank you for checking on on this one.  Your timing is perfect.  I had not solved it but dropped this for a while.  I sorted out my issue by working with the entire CMS solution.  I have to do some search inhancements again and really wanted to get this console app working.  It would be a lot quicker to work with.

@Ashish, thank you for your response, but that didn't work out for me either.  I'm not quite sure what I'm doing wrong.  This is just a bare bones console app.  I was trying to just use UnifiedSearch so I didn't need to bring the entire page object model over from the main solution.

Mark

#248159
Feb 04, 2021 15:15
Vote:
 

The UnifiedSearch documentation says: 

Note: The GetResult method modifies search queries by searching for objects that implement ISearchContent and for all types added to the UnifiedSearchRegistry. The GetResult method also adds a projection from ISearchContent to UnifiedSearchHit with sensible defaults, along with any type-specific projections added to the UnifiedSearchRegistry. Finally, before executing a search query (such as the GetResult method), Unified Search adds type-specific filters that were added to the UnifiedSearchRegistry.

How is UnifiedSearch "configured" in your main solution? Do you use unified search or typed search? Have you implemented ISearchContent interface or made any changes to conventions (UnifiedSearchRegistry)?

#248447
Feb 10, 2021 14:22
Vote:
 

Mari,

Thank you for this.  Sorry, I had to sit this down for a while.  I think you pointed out some vital information here.  ISearchContent has not been implemented.  I'll have to look into this and I'll update the thread with my results when I can.

Cheers,

Mark

#249289
Feb 26, 2021 15:35
Vote:
 

I just wanted to loop back on this thread.  I think the problem I encountered was due to our site having multiple subsites.  In the Console application I believe the wrong default filter was being used, and it was filtering results for the wrong SiteId.

I came across this example and it seemed to give me results from all the sites.

https://world.optimizely.com/forum/developers-add-ons-forum/Search/Thread-Container/2018/11/disable--filteroncurrentsite-for-unifiedsearch/?_gl=1*qin1fn*_ga*NzQ5Njk3MTMxLjE2NjEzNTQ5NjU.*_ga_C7SLJ6HMJ5*MTY2NjgxMzY3Ni4zMy4xLjE2NjY4MTU1MDQuNjAuMC4w

This is an excerpt of code that Peter Gustafsson has in that above thread.  It was decompiled from Episerver.Find.CMS.  The FilterOnCurrentSite<IContentData>() was just commented out, and that allowed for results.

// Code from CmsUnifiedSearchSetUp.cs in Episerver.Find.Cms DLL 13.0.5
var cmsUnifiedSearchSetup = new EPiServer.Find.Cms.CmsUnifiedSearchSetUp();

SearchClient.Instance.Conventions.UnifiedSearchRegistry.Add<PageData>()
    .PublicSearchFilter((Func<IClient, ISearchContext, Filter>)((c, ctx) => (Filter)c.BuildFilter<IContentData>()
        .FilterForVisitor<IContentData>(this.GetLanguage(ctx)
        ).ExcludeContainerPages<IContentData>()
        .ExcludeContentFolders<IContentData>()
        //.FilterOnCurrentSite<IContentData>()
        ))
    .CustomizeIndexProjection(new Func<IndexProjectionBuilder, IndexProjectionBuilder>(cmsUnifiedSearchSetup.CustomizeIndexProjectionForPageData))
    .CustomizeProjection(new Func<HitProjectionBuilder, HitProjectionBuilder>(cmsUnifiedSearchSetup.CustomizeProjectionForPageData));
#290855
Oct 31, 2022 15:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.