How to make IPublishedContentQuery take IsVisible in consideration ?
s
I'm doing a fairly basic search on a website, but can't make the IPublishedContentQuery handle IsVisible. The total amount of results are never affected by the IsVisible. If I do like this, IsVisible is taken in consideration in the result, but totalRecords is not:
Copy code
var result = publishedContentQuery.Search(q, p * pageSize, pageSize, out long totalRecords)
    .OrderByDescending(y => y.Score)
    .Where(x => x.Content.IsVisible());
If I do like this, IsVisible is not taken in consideration, neither in the result, or in totalRecords
Copy code
var result = publishedContentQuery.Search(q, p * pageSize, pageSize, out long totalRecords)
    .Where(x => x.Content.IsVisible())
    .OrderByDescending(y => y.Score);
How can I affect totalRecords, and what is the difference between the 2 examples ?
j
Problem is you are performing a search on the .Search method, then you get a list of results and the totalRecords count back. After that you use linq to order and filter out based on the where clause. As far as I can read your code the results should be exactly the same, in one you order then filter out, in the other you filter out then order. What you really want to do is to pass along the filter inside the search method. Looks like you can use this example: https://docs.umbraco.com/umbraco-cms/reference/querying/ipublishedcontentquery#search-iqueryexecutor-queryexecutor And then you can do something like this
Copy code
csharp
 var query = index.Searcher.CreateQuery(IndexTypes.Content);

var queryExecutor = query.ManagedQuery(searchTerm).And().Field("isVisible", "1");

var result = publishedContentQuery.Search(queryExecutor, p * pageSize, pageSize, out long totalRecords)
            .OrderByDescending(y => y.Score);
s
Thanks @Jemayn that worked perfect 👍