Out of curiosity, did you ever find a way to do this?
I'm thinking of writing a custom GatheringNodeData event to handle it as it doesn't seem obvious to do it any other way. It's quite an overhead hitting the db each time I want to query if a member is in a particular group..
I have in my mind that it was necessary to change the analyzer, but my code appears to be using the StandardAnalyzer, so maybe it wasn't an issue in the end. It had something to do with spaces between the comma's, so make sure there aren't any when putting the groups into Examine.You can then query the index as normal. I wrote a couple of helper methods to return a members groups and to return all members within groups etc.
well, I can share what I used, though you will want to adapt them to your needs:
/// Return a list of member groups for a given Member Id publicstaticList<string>MemberGroups(intmemberId){varsearcher=ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];varsearchCriteria=searcher.CreateSearchCriteria();varquery=searchCriteria.Field("id",memberId.ToString());varcompiledQuery=query.Compile();varresults=(Examine.LuceneEngine.SearchResults)searcher.Search(compiledQuery);varreturnList=newList<string>();foreach(varresultinresults){if(result.Fields.Keys.Contains("_memberGroups")){returnresult.Fields["_memberGroups"].ToString().Split(',').ToList();}}returnreturnList;}
/// Returns a list of MyCustomMemberClass for any given member group names ( publicstaticList<MyCustomMemberClass>GetCustomerMembersByGroups(IEnumerable<string>groupNames){varsearcher=ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];varsearchCriteria=searcher.CreateSearchCriteria();varquery=searchCriteria.GroupedOr(newstring[]{"_memberGroups"},groupNames.ToArray()).And().Field("nodeTypeAlias","customer");varcompiledQuery=query.Compile();varresults=(Examine.LuceneEngine.SearchResults)searcher.Search(compiledQuery);varmemberList=newList<MyCustomMemberClass>(); if(results.Count()>0){foreach(varresultinresults){if(result.Fields.Keys.Contains("_memberGroups")){memberList.Add(newMyCustomMemberClass{Id=Convert.ToInt32(result.Fields["id"].ToString()),LoginName=result.Fields["loginName"].ToString()});}}}returnmemberList;}
Hey Mark! I got everything going thanks to your great help with the code sample! Wish I could mark your answer as a solution, but I didn't originate the post so can't help there.
Thank you Mark. Not only did it help with the exceedingly slow member queries I'm doing in a business layer, but getting the groups was a bonus. Besides adapting it for my situation, I am rebuilding the index on app start (seemed to be an issue with existing data not being indexed).
How to Add Member Group in Examine Index
Hi,
I'm currently using the Internal Member Index but I need to have the member group in the index as well. Any suggestions?
Thanks,
Karlo
Out of curiosity, did you ever find a way to do this?
I'm thinking of writing a custom GatheringNodeData event to handle it as it doesn't seem obvious to do it any other way. It's quite an overhead hitting the db each time I want to query if a member is in a particular group..
Thanks,
Mark
Did either of you guys solve this issue? I am now stuck trying to figure the same thing out!
Cheers.
Hi Josh,
In the end I went with the GatheringNodeData solution to add to an index:
I have in my mind that it was necessary to change the analyzer, but my code appears to be using the StandardAnalyzer, so maybe it wasn't an issue in the end. It had something to do with spaces between the comma's, so make sure there aren't any when putting the groups into Examine.You can then query the index as normal. I wrote a couple of helper methods to return a members groups and to return all members within groups etc.
Hope that helps!
Mark
Mark, that looks like exactly what I need. I don't suppose you could share those helper methods too? Pretty please?
Cheers!
Haha..
well, I can share what I used, though you will want to adapt them to your needs:
Don't for get to include the usings:
Hopefully you'll find these useful.
:-)
Mark
Thanks Mark! This looks great. It will definitely get me 99% of the way there. Just need to adapt it a bit and it will be perfect.
Cheers!
**First couple round of the beer of your choice are on me if you are ever passing through Slovenia!
Hey Mark! I got everything going thanks to your great help with the code sample! Wish I could mark your answer as a solution, but I didn't originate the post so can't help there.
Cheers!
Thank you Mark. Not only did it help with the exceedingly slow member queries I'm doing in a business layer, but getting the groups was a bonus. Besides adapting it for my situation, I am rebuilding the index on app start (seemed to be an issue with existing data not being indexed).
is working on a reply...