I am looking to add a search bar on my front end to search for members. Any ideas how to go about this? I have a list of all members in alphabetical order on my frontend so far.
Thanks for that. I got it on the homepage, just have to figure out how to search for members now!It only seems to want to search for content or media. Needs further investigating....
I have the ez-search up and running. It only seems to search through Media and on Content it only finds page titles like Data Comms, Dual Development, .Net, Java... from the image
It doesn't seem to dig deep enough to pick words off the Content pages. So my Members are all displayed on a Content page and it can't see them!
What does your EZsearch configuration look like? You need to specify, which fields it should look at when you're doing your search and, which it should use to display the search results.
Hope this makes sense and that I have understood your issue.
Okay now I see the issue that you have. The way I think that you can solve this case is by adding the macro with the member data into the rich text editor, and then make the rich text editor searchable with the ezSearch package.
As Jan says you need to specify, which fields it should look at when you're doing your search and, which it should use to display the search results. Try to see this documentation https://our.umbraco.org/FileDownload?id=7816
Thanks for the pointers. I have the ezsearch macro in the Content editor and it still doesn't find data from the rte. I don't have a macro for the member data, I got this by using a foreach through all the members and displaying them on their own page (alphabetically too - top of the range!!). I am wondering if the macro for the ezsearch needs to be altered to make it search either on the rte where the members are displayed or else through members. My members have custom fields, so it might be easier just to search through the rte. This is the macroPartials.cshtml (sorry it's huge!).
@foreach (var result in model.PagedResults)
{
switch (result.Fields["__IndexType"])
{
case UmbracoExamine.IndexTypes.Content:
var contentItem = Umbraco.TypedContent(result.Fields["id"]);
@RenderContentResult(model, contentItem)
break;
case UmbracoExamine.IndexTypes.Media:
var mediaItem = Umbraco.TypedMedia(result.Fields["id"]);
@RenderMediaResult(model, mediaItem)
break;
}
}
// Cleanse the search term
public string CleanseSearchTerm(string input)
{
return Umbraco.StripHtml(input).ToString();
}
// Splits a string on space, except where enclosed in quotes
public IEnumerable<string> Tokenize(string input)
{
return Regex.Matches(input, @"[\""].+?[\""]|[^ ]+")
.Cast<Match>()
.Select(m => m.Value.Trim('\"'))
.ToList();
}
// Highlights all occurances of the search terms in a body of text
public IHtmlString Highlight(IHtmlString input, IEnumerable<string> searchTerms)
{
return Highlight(input.ToString(), searchTerms);
}
// Highlights all occurances of the search terms in a body of text
public IHtmlString Highlight(string input, IEnumerable<string> searchTerms)
{
input = HttpUtility.HtmlDecode(input);
foreach (var searchTerm in searchTerms)
{
input = Regex.Replace(input, Regex.Escape(searchTerm), @"<strong>$0</strong>", RegexOptions.IgnoreCase);
}
return new HtmlString(input);
}
// Formats a string and returns as HTML
public IHtmlString FormatHtml(string input, params object[] args)
{
return Html.Raw(string.Format(input, args));
}
// Gets a dictionary value with a fallback
public string GetDictionaryValue(string key, string fallback)
{
var value = Umbraco.GetDictionaryValue(key);
return !string.IsNullOrEmpty(value)
? value
: fallback;
}
// Truncates a string on word breaks
public string Truncate(IHtmlString input, int maxLength)
{
return Truncate(input.ToString(), maxLength);
}
// Truncates a string on word breaks
public string Truncate(string input, int maxLength)
{
var truncated = Umbraco.Truncate(input, maxLength, true).ToString();
if (truncated.EndsWith("…"))
{
var lastSpaceIndex = truncated.LastIndexOf(' ');
if(lastSpaceIndex > 0)
{
truncated = truncated.Substring(0, lastSpaceIndex) + "…";
}
}
return truncated;
}
// Gets a macro parameter in a safe manner with fallback
public string GetMacroParam(PartialViewMacroModel model, string key, string fallback)
{
return GetMacroParam(model, key, s => s, fallback);
}
// Gets a macro parameter in a safe manner with fallback
public TType GetMacroParam<TType>(PartialViewMacroModel model, string key, Func<string, TType> convert, TType fallback)
{
if(!model.MacroParameters.ContainsKey(key))
{
return fallback;
}
var value = model.MacroParameters[key];
if(value == null || value.ToString().Trim() == "")
{
return fallback;
}
try
{
return convert(value.ToString());
}
catch (Exception)
{
return fallback;
}
}
// Splits a coma seperated string into a list
public IList<string> SplitToList(string input)
{
return input.Split(',')
.Select(f => f.Trim())
.Where(f => !string.IsNullOrEmpty(f))
.ToList();
}
// ==================================================
// Helper Classes
//==================================================
public class SearchViewModel
{
// Query Parameters
public string SearchTerm { get; set; }
public IEnumerable<string> SearchTerms { get; set; }
public int CurrentPage { get; set; }
// Options
public int RootContentNodeId { get; set; }
public int RootMediaNodeId { get; set; }
public string IndexType { get; set; }
public IList<string> SearchFields { get; set; }
public IList<string> PreviewFields { get; set; }
public int PreviewLength { get; set; }
public int PageSize { get; set; }
public string HideFromSearchField { get; set; }
public string SearchFormLocation { get; set; }
// Results
public int TotalResults { get; set; }
public int TotalPages { get; set; }
public IEnumerable<SearchResult> AllResults { get; set; }
public IEnumerable<SearchResult> PagedResults { get; set; }
}
I've just noticed something interesting. I have two search bars working, one on my homepage and the other on my Staff Listing page (where all the staff are listed). The search on the homepage seems to only search for my links, any text on the homepage which is displayed from the Content Editor is ignored.
So over on the Staff Listing page nothing is found in the search as there are no links from it, no text is displayed (which is the staff names and their contact details) in a search either.
I should be necessary to change anything in the files to get the ezSeach search in content or media, you just need to configure which fields it should look into.
Thanks for your links. I don't understand what you did there. In theory it makes sense, like Jan said you need to specify, which fields it should look at when you're doing your search and, which it should use to display the search result. I have no idea how to do this in Umbraco....
Glad to see the forum is back up and running - hope the nuke went down well!
During the quiet time (or very noisy depending on where you are!) I went through ezSearch and discovered that it is finding my Media names, the names of the jpg images I have uploaded and in Content the page names. So would it be very unorthodox to have a page for every member and let the search find them that way, there could be 120 pages, though I would save them in folders according to their branches, for neatness. 99.5% of them won't need to access the site, they will be just viewing.
Just to finish this out and mark as solved. What I did was scrap the Members section and just set up a page for each member of staff here. We have 8 branches so I made a branch page and under each branch page there are staff pages. So, in effect each member of staff gets their own page. The page name is the member of staff's name and this shows up in the search. Even just the first letter like T, brings up all the T's - it's very powerful and fast. Later on we will give each branch manager a login to the back office to add staff members as they hire, so spreading the load!
Add a Search on frontend
Hi All
I am looking to add a search bar on my front end to search for members. Any ideas how to go about this? I have a list of all members in alphabetical order on my frontend so far.
I found this http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/examine/adding-a-search-to-your-website/TVPlayer# but can only see 2 minutes. I can't find a way to log in with my umbraco.tv subscription.
Thanks.
Tony
Hi Tony,
Perhaps you can use the ezSearch package https://our.umbraco.org/projects/website-utilities/ezsearch, it´s pretty nice to use when you need search functionality on your website. It think you could use it because it´s page content
Hope this could be a solution
/Dennis
Hi Dennis
Thanks for that. I got it on the homepage, just have to figure out how to search for members now!It only seems to want to search for content or media. Needs further investigating....
Tony
Hi Dennis
Forget the last comment - I misread yours!
I have the ez-search up and running. It only seems to search through Media and on Content it only finds page titles like Data Comms, Dual Development, .Net, Java... from the image
It doesn't seem to dig deep enough to pick words off the Content pages. So my Members are all displayed on a Content page and it can't see them!
Any ideas?
Thanks.
Tony
Hi Tony
What does your EZsearch configuration look like? You need to specify, which fields it should look at when you're doing your search and, which it should use to display the search results.
Hope this makes sense and that I have understood your issue.
/Jan
Hi Tony,
Okay now I see the issue that you have. The way I think that you can solve this case is by adding the macro with the member data into the rich text editor, and then make the rich text editor searchable with the ezSearch package.
For the documentation on how to add a macro into the rich text editor see here: http://umbraco.tv/videos/implementor/working-with-umbraco-data/macros/using-macros-in-the-rte/
As Jan says you need to specify, which fields it should look at when you're doing your search and, which it should use to display the search results. Try to see this documentation https://our.umbraco.org/FileDownload?id=7816
Hope this helps,
/Dennis
Hi Guys
Thanks for the pointers. I have the ezsearch macro in the Content editor and it still doesn't find data from the rte. I don't have a macro for the member data, I got this by using a foreach through all the members and displaying them on their own page (alphabetically too - top of the range!!). I am wondering if the macro for the ezsearch needs to be altered to make it search either on the rte where the members are displayed or else through members. My members have custom fields, so it might be easier just to search through the rte. This is the macroPartials.cshtml (sorry it's huge!).
Thanks a lot.
Tony
@using System.Globalization @using System.Text @using System.Text.RegularExpressions @using Examine @using Umbraco.Core.Logging @using Umbraco.Web.Models @inherits Umbraco.Web.Macros.PartialViewMacroPage @{ int parsedInt;
}
@*
Render Functions
*@
@helper RenderForm(SearchViewModel model) {
}@helper RenderSummary(SearchViewModel model) {
@FormatHtml(GetDictionaryValue("[ezSearch] Summary", "Your search for \"{0}\" matched {1} page(s)."), model.SearchTerm, model.TotalResults)
@helper RenderResultsRange(SearchViewModel model) { var startRecord = ((model.CurrentPage - 1)*model.PageSize) + 1; var endRecord = Math.Min(model.TotalResults, (startRecord - 1) + model.PageSize);
}
@helper RenderResults(SearchViewModel model) {
@helper RenderContentResult(SearchViewModel model, IPublishedContent result) {
@result.Name
@foreach (var field in model.PreviewFields.Where(field => result.HasValue(field))) {@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)
break; }@helper RenderMediaResult(SearchViewModel model, IPublishedContent result) {
@result.Name
@foreach (var field in model.PreviewFields.Where(field => result.HasValue(field))) {@Highlight(Truncate(Umbraco.StripHtml(result.GetPropertyValue(field).ToString()), model.PreviewLength), model.SearchTerms)
break; }@helper RenderPager(SearchViewModel model) {
@if (model.CurrentPage > 1) { @(GetDictionaryValue("[ezSearch] Previous", "Previous")) } else { @(GetDictionaryValue("[ezSearch] Previous", "Previous")) }
}
@helper RenderNoResults(SearchViewModel model) {
@FormatHtml(GetDictionaryValue("[ezSearch] No Results", "No results found for search term {0}."), model.SearchTerm)
@functions { // ================================================== // Helper Functions //==================================================
}
Hi Guys
I've just noticed something interesting. I have two search bars working, one on my homepage and the other on my Staff Listing page (where all the staff are listed). The search on the homepage seems to only search for my links, any text on the homepage which is displayed from the Content Editor is ignored.
So over on the Staff Listing page nothing is found in the search as there are no links from it, no text is displayed (which is the staff names and their contact details) in a search either.
Hopefully this makes sense. Thanks.
Tony
Hi Tony,
Perhaps it can help you if you see this post https://our.umbraco.org/projects/website-utilities/ezsearch/bugs-feedback-suggestions/50405-open-search-results-in-a-new-page, try to see my comment, I think it can help you to get it work.
I should be necessary to change anything in the files to get the ezSeach search in content or media, you just need to configure which fields it should look into.
Hope this helps,
/Dennis
Hi Dennis
Thanks for your links. I don't understand what you did there. In theory it makes sense, like Jan said you need to specify, which fields it should look at when you're doing your search and, which it should use to display the search result. I have no idea how to do this in Umbraco....
It's like digging a bigger hole! Thanks.
Tony
Hi Guys
Glad to see the forum is back up and running - hope the nuke went down well!
During the quiet time (or very noisy depending on where you are!) I went through ezSearch and discovered that it is finding my Media names, the names of the jpg images I have uploaded and in Content the page names. So would it be very unorthodox to have a page for every member and let the search find them that way, there could be 120 pages, though I would save them in folders according to their branches, for neatness. 99.5% of them won't need to access the site, they will be just viewing.
Thanks.
Tony
Hi Guys
Just to finish this out and mark as solved. What I did was scrap the Members section and just set up a page for each member of staff here. We have 8 branches so I made a branch page and under each branch page there are staff pages. So, in effect each member of staff gets their own page. The page name is the member of staff's name and this shows up in the search. Even just the first letter like T, brings up all the T's - it's very powerful and fast. Later on we will give each branch manager a login to the back office to add staff members as they hire, so spreading the load!
Thanks for all the help Dennis and Jan. :)
Tony
is working on a reply...