Share via

SharePoint Document library item searching using the Graph API within my SPFx solution (react framework) is not working properly.

Siva M 45 Reputation points
2023-10-03T09:24:23.9966667+00:00

Hi,

Am currently encountering a challenge while attempting to conduct searches in a SharePoint Document library using the Graph API within my SPFx solution, which is built on the React framework.

The issue we're facing is that when we try to search by either the file name or the content of a document, we're not getting any search results, even though the files are present in the document library.

We've thoroughly checked the response in both our code and the Graph Explorer tool, and in both cases, the response indicates a count of 0 hits.

Additionally, we've already ensured that all the necessary permissions have been enabled.

I would appreciate it if someone could shed light on why we are unable to perform searches using the document's name.

Furthermore, the search by file contents is somewhat inconsistent – it works at times but fails at other times.

Could someone explain the mechanism being followed in this scenario?

Thanks in advance.

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-10-24T06:36:49.3133333+00:00

    Hi @Siva M,

    I have tried to use Search to get new files, and generally wait a short time.

    You have to pay attention to whether your Search method is correct. For the special situation of the file name, you need to go to Search like this.

    If you can get the results correctly in graph explorer. Then when using SPFX, you should be able to get the correct results.User's image

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    Was this answer helpful?


  2. Anonymous
    2023-10-04T02:12:11.0366667+00:00

    Hi @Siva M,

    Can you tell me: are there some special characters (or spaces for example) in your filename?

    For example, I have a folder named "the a a"

    Please enclose the file name "the a a" in double quotes to ensure that search engines see it as an exact matched phrase rather than a separate word. This will help you find files with exact file name matches.

    Here is a test for your reference:

    User's image

    Here is test result:

    User's image

    Maybe you can try Graph explorer to test the retrieval in different situations before using it in the code.

    https://developer.microsoft.com/en-us/graph/graph-explorer


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.