Skip to content

Commit

Permalink
Added search logic. You can now search per language.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbreuer committed Oct 3, 2016
1 parent 8de4b3d commit 5373f1a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
Binary file modified Sources/24days/App_Data/Umbraco.sdf
Binary file not shown.
2 changes: 1 addition & 1 deletion Sources/24days/App_Data/umbraco.config
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<urlSegment><![CDATA[{"values":{"nl-NL":"nieuws","en-US":"news","fr-FR":"neauws"},"dtdGuid":"fb50e229-2f59-48ca-9b16-c21927bfcf21"}]]></urlSegment>
<umbracoNaviHide>0</umbracoNaviHide>
<title><![CDATA[Adventure log]]></title>
<umbNewsItem id="1068" key="e7f0bc60-038d-447b-a13b-07d24e751ace" parentID="1065" level="3" creatorID="0" sortOrder="2" createDate="2015-12-06T16:21:21" updateDate="2016-09-30T15:13:07" nodeName="The future of Grid Layouts" urlName="the-future-of-grid-layouts" path="-1,1060,1065,1068" isDoc="" nodeType="1057" creatorName="Admin" writerName="Admin" writerID="0" template="1052" nodeTypeAlias="umbNewsItem">
<umbNewsItem id="1068" key="e7f0bc60-038d-447b-a13b-07d24e751ace" parentID="1065" level="3" creatorID="0" sortOrder="2" createDate="2015-12-06T16:21:21" updateDate="2016-10-03T13:24:21" nodeName="The future of Grid Layouts" urlName="the-future-of-grid-layouts" path="-1,1060,1065,1068" isDoc="" nodeType="1057" creatorName="Admin" writerName="Admin" writerID="0" template="1052" nodeTypeAlias="umbNewsItem">
<umbracoNaviHide>0</umbracoNaviHide>
<urlSegment><![CDATA[{"values":{"en-US":"The future of Grid Layouts","nl-NL":"De toekomst van grid layouts","fr-FR":"L'avenir de la grille Layouts"},"dtdGuid":"fb50e229-2f59-48ca-9b16-c21927bfcf21"}]]></urlSegment>
<publishDate>2015-12-06T19:21:44</publishDate>
Expand Down
64 changes: 62 additions & 2 deletions Sources/24days/Views/umbSearchPage.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
@using Umbraco.Extensions.Models
@using System.Threading
@using Umbraco.Extensions.Models
@inherits UmbracoTemplatePage<UmbSearchPage>
@{
Layout = "umbLayout.cshtml";
}

<p>@Umbraco.GetDictionaryValue("SearchTitle")</p>
<div id="main-wrapper">
<div id="main" class="container">
<div class="row">
<div class="12u skel-cell-mainContent">
<div class="content content-left">
<!-- Content -->
<article class="is-page-content">
<h2>@Umbraco.GetDictionaryValue("SearchTitle")</h2>

<form method="get">
<input type="text" name="q" value="@Request.QueryString["q"]">
<input type="submit" value="search">
</form>

@{
var q = Request.QueryString["q"];

if (!string.IsNullOrEmpty(q))
{
var currentCulture = Thread.CurrentThread.CurrentCulture.ToString();

var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];

var searchCriteria = searcher.CreateSearchCriteria();

// All page content is indexed per language. Search the content for the current language.
var query = searchCriteria.Field("PageContent-" + currentCulture, q.ToLowerInvariant());

var searchResults = searcher.Search(query.Compile()).OrderByDescending(x => x.Score);

if (searchResults.Any())
{
<ul>
@foreach (var item in searchResults)
{
var content = Umbraco.TypedContent(item.Fields["id"]);
if (content != null)
{
<li>
<a href="@content.Url">
@content.Name
@if (content is UmbNewsItem)
{
<text> - @(((UmbNewsItem)content).News.Subheader)</text>
}
</a>
</li>
}
}
</ul>
}
}
}
</article>
<!-- /Content -->
</div>
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions Sources/Umbraco.Extensions/Events/UmbracoEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private void ExternalIndexerGatheringContentData(object sender, IndexingNodeData
content.ExtractForExamine(searhContentBuilder, lang.CultureInfo.Name);

// Index all properties per language. For Vorto this means the properties for that language.
// If a property is not multilingual it will be added to all languages.
indexingNodeDataEventArgs.Fields.Add("PageContent" + "-" + lang.CultureInfo.Name, searhContentBuilder.ToString());
}
}
Expand Down

0 comments on commit 5373f1a

Please sign in to comment.