Currently I'm working on setting up a private site for customers to access Reference Manuals for our products.
So say I'm in Sub Page 1 under Parent Node 1 and I want to search for a definition that I know is in Page 3 of Parent node 1. I want a search function using EzSearch (if possible) that dynamically limits the search to the specific parent node that I'm within.
If someone could let me know if this is possible or knows how to do it that would be fantastic. In the mean time if I can come up with an answer before someone else I will post it in here.
I'm using ezsearch for a phonebook type search. Each person is stored as a page of doctype branchStaff. This is (I think level 3 nodes) created under a branch which is under Homepage. Is there a way I can force ezsearch to only search this level of node or else to only search by doctype?
you can specify the rootNode that you want ezSearch to start from, as in the post above.
Out of the box ezSearch doesn't limit searches by DocType.
I have added this code in a project recently to do this. chaning the ezSearch.cshtml
i added this to the search model.
var model = new SearchViewModel
{
... (existing bits) ...
NodesToSearch = GetMacroParam(Model, "nodesToSearch", s => SplitToList(s), new List<string> {}),
}
i then added this in the main section that builds the search query
(just above // Ensure page contains all search terms in some way)
if ( model.NodesToSearch.Any() )
{
foreach(var doctype in model.NodesToSearch)
{
query.AppendFormat("+nodeTypeAlias:({0}) ", doctype );
}
}
you can just add nodesToSearch = "doctypea,doctypeb" to the macro.
I did a similar thing for NodesToExclude so you could do it the other way around. I haven't gotten around to submitting a Pull request for ezSearch yet
You also need to add the parameter to the ezSearch macro (in macros section, click on the properties tab of the ezSearch Macro and add the NodesToSearch paramater), If you don't do this the parameter can be set but it never reaches the code.
Then you can add NodesToSearch to the the place you call ezSearch from (probibly you're template?) something like.
To anybody coming across this thread now, I used Kevin Jump's solution for limiting the search to document types, but found that if implemented as stated above, the search would only work on single document types. If multiple doctypes were entered, no results would be returned.
Kevin's solution will only work on multiple document types if the appended query string is written like this:
@* ADDED to limit searches to specified doctypes *@
if (model.NodesToSearch.Any())
{
var groupedOr = new StringBuilder();
foreach(var doctype in model.NodesToSearch)
{
groupedOr.AppendFormat("{0}* ", doctype);
}
query.Append("+nodeTypeAlias:(" + groupedOr.ToString() + ") ");
}
Also, Tony - I know you have probably solved this a long time ago, but for the benefit of others; your attempt here was not working because you named a parameter 'branchStaff' when it should have been named 'doctype', as per the variable name inside the scope of the foreach.
EzSearch Project
Currently I'm working on setting up a private site for customers to access Reference Manuals for our products.
So say I'm in Sub Page 1 under Parent Node 1 and I want to search for a definition that I know is in Page 3 of Parent node 1. I want a search function using EzSearch (if possible) that dynamically limits the search to the specific parent node that I'm within.
If someone could let me know if this is possible or knows how to do it that would be fantastic. In the mean time if I can come up with an answer before someone else I will post it in here.
Hi,
In ezSearch you can pass the root node for your search as a parameter to the macro.
I have a project where the search page is placed beneath the page you want to search from. the macro looks like this.
If you want to go upto a certain type of page (so if you parent pages have a specifc doctype). then you could get that by calling
var parent = Model.AncestorsOrSelf("name-of-doctype").Last()
this will get you the nearest parent of the doctype. (see https://our.umbraco.org/forum/developers/razor/28410-AncestorOrSelf-by-document-type)
Hi
I'm using ezsearch for a phonebook type search. Each person is stored as a page of doctype branchStaff. This is (I think level 3 nodes) created under a branch which is under Homepage. Is there a way I can force ezsearch to only search this level of node or else to only search by doctype?
Thanks. Tony
Hi,
you can specify the rootNode that you want ezSearch to start from, as in the post above.
Out of the box ezSearch doesn't limit searches by DocType.
I have added this code in a project recently to do this. chaning the ezSearch.cshtml
i added this to the search model.
i then added this in the main section that builds the search query (just above
// Ensure page contains all search terms in some way
)you can just add
nodesToSearch = "doctypea,doctypeb"
to the macro.I did a similar thing for NodesToExclude so you could do it the other way around. I haven't gotten around to submitting a Pull request for ezSearch yet
Hi Kevin
I'm obviously missing something here, I added
to the SearchViewModel, and the block of code to just above //Ensure page contains all search terms in some way.
Where does nodesToSearch = "branchStaff" go? branchStaff is my Document Type that I want to search.
Thanks. :)
HI,
yes i might have missed something too : (
You also need to add the parameter to the ezSearch macro (in macros section, click on the properties tab of the ezSearch Macro and add the NodesToSearch paramater), If you don't do this the parameter can be set but it never reaches the code.
Then you can add NodesToSearch to the the place you call ezSearch from (probibly you're template?) something like.
@Umbraco.RenderMacro("ezSearch", new { IndexType = "CONTENT", searchFormLocation = "Top", pageSize = 5, nodesToSearch="nodename" })
Hi Kevin
I think I must be having a blonde day!
And then I added the
@Umbraco.RenderMacro("ezSearch", new { IndexType = "CONTENT", searchFormLocation = "Top", pageSize = 5, nodesToSearch="branchStaff" })
to the template and if fails to load.
Thanks. Tony
don't worry it's nearly beer o'clock.
I would say the property should be textbox not content picker - as you are just passing a string.
that might be it.
Exactly - beer o clock. :) WooHoo!!
That didn't work so I'm going to revert to beer o clock and leave it till Monday....
Thanks :)
To anybody coming across this thread now, I used Kevin Jump's solution for limiting the search to document types, but found that if implemented as stated above, the search would only work on single document types. If multiple doctypes were entered, no results would be returned.
Kevin's solution will only work on multiple document types if the appended query string is written like this:
Also, Tony - I know you have probably solved this a long time ago, but for the benefit of others; your attempt here was not working because you named a parameter 'branchStaff' when it should have been named 'doctype', as per the variable name inside the scope of the foreach.
is working on a reply...