-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchMapper3.cs
46 lines (42 loc) · 1.85 KB
/
SearchMapper3.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using ToSic.Sxc.Context;
using ToSic.Sxc.Search;
/*
Custom code which views use to customize how dnn search treats data of that view.
It's meant for customizing the internal indexer of the platform, _not_ for Google Search.
To use it, create a custom code (.cs) file which implements ICustomizeSearch interface.
You can also inherit from a DynamicCode base class (like Code12) if you need more functionality.
For more guidance on search customizations, see https://r.2sxc.org/customize-search
*/
public class SearchMapper3 : Custom.Hybrid.Code12, ICustomizeSearch
{
/// <summary>
/// Populate the search
/// </summary>
/// <param name="searchInfos">Dictionary containing the streams and items in the stream for this search.</param>
/// <param name="moduleInfo">Module information with which you can find out what page it's on etc.</param>
/// <param name="beginDate">Last time the indexer ran - because the data you will get is only what was modified since.</param>
public void CustomizeSearch(Dictionary<string, List<ISearchItem>> searchInfos, IModule moduleInfo, DateTime beginDate)
{
// Set this to true if you want to see logs of this search in the insights
// Only do this while developing, otherwise you'll flood the logs and never see the important parts
Log.Preserve = false;
foreach (var si in searchInfos["AllPosts"])
{
var entity = AsDynamic(si.Entity);
si.Title = "Title: " + entity.Title;
si.QueryString = "details=" + entity.UrlKey;
}
// Remove not needed streams
var keys = searchInfos.Keys.ToList();
foreach (var key in keys)
{
if (key != "AllPosts")
{
searchInfos.Remove(key);
}
}
}
}