0

How can i exclude "Forms/DispForm.aspx?" from search results using the search api for SharePoint Online?

I tried the following querytext:

$querytext= path: *: // * /DispForm.aspx*

But it is not working and is throwing an error:"Search has encountered a problem that prevents results from being returned"

Please suggest a solution.


EDIT

I need to get Documents(docx,pdf,xslx,ppt..) and pages only from the whole tenant. But i am also getting Forms\DispForm.aspx?ID=1 (when i checked this url,this is a js file). So how can i exclude js files? Below is my script. Kindly help me.

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($webApp) 
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName,$securePassword)
$Context.Credentials = $Creds 
$keywordQuery = New-Object Microsoft.SharePoint.Client.Search.Query.KeywordQuery($Context) 
$queryText="createdby:xxxx contentclass:STS_ListItem_850 contentclass:STS_ListItem_DocumentLibrary -fileextension:html -ContentTypeId:0x0120*" 
$keywordQuery.QueryText = $queryText 
$keywordQuery.SelectProperties.Add("Created") 
$keywordQuery.SelectProperties.Add("LastModifiedTime") 
$keywordQuery.SelectProperties.Add("CreatedBy") 
$keywordQuery.SelectProperties.Add("ModifiedBy") 
$keywordQuery.SelectProperties.Add("ListItemID") 
$keywordQuery.SelectProperties.Add("ListID") 
$keywordQuery.SelectProperties.Add("SPWebUrl") 
$searchExecutor = New-Object Microsoft.SharePoint.Client.Search.Query.SearchExecutor($Context)
$results = $searchExecutor.ExecuteQuery($keywordQuery)
$Context.ExecuteQuery()
Write-Host $results.Value[0].ResultRows.Count

$exportlocation = "CSV path to export"

0

After reading you script the you provided I think you are on the right track. How about you just edit your search query to search for the type of documents and pages you are looking for? Sort of like this:

contentclass:STS_ListItem_850 OR (IsDocument:1 FileType:doc* FileType:pdf* FileType:xls* FileType:ppt*)

An other alternative would be to write the query like this where you look for just pages of contentclass STS_ListItem_850 and contentclass STS_ListItem_DocumentLibrary.

contentclass:STS_ListItem_850 OR (IsDocument:1 contentclass:STS_ListItem_DocumentLibrary)

So edit your script to look like this.

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($webApp) 
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName,$securePassword)
$Context.Credentials = $Creds 
$keywordQuery = New-Object Microsoft.SharePoint.Client.Search.Query.KeywordQuery($Context) 
$queryText="contentclass:STS_ListItem_850 OR (IsDocument:1 FileType:doc* FileType:pdf* FileType:xls* FileType:ppt*)" 
$keywordQuery.QueryText = $queryText 
$keywordQuery.SelectProperties.Add("Created") 
$keywordQuery.SelectProperties.Add("LastModifiedTime") 
$keywordQuery.SelectProperties.Add("CreatedBy") 
$keywordQuery.SelectProperties.Add("ModifiedBy") 
$keywordQuery.SelectProperties.Add("ListItemID") 
$keywordQuery.SelectProperties.Add("ListID") 
$keywordQuery.SelectProperties.Add("SPWebUrl") 
$searchExecutor = New-Object Microsoft.SharePoint.Client.Search.Query.SearchExecutor($Context)
$results = $searchExecutor.ExecuteQuery($keywordQuery)
$Context.ExecuteQuery()
Write-Host $results.Value[0].ResultRows.Count

$exportlocation = "CSV path to export"

After running this script I think it will return your expected results. Also please read Mikael Svensons article about limiting search results to only documents. Limit search results to “Documents”

You can read more about searchqueries over at Microsoft docs. Keyword Query Language (KQL) syntax reference

  • this did'nt work :-( .Any other way? – Swetha Paritala Aug 6 '18 at 12:13
  • If you include your original script in you post maybe it could help tracking the problem down. – Johan Brännmar Aug 6 '18 at 12:38
  • @SwethaParitala did this solve you issue? – Johan Brännmar Aug 7 '18 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.