Skip to content

Commit

Permalink
Merge pull request #20 from Kentico/feature/crawler-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
seangwright authored Sep 22, 2023
2 parents dd2ccad + e55653f commit 2d9e05a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Kentico.Xperience.Lucene.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The constraint ensures that broken URLs lead to a "404 page not found" page and
builder.Services.AddDancingGoatServices();

builder.Services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
builder.Services.Configure<SearchOptions>(builder.Configuration.GetSection("SearchOptions"));

builder.Services.AddLocalization()
.AddControllersWithViews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public LuceneSearchResultModel<CafeSearchModel> Search(string searchText, int pa
var boolQuery = new BooleanQuery();
boolQuery.Add(new TermQuery(DrillDownQuery.Term(countryDim.IndexFieldName, "Country", f.Skip(1).ToArray())), Occur.MUST);
boolQuery.Add(query, Occur.MUST);
drillDownQuery.Add("Country", boolQuery);
drillDownQuery.Add("Country", boolQuery);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Kentico.Xperience.Lucene.Sample/Search/SearchOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DancingGoat.Search;

public class SearchOptions
{
public string WebCrawlerBaseUrl { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CMS.DocumentEngine;
using CMS.Helpers;
using Kentico.Content.Web.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;

namespace DancingGoat.Search;
Expand All @@ -10,14 +11,16 @@ public class WebCrawlerService
private readonly HttpClient httpClient;
private readonly IPageUrlRetriever urlRetriever;
private readonly IEventLogService eventLogService;
private readonly IAppSettingsService appSettingsService;

public WebCrawlerService(HttpClient httpClient, IPageUrlRetriever urlRetriever, IEventLogService eventLogService)
public WebCrawlerService(HttpClient httpClient, IPageUrlRetriever urlRetriever, IEventLogService eventLogService, IAppSettingsService appSettingsService, IOptions<SearchOptions> options)
{
this.appSettingsService = appSettingsService;
this.httpClient = httpClient;
// configure the client inside constructor if needed (add custom headers etc.)
this.httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, "SearchCrawler");
// get crawler base url from settings or site configuration, make sure that WebCrawlerBaseUrl is correct
string baseUrl = ValidationHelper.GetString(Service.Resolve<IAppSettingsService>()["WebCrawlerBaseUrl"], DocumentURLProvider.GetDomainUrl("DancingGoatCore"));
string baseUrl = ValidationHelper.GetString(options.Value.WebCrawlerBaseUrl, DocumentURLProvider.GetDomainUrl("DancingGoatCore"));
this.httpClient.BaseAddress = new Uri(baseUrl);

this.urlRetriever = urlRetriever;
Expand Down
5 changes: 4 additions & 1 deletion src/Kentico.Xperience.Lucene.Sample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"CMSConnectionString": ""
},
"CMSHashStringSalt": "195a79ed-c559-42d8-b801-5857fc07ab1c",
"WebCrawlerBaseUrl": "http://localhost:41489/"

"SearchOptions": {
"WebCrawlerBaseUrl": "http://localhost:41489/"
}
}

0 comments on commit 2d9e05a

Please sign in to comment.