2

The rest query is as follows, I want to get most viewed pages. I have used ViewsLifeTime property. This query returns some pages (unwanted) which their ViewsLifeTime is null.

https://domain.com/_api/search/query?querytext='ContentTypeId:0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39*'&sortlist='ViewsLifeTime:descending'&filter=ViewsLifeTime gt '0'

I have tested with eq, ne as well.

The ViewsLifeTime of unwanted pages is like:

<d:element m:type="SP.KeyValue">
  <d:Key>ViewsLifeTime</d:Key>
  <d:Value m:null="true"/>
  <d:ValueType>Null</d:ValueType>
</d:element>

But I want to have those pages is viewed (ViewsLifeTime is not null) like:

 <d:element m:type="SP.KeyValue">
   <d:Key>ViewsLifeTime</d:Key>
   <d:Value>14</d:Value>
   <d:ValueType>Edm.Int64</d:ValueType>
 </d:element>

The other problem with this query is it returns all pages within the farm. I want to get pages only from current Site collection.

How do I filter out those pages that have not been viewed (ViewsLifeTime is null) and restrict the result to current Site Collection?

1

I don't think the $filter parameter works on the search API. You need to specify the filters in the querytext parameter.

querytext='ContentTypeId:0x010100C568*+AND+ViewsLifeTime>0'

As for the specific to site collection. There is a WebID property for the querytext, not sure about Site Collection.

What I do is test my querytext in the standard SharePoint search box to get my query string value for my api calls!

  • Try level=sitecol for site collection only – SteveCl Dec 3 '13 at 13:58
0

First enable Search and Query property for "ViewsLifeTime" managed property in search service and perform full crawl.

Use Search Query API for not returning the items for which "ViewsLifeTime" count is null

https://domain.com/_api/search/query?querytext='NOT(viewslifetime:0)'

Reference Links :- Filter for Empty Values in Search

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.