我构建了一个函数,我在其中传递了我想要搜索的国家字符串以及我想从搜索结果中获取的文章数量。
但是,当搜索从 Sitecore 内容项返回时,我不想在标题字段的开头显示有星号(*)的项。这是函数名称:
protected IEnumerable<Item> ShowHomePageNews(int numOfArticles, string stringofCountries)
{
List<Item> items = new List<Item>();
Sitecore.Search.Index indx = SearchManager.GetIndex("my_index_name");
using (IndexSearchContext searchContext = indx.CreateSearchContext())
{
CombinedQuery query = new CombinedQuery();
QueryBase catQuery = new FieldQuery("countries", stringofCountries); //FieldName, FieldValue.
SearchHits results = searchContext.Search(catQuery); //Searching the content items by fields.
SearchResultCollection result = results.FetchResults(0, numOfArticles);
foreach (SearchResult i in result)
{
Lucene.Net.Documents.Field url = i.Document.GetField("_url");
Sitecore.Data.ItemUri itemUri = new Sitecore.Data.ItemUri(url.StringValue());
Sitecore.Data.Items.Item item = Sitecore.Context.Database.GetItem(itemUri.ToDataUri());
items.Add(item);
}
}
return items;
}
我在我的 PageLoad 上调用这个函数:
rptHomePageNews.DataSource = ShowHomePageNews(4, "USA");
这是我的标记:
<asp:Panel ID="HomePageNews" runat="server">
<asp:Repeater ID="rptHomePageNews" runat="server">
<ItemTemplate>
<li>
<%--<sc:FieldRenderer ID="FieldRenderer1" FieldName="Date" runat="server" Item="<%# Container.DataItem as Sitecore.Data.Items.Item %>" />--%>
<a href="<%# Sitecore.Links.LinkManager.GetItemUrl(Container.DataItem as Sitecore.Data.Items.Item) %>">
<sc:FieldRenderer ID="FieldRenderer2" FieldName="Title" runat="server" Item="<%# Container.DataItem as Sitecore.Data.Items.Item %>" />
</a>
</li>
</ItemTemplate>
</asp:Repeater>
我应该在 ShowHomePageNews 函数中进行哪些更改?