2015-09-22 20 views
0

我正在用EPiServer建立一個restaurantfinder網站,我正在使用EPiFind在網站上進行搜索。但我遇到了一個問題。我試圖在pagetree中面向頁面類型,儘管我只在一個特定的頁面類型中進行搜索。我的目標是能夠打印出頁面的標題。因此,如果我搜索瑞典的例子,那麼在頁面樹中的所有城市都應該在他們的名字中列出。Episerver找到方面

我的代碼:

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}); 
+0

你沒有得到任何方面的一切,或者不是你期待的嗎? –

+0

@TedNyberg我得到了一些方面,只是不包括在上面的代碼。 – Fredrik

+0

我想說CityPage屬性(一個PageData對象?)沒有索引。我的猜測是你需要配置你的索引來明確地包含那個屬性,或者可能包含Headline屬性。 –

回答

0

爲了獲取方面,你可以這樣做:

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