Sharepoint Online - CSOM search KeyWordQuery document not appear

Mauricio Poggio Veiro 301 Reputation points
2020-12-09T21:46:51.26+00:00

Hello,

I'm doing a search in Sharepoint with CSOM, some documents are missing, otherwise if a do the same search directly over Sharepoint this documents appear....

I already check Query Source, crawled properties, syntax, etc... need help.

=======================

			KeywordQuery keywordQuery = new KeywordQuery(lContext)  
			{  
				QueryText = lsQuery,  
				SourceId = new Guid("21a5d2a0-e739-48a7-948d-deeb5f705f48"),  
				StartRow = liStartAt, RowLimit = liRowLimit  
			};  
            QueryPropertyValue lValue = new QueryPropertyValue();  
            lValue.StrVal = "Documentos";  
            keywordQuery.Properties.SetQueryPropertyValue("SourceName", lValue);  
            lValue.StrVal = "SPSiteSubscription"; //tenant level  
            keywordQuery.Properties.SetQueryPropertyValue("SourceLevel", lValue);  

=======================

46722-image.png

Using the same syntax that in the print screen, KeyWordSearch returns nothing....

Thanks a lot,

Mauricio.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,892 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,408 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,016 Reputation points
    2020-12-11T01:53:07.037+00:00

    Hi @Mauricio Poggio Veiro ,

    This could be some rows / items are incorrectly treated as duplicates by search.

    Try to add keywordQuery.TrimDuplicates = false; in your code, check if it works for you.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.

    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points
    2020-12-10T06:03:04.183+00:00

    Hi @Mauricio Poggio Veiro ,

    Please try to use the below CSOM code, check if it work for you:

    string username = "michael";  
    string pwd = "password";  
    string siteURL = "https://tenant.sharepoint.com/yoursite";       
    ClientContext context = new ClientContext(siteURL);  
    SecureString pass = new SecureString();  
    foreach (char c in pwd.ToCharArray()) pass.AppendChar(c);  
    context.Credentials = new SharePointOnlineCredentials(username, pass);  
    KeywordQuery query= new KeywordQuery(ctx);  
    query.QueryText = "IdSeguimientolni=604068";  
    SearchExecutor search = new SearchExecutor(context);  
    ClientResult<ResultTableCollection> results = search.ExecuteQuery(query);  
    context.ExecuteQuery();  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.

    0 comments No comments

  2. Mauricio Poggio Veiro 301 Reputation points
    2020-12-10T13:41:59.573+00:00

    Hi Michael,

    I already try security issues, but I tried your example and throw this error:

    "'=' is an unexpected token. The expected token is ';'. Line 1, position 434."

    thanks a lot!
    Mauricio.

    0 comments No comments

  3. Mauricio Poggio Veiro 301 Reputation points
    2020-12-10T21:07:58.16+00:00

    Forget my last post.

    Now I could get the document, this is my code:

            KeywordQuery keywordQuery = new KeywordQuery(lContext)
            {
            QueryText = lsQuery,
            SourceId = new Guid("BLABLABLABLA"),
            // HOUSTON!! StartRow = liStartAt, 
            RowLimit = liRowLimit
            };
            QueryPropertyValue lValue = new QueryPropertyValue();
            lValue.StrVal = "Documentos";
            keywordQuery.Properties.SetQueryPropertyValue("SourceName", lValue);
            lValue.StrVal = "SPSiteSubscription"; //tenant level
            keywordQuery.Properties.SetQueryPropertyValue("SourceLevel", lValue);
    
         
    

    If I comment "StartRow" then I get the expected result....

    But now I have another strange behavior:

    If I filter with "IdSeguimientoIni=604126" then I get the documento, but if I filter with "isdocument:1 AND (FileName<>index.aspx) AND IdCliente=100000 TemaId=14964 " then this document is missing (I get nine documents, 7 are missing).
    I did the same search directly in sharepoint site search box and I get the fifthing documents, so I may suppose that is not a crawler problem......

    thanks!
    Mauricio.

    0 comments No comments

  4. Mauricio Poggio Veiro 301 Reputation points
    2020-12-11T13:15:28.963+00:00

    Excelent Michael!! thanks!

    Now I should find out why I get 7 documents more than in my Sharepoint onpremises :)

    cheers!
    Mauricio.

    0 comments No comments