ezSearch not displaying content that has Public Access restrictions set
I've set up ezSearch straight out of the box and it's working fine (and I love it!)
However, as soon as I change the Public Access rights of a piece of content to be only availble to a specific Member Group, it disappears from the search results - even if I'm logged in with a user from that Member Group!
Digging into the ezSearch code, I've found the function that does the search (line 115):
First, I had to add an extra line to the ezSearchBootstrapper.cs file, to make it aware of the "Internal" Examine index - I added this line to the OnApplicationStarted() method (line 23):
Then I had to make changes to the ezSearch.cshtml file (the one stored in MacroPartials) to tell it which index to search from depending on if the user is logged in or not.
There is a line in there that by default uses the External Examine index:
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
and I changed this to allow use a parameter that I pass into the page:
var searcher = ExamineManager.Instance.SearchProviderCollection[indexToSearch];
Interesting... that line have the ExternalIndexer by default. Did you replace it with Internal or add next to the Internal (sorry if that sounds dumb, im learning as i go along)?
do you mean to say you have changed the line 23 function at ezSearchBootstrapper.cs to be like;
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
I dont think you need to remove that line, as what Maff commented, the line is added to existing.
Then you can follow Maff's suggestion to edit the file in your Umbraco installation and change Search provider if user logged in and dont change it not logged in
ezSearch not displaying content that has Public Access restrictions set
I've set up ezSearch straight out of the box and it's working fine (and I love it!)
However, as soon as I change the Public Access rights of a piece of content to be only availble to a specific Member Group, it disappears from the search results - even if I'm logged in with a user from that Member Group!
Digging into the ezSearch code, I've found the function that does the search (line 115):
var results = searcher.Search(criteria2)
.Where(x => (
!Umbraco.IsProtected(int.Parse(x.Fields["id"]), x.Fields["path"]) ||
(
Umbraco.IsProtected(int.Parse(x.Fields["id"]), x.Fields["path"]) && Umbraco.MemberHasAccess(int.Parse(x.Fields["id"]), x.Fields["path"])
)) && (
(x.Fields["__IndexType"] == UmbracoExamine.IndexTypes.Content && Umbraco.TypedContent(int.Parse(x.Fields["id"])) != null) ||
(x.Fields["__IndexType"] == UmbracoExamine.IndexTypes.Media && Umbraco.TypedMedia(int.Parse(x.Fields["id"])) != null)
))
.ToList();
The protected content is missing even if I strip out all the .Where() clauses and just use this:
var results = searcher.Search(criteria2).ToList();
Is this a bug with Examine, ezSearch or user error?
Thanks,
Maff
Hi Maff
Did you figure out a solution with the protected page search?
Hi Kielo,
Yes I figured this out out.
First, I had to add an extra line to the ezSearchBootstrapper.cs file, to make it aware of the "Internal" Examine index - I added this line to the OnApplicationStarted() method (line 23):
ExamineManager.Instance.IndexProviderCollection["InternalIndexer"].GatheringNodeData += OnGatheringNodeData;
Then I had to make changes to the ezSearch.cshtml file (the one stored in MacroPartials) to tell it which index to search from depending on if the user is logged in or not.
There is a line in there that by default uses the External Examine index:
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
and I changed this to allow use a parameter that I pass into the page:
var searcher = ExamineManager.Instance.SearchProviderCollection[indexToSearch];
Cheers,
Maff
Hi Maff
Interesting... that line have the ExternalIndexer by default. Did you replace it with Internal or add next to the Internal (sorry if that sounds dumb, im learning as i go along)?
do you mean to say you have changed the line 23 function at ezSearchBootstrapper.cs to be like;
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData += OnGatheringNodeData;
ExamineManager.Instance.IndexProviderCollection["InternalIndexer"].GatheringNodeData += OnGatheringNodeData;
}
and that allowed both Internal and External Index to be available for
var searcher = ExamineManager.Instance.SearchProviderCollection[indexToSearch];
where indexToSearch is the parameter you pass with value of InternalIndexer or ExternalIndexer - based on if user is logged in or not?
Am I following this correctly?
Its interesting indeed, that protected page support is not thought of. I dont think we are only ones who will be looking for such solution...
Hi Kielo,
I have both lines in there, to allow ezSearch to access either index:
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData += OnGatheringNodeData;
ExamineManager.Instance.IndexProviderCollection["InternalIndexer"].GatheringNodeData += OnGatheringNodeData;
}
and yes you are correct with the indexToSearch parameter - this should be set to either "ExternalIndexer" or "InternalIndexer"
Cheers,
Maff
I have tired the way you said......but getting error message as, error loading partial view script (file: ~/Views/MacroPartials/ezSearch.cshtml)
what exactly you want me to put in .cshtml
I have removed this line
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"] and added below line
var searcher = ExamineManager.Instance.SearchProviderCollection[indexToSearch];
Thanks in advance
Hi Harish
I dont think you need to remove that line, as what Maff commented, the line is added to existing.
Then you can follow Maff's suggestion to edit the file in your Umbraco installation and change Search provider if user logged in and dont change it not logged in
/Views/MacroPartials/ezSearch.cshtml
Hi Keilo,
Thanks for your reply ....but still did not work.....
dont know what to do....
Many Thanks
hi
when given indexToSearch, then complaining about could not find indexToSearch....
should i decalre else where in .cshtml...
please reply as soon as possible.....
Thanks in advance....
Isn't it easier to just let the ExternalIndexer also index protected nodes if that's not a problem?
Jeroen
That worked for me thanks. For future reference:
Open the "/Config/ExamineSettings.config" file.
Change this line:
to this:
I just incurred into this, I was getting mad... thanks for the info!
Michele
is working on a reply...