2

I am using SharePoint KeywordQuery class to query SharePoints search. When processing the record set which is returned I need the userId/user profile of the user which created the entry.

I tried to use the "Author" property, but that seems to contain only the PreferredName of the user.

Do I need to manually map a new property to do this, or which metadata property do I need to include in the result set?

EDIT: I need a property from the search Index which contains the unique identifier (user id. record id, account name ...) for the user. The Author property seems to contain the preferred name and is not unique.

I am currently mapping AuthorUserId to the search index and adding this to my query, but there should be an easier way

1 Answer 1

2

Select AccountName and use that. This will give you <domain>\<loginName>.

If necessary you can then load the SPUser from that with SPContext.Current.Web.EnsureUser(loginName)

EDIT: Here is how to use XSLT extension functions to retrieve SPUser from Author.

  • Create a public class with a public method called something like RenderUserName(string author) and create logic to fetch user name from accountname (depending on what properties you could go for UserProfile or SPUser)
  • Add a namespace to your XSLT <xsl:stylesheet> element, that matches the classname: xmlns:YourClass="urn:YourNameSpace"
  • In code call the function as any OOB function: <xsl:value-of select="YourClass:RenderUserName(Author)"/>. Note that you can also pass variables to functions using the $myVariablesyntax
5
  • I am not searching for people but usual list items. AccountName is not available for these kinds of items ... at least it is not included in the index by default. Aug 18, 2011 at 20:54
  • Author is a managed property, but requires that you fill it out (eg Welcome page). Did you actually put data into the Author page property? Aug 18, 2011 at 21:21
  • I do have data in the Authors field. But this field does not contain the account names or ids but the user name (the display name). And I don't think I can resolve the user profile from that. Aug 18, 2011 at 21:57
  • A ok, didnt read carefully :) you could use XSLT extension functions for this. See csharpfriends.com/Articles/getArticle.aspx?articleID=64 . When i get back to work ill throw in a sample Aug 19, 2011 at 5:46
  • ok sample added. let me know if you have questions Aug 21, 2011 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.