Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have around 4000 members on my site. I need to be able to search against two properties 'firstname' and 'surname'. I have tried standard linq:
foreach (var m in umbraco.cms.businesslogic.member.Member.GetAllAsList().Where(m => m.getProperty("firstName").Value.ToString().ToLower().Contains(s) || m.getProperty("lastName").Value.ToString().ToLower().Contains(s)).Take(4)) { if (m.getProperty("firstName") != null) { sb.Append("<child>"); sb.Append("<id>" + m.Id + "</id>"); sb.Append("<first>" + m.getProperty("firstName").Value + "</first>"); sb.Append("<last>" + m.getProperty("lastName").Value + "</last>"); sb.Append("<picture>"); if (m.getProperty("profilePicture") != null) { if (m.getProperty("profilePicture").Value != "") { sb.Append(m.getProperty("profilePicture").Value); } } sb.Append("</picture>"); sb.Append("</child>"); } }
Even though i just want 4 results this is very slow. Does anyone know a quicker way to do this?
Hi Phil,
Yes, there's indeed a faster way of doing that :-) Check out my reply to this thread: http://our.umbraco.org/forum/developers/api-questions/33736-How-to-populate-all-Members-with-Profile-properties
In the XPath string, you can specify the conditions you have in your Where() clause.
This loads the members from the XML cache instead of the database. The Member.GetAllAsList() gets slow at around 100 - 200 members.
Let me know if this works :-)
All the best,
Bo
Hmm, doesnt seem to much quicker to be honest
var members = uQuery.GetMembersByXPath("//*");
foreach(var m in members.Where(m => m.getProperty("firstName").Value.ToString().ToLower().Contains(s) || m.getProperty("lastName").Value.ToString().ToLower().Contains(s)).Take(4))
{
if (m.getProperty("firstName") != null)
sb.Append("<child>");
sb.Append("<id>" + m.Id + "</id>");
sb.Append("<first>" + m.getProperty("firstName").Value + "</first>");
sb.Append("<last>" + m.getProperty("lastName").Value + "</last>");
sb.Append("<picture>");
if (m.getProperty("profilePicture") != null)
if (m.getProperty("profilePicture").Value != "")
sb.Append(m.getProperty("profilePicture").Value);
}
sb.Append("</picture>");
sb.Append("</child>");
sorry! mis read works great!
var members = uQuery.GetMembersByXPath("//* [contains(firstName,'" + s + "') or contains(lastName,'" + s + "')]");
If you use the power of XPath to do the filtering it'll be quicker :) (atm you're getting all members and then checking each via the API)
As Hendy points out, the filtering should be done in the XPath itself, but I see you've already got that in place ;-)
Remember to mark this post as 'solved' for future reference if it solved your problem :-)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Fastest way to query members
I have around 4000 members on my site. I need to be able to search against two properties 'firstname' and 'surname'. I have tried standard linq:
Even though i just want 4 results this is very slow. Does anyone know a quicker way to do this?
Hi Phil,
Yes, there's indeed a faster way of doing that :-) Check out my reply to this thread: http://our.umbraco.org/forum/developers/api-questions/33736-How-to-populate-all-Members-with-Profile-properties
In the XPath string, you can specify the conditions you have in your Where() clause.
This loads the members from the XML cache instead of the database. The Member.GetAllAsList() gets slow at around 100 - 200 members.
Let me know if this works :-)
All the best,
Bo
Hmm, doesnt seem to much quicker to be honest
var members = uQuery.GetMembersByXPath("//*");
foreach(var m in members.Where(m => m.getProperty("firstName").Value.ToString().ToLower().Contains(s) || m.getProperty("lastName").Value.ToString().ToLower().Contains(s)).Take(4))
{
if (m.getProperty("firstName") != null)
{
sb.Append("<child>");
sb.Append("<id>" + m.Id + "</id>");
sb.Append("<first>" + m.getProperty("firstName").Value + "</first>");
sb.Append("<last>" + m.getProperty("lastName").Value + "</last>");
sb.Append("<picture>");
if (m.getProperty("profilePicture") != null)
{
if (m.getProperty("profilePicture").Value != "")
{
sb.Append(m.getProperty("profilePicture").Value);
}
}
sb.Append("</picture>");
sb.Append("</child>");
}
}
sorry! mis read works great!
var members = uQuery.GetMembersByXPath("//* [contains(firstName,'" + s + "') or contains(lastName,'" + s + "')]");
Hi Phil,
If you use the power of XPath to do the filtering it'll be quicker :) (atm you're getting all members and then checking each via the API)
Hi Phil,
As Hendy points out, the filtering should be done in the XPath itself, but I see you've already got that in place ;-)
Remember to mark this post as 'solved' for future reference if it solved your problem :-)
All the best,
Bo
is working on a reply...