Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharePoint Search Query Returning Empty Table #845

Closed
J-Goodall opened this issue Apr 11, 2024 · 1 comment
Closed

SharePoint Search Query Returning Empty Table #845

J-Goodall opened this issue Apr 11, 2024 · 1 comment
Labels

Comments

@J-Goodall
Copy link

Hello,

I'm trying to run a search query to get ViewsLifeTime & ViewsLifeTimeUniqueUsers for pages in our SharePoint tenant, however the table being returned for each query is empty.

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_app(client_id, client_secret)
ctx = ClientContext(url, ctx_auth)

results = ctx.search.query(query_text="path:{url of page}").execute_query()

If I follow down results.value.PrimaryQueryResult.RelevantResults.Table there are no rows / key/value pairs, and if I attempt using the get_property() func to isolate a property, it does not find it.

If the query is executed in a browser (e.g. https://{site}.sharepoint.com/_api/search/query?querytext='path:{url of page}') this returns the required data in the SimpleDataTable table

Looking at other issues I also tried:

search = SearchService(ctx)
request = SearchRequest(query_text="path:{url of page}")
result = search.post_query(request).execute_query()

However this returns an error of ('-1, Microsoft.Data.OData.ODataException', "Incompatible type kinds were found. The type 'Microsoft.Office.Server.Search.REST.SearchRequest' was found to be of kind 'Complex' instead of the expected kind 'Primitive'.", '400 Client Error: Bad Request for url: {url of page}).

Am I missing something?

Cheers,

James

@vgrem vgrem added the question label May 9, 2024
@vgrem
Copy link
Owner

vgrem commented May 9, 2024

Greetings,

since SearchService.post_query method signature has changed since 2.4.0 version:

def post_query(
        self,
        query_text,
        select_properties=None,
        trim_duplicates=None,
        row_limit=None,
        **kwargs
    )

the search request is getting constructed incorrectly and the provided error occurs, it could be adjusted like this one:

result = search.post_query(query_text="path:{url of page}").execute_query()

@vgrem vgrem closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants