🔍 Code Extractor

class SearchQuery

Maturity: 36

Represents a search query object that encapsulates search terms and optional query templates for SharePoint/Office365 search operations.

File:
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/search/query.py
Lines:
4 - 14
Complexity:
simple

Purpose

This class is used to construct and represent search queries in the Office365 API context. It inherits from ClientValue, making it serializable for transmission to SharePoint/Office365 services. The class allows specifying both raw search query strings and query templates that can include KQL (Keyword Query Language) syntax and query variables for more sophisticated search operations.

Source Code

class SearchQuery(ClientValue):
    def __init__(self, query_string=None, query_template=None):
        """
        Represents a search query that contains search terms and optional filters.

        :param str query_string: The search query containing the search terms.
        :param str query_template: Provides a way to decorate the query string. Supports both KQL and query variables.
        """
        super(SearchQuery, self).__init__()
        self.queryString = query_string
        self.queryTemplate = query_template

Parameters

Name Type Default Kind
bases ClientValue -

Parameter Details

query_string: The search query containing the actual search terms to be executed. This is the main search text that will be used to find matching items. Can be None if only using a query template. Expected to be a string value.

query_template: An optional template that decorates or enhances the query string. Supports both KQL (Keyword Query Language) syntax and query variables for dynamic query construction. This allows for more complex search scenarios with filters, refiners, and parameterized queries. Can be None if only a simple query string is needed.

Return Value

Instantiation returns a SearchQuery object that inherits from ClientValue. The object contains two main attributes (queryString and queryTemplate) that can be serialized and sent to Office365 services for search operations. No methods return values as this is primarily a data container class.

Class Interface

Methods

__init__(query_string=None, query_template=None)

Purpose: Initializes a new SearchQuery instance with optional search terms and query template

Parameters:

  • query_string: The search query containing the search terms (optional, defaults to None)
  • query_template: Template for decorating the query with KQL and variables (optional, defaults to None)

Returns: None (constructor)

Attributes

Name Type Description Scope
queryString str or None Stores the search query string containing the actual search terms to be executed instance
queryTemplate str or None Stores the query template that can include KQL syntax and query variables for decorating the search query instance

Dependencies

  • office365

Required Imports

from office365.runtime.client_value import ClientValue

Usage Example

from office365.runtime.client_value import ClientValue
from office365.sharepoint.search.query.search_query import SearchQuery

# Simple search query with just search terms
simple_query = SearchQuery(query_string="project documents")

# Search query with KQL template for filtering
filtered_query = SearchQuery(
    query_string="budget",
    query_template="{searchTerms} ContentType:Document"
)

# Search query with query variables
advanced_query = SearchQuery(
    query_string="sales report",
    query_template="{searchTerms} Path:{Site.URL}/Documents"
)

# Access the query properties
print(simple_query.queryString)  # Output: project documents
print(filtered_query.queryTemplate)  # Output: {searchTerms} ContentType:Document

Best Practices

  • Always provide at least one of query_string or query_template when instantiating the class
  • Use query_template for complex searches that require KQL syntax or filtering
  • The {searchTerms} placeholder in query_template will be replaced with the query_string value
  • This class is typically used as part of a larger search request object and not executed directly
  • Ensure proper KQL syntax when using query_template to avoid search errors
  • The class inherits from ClientValue, so it will be automatically serialized when sent to Office365 services
  • Both parameters are optional but at least one should be provided for meaningful search operations

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class SearchResponse 74.8% similar

    A data class that encapsulates search query results and the search terms used to generate those results, inheriting from ClientValue for Office 365 API integration.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/search/response.py
  • class ExpandedQueryParameters 74.7% similar

    A class representing expanded query parameters for Microsoft Office Server Search REST API, inheriting from ClientValue to provide serialization capabilities.

    From: /tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/search/query/expanded_parameters.py
  • class QueryContext 74.5% 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 QueryCondition 73.9% similar

    QueryCondition is a data class that represents conditions for promoted search results in Microsoft Office Server Search REST API.

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

    A client value class representing a query suggestion query for SharePoint search operations.

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