簡體   English   中英

Episerver查找方面

[英]Episerver find facets

我正在使用EPiServer建立一個restaurantfinder網站,並且正在使用EPiFind在該網站上進行搜索。 我遇到了一個問題。 盡管我僅在一種特定的頁面類型中進行搜索,但我試圖在頁面樹中使用一種頁面類型。 我的目標是能夠打印出頁面類型的標題。 因此,如果我搜索瑞典,則應該在頁面樹中列出所有位於頁面樹中的城市及其名稱。

我的代碼:

if (query == null && tags == null && cities == null)
{
    return View();
}

var q = SearchClient.Instance.Search<RestaurantPage>()
    .For(query)
    .TermsFacetFor(x => x.CityPage.HeadLine);

if (!string.IsNullOrWhiteSpace(cities))
{
    q = q.Filter(x => x.HeadLine.MatchCaseInsensitive(cities));
}
var results = q.Select(x => new SearchHit
{
    Title = x.HeadLine,
    Url = x.LinkURL,
    Tag = x.Tags,
    Adress = x.Adress,
    Latitude = x.Latitude,
    Longitude = x.Longitude,
    Image = x.RestaurantImage
}).GetResult();

ViewBag.Query = query;
ViewBag.Id = results.ProcessingInfo.ServerDuration;
ViewBag.Hits = results.TotalMatching;

var facets = new List<FacetResult>();      
var testFacet = (TermsFacet)results.Facets["CityPage.HeadLine"];
var testLinks = new FacetResult("Cities", testFacet.Terms.Select(x => new FacetLink
{
    Text = x.Term,
    Count = x.Count,       
}));
facets.Add(testLinks);         

ViewBag.Filters = new List<FacetLink>();
if (!string.IsNullOrEmpty(tags))
{
    ViewBag.Filters.Add(new FacetLink
    {
        Text = tags,
        Url = Url.QueryBuilder(currentPage.ContentLink).AddSegment("?query=" + query).ToString()
    });
}


return View(new SearchResult(results, query) {Facets = facets});  

為了檢索構面,您可以執行以下操作:

results.TermsFacetFor<RestaurantPage>(x => x.CityPage.HeadLine)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM