0
votes

I am using the Document Library of SharePoint online for document storage. I have added certain custom columns to the SharePoint Document Library to store additional metadata for a document.

SharePoint Columns Screenshot

Now, I want to do fulltext search in SharePoint through REST API's. We are able to do full text search on the custom column data. However, one more requirement is to filter the results based on certain columns like 'ASSET TYPE = image'.

How can i achieve this functionality? my current query is as follows:

_api/search/query?querytext='(cloud computing)'&querytemplate='{searchTerms} path:"https://DOMAIN_NAME.sharepoint.com/sites/LOREM_IPSUM/Shared%20Documents" ContentTypeId:0x0* IsDocument:true'&SummaryLength=100&RowLimit=500&culture=1033&BypassResultTypes=true&EnableQueryRules=false&ProcessBestBets=false&ProcessPersonalFavorites=false&properties='EnableDynamicGroups:true'
1

1 Answers

0
votes

Search API uses "Managed Properties" for custom columns, when you create a custom property it will create automatically a Managed Property with a name similar to

INTERNALNAMEPROPERTYtype

For instance, if your "ASSET TYPE" column has as internal name "ASSET_TYPE" and it is a column of type "one line text" your Managed Property will be:

ASSET_TYPEOWSTEXT

You can also search for your managed property name by going to:

Site Configuration >> Manage Search Schema >> Managed Properties

You can learn a little bit more about managed properties here: https://docs.microsoft.com/en-us/sharepoint/technical-reference/automatically-created-managed-properties-in-sharepoint

Now, considering that if your managed property has the name of ASSET_TYPEOWSTEXT you can use it in your search query just like this:

ASSET_TYPEOWSTEXT=image

So your search query would look like this:

_api/search/query?querytext='(cloud computing)'&querytemplate='{searchTerms} path:"https://DOMAIN_NAME.sharepoint.com/sites/LOREM_IPSUM/Shared%20Documents" ContentTypeId:0x0* IsDocument:true ASSET_TYPEOWSTEXT=image'&SummaryLength=100&RowLimit=500&culture=1033&BypassResultTypes=true&EnableQueryRules=false&ProcessBestBets=false&ProcessPersonalFavorites=false&properties='EnableDynamicGroups:true'

I would recommend you to use a content search webpart to test your query in a easy way.