🔍 Code Extractor

class QueryPersonalizationData

Maturity: 45

A SharePoint entity class that encapsulates user identification data for personalizing search queries in SharePoint Online/Office 365.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/search/query/personalization_data.py
Lines:
5 - 16
Complexity:
simple

Purpose

QueryPersonalizationData is used to associate a specific user identifier with search queries in SharePoint, enabling personalized search results based on the user's context. It extends the Entity base class and creates a service operation path that includes the user's GUID for SharePoint search query personalization. This class is typically used when executing search queries that need to be tailored to individual users based on their permissions, preferences, or historical interactions.

Source Code

class QueryPersonalizationData(Entity):
    """Contains a unique identifier for the current user who is executing a search query"""

    def __init__(self, context, user_id):
        """
        :param str user_id:
        """
        static_path = ServiceOperationPath(
            "Microsoft.SharePoint.Client.Search.Query.QueryPersonalizationData",
            {"guidUserIdString": user_id},
        )
        super(QueryPersonalizationData, self).__init__(context, static_path)

Parameters

Name Type Default Kind
bases Entity -

Parameter Details

context: The client context object that manages the connection to SharePoint. This is required for all SharePoint entity operations and provides the runtime environment for executing requests against the SharePoint service.

user_id: A string representing the unique identifier (typically a GUID) for the user whose search queries should be personalized. This identifier is used by SharePoint to apply user-specific personalization to search results.

Return Value

Instantiation returns a QueryPersonalizationData object that inherits from Entity. This object represents a SharePoint entity with a service operation path configured for query personalization. The object can be used in SharePoint search query operations to provide user context.

Class Interface

Methods

__init__(self, context, user_id: str)

Purpose: Initializes a new QueryPersonalizationData instance with the specified context and user identifier

Parameters:

  • context: The SharePoint client context object for managing service connections
  • user_id: String representation of the user's unique identifier (GUID) for query personalization

Returns: None (constructor)

Attributes

Name Type Description Scope
context ClientContext Inherited from Entity base class. Stores the SharePoint client context used for service operations instance
resource_path ServiceOperationPath Inherited from Entity base class. Contains the service operation path with the user GUID parameter for personalization instance

Dependencies

  • office365

Required Imports

from office365.runtime.paths.service_operation import ServiceOperationPath
from office365.sharepoint.entity import Entity
from office365.sharepoint.client_context import ClientContext

Usage Example

from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.search.query.personalization_data import QueryPersonalizationData
from office365.runtime.auth.user_credential import UserCredential

# Establish SharePoint connection
site_url = 'https://contoso.sharepoint.com/sites/team'
ctx = ClientContext(site_url).with_credentials(UserCredential('user@contoso.com', 'password'))

# Create personalization data with user GUID
user_guid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'
personalization_data = QueryPersonalizationData(ctx, user_guid)

# Use with search query operations
# The personalization_data object can now be passed to search query methods
# to ensure results are personalized for the specified user

Best Practices

  • Always ensure the user_id parameter is a valid GUID string that corresponds to an actual user in the SharePoint tenant
  • The context parameter must be a properly authenticated ClientContext object before instantiating this class
  • This class is typically used as part of a larger search query operation and should not be instantiated in isolation without a search context
  • The QueryPersonalizationData object inherits from Entity, so it follows the standard SharePoint entity lifecycle including lazy loading and deferred execution patterns
  • Do not reuse the same QueryPersonalizationData instance across different user contexts; create a new instance for each user
  • Ensure proper error handling when the user_id does not exist or the user lacks permissions for the search operation

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class QueryProperty 63.4% similar

    A class representing a name-value pair for storing additional or custom properties for SharePoint search queries.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/search/query/property.py
  • class PeoplePickerQuerySettings 61.7% similar

    A data class representing additional settings for SharePoint principal queries, specifically for people picker operations.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/ui/applicationpages/peoplepicker/query_settings.py
  • class PersonalCache 61.0% similar

    A SharePoint user profile personal cache entity that manages per-user key/value pairs organized by folders for optimizing client load performance.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/userprofiles/personal_cache.py
  • class QueryContext 61.0% similar

    QueryContext is a data container class that encapsulates query context properties for Microsoft Office Server Search REST API operations.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/search/query/context.py
  • class QuerySuggestionResults 59.3% similar

    A container class for SharePoint search query suggestions, including people names, personal results, popular results, and query suggestions.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/search/query/suggestion_results.py
← Back to Browse