Skip to content

Commit 7630604

Browse files
committed
Fix HasTemplate and IsVisible checks, CreatePublishedQuery creates correct query for visible published content
1 parent 070751d commit 7630604

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/).
66

7+
## [1.5.1] - 2022-02-29
8+
### Fixed
9+
* `CreatePublishedQuery` returns content without templates and with `umbracoNaviHide` set
10+
711
## [1.5.0] - 2022-02-28
812
### Changed
913
* Indexing UDI values as GUIDs instead of strings for easier searching
@@ -71,7 +75,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
7175
### Added
7276
* Initial release of Search Extensions for Umbraco 8.1
7377

74-
[Unreleased]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.5.0...HEAD
78+
[Unreleased]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.5.1...HEAD
79+
[1.5.1]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.5.0...release-1.5.1
7580
[1.5.0]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.4.1...release-1.5.0
7681
[1.4.1]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.4.0...release-1.4.1
7782
[1.4.0]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.3.0...release-1.4.0

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![NuGet release](https://img.shields.io/nuget/v/Our.Umbraco.Extensions.Search.svg)](https://www.nuget.org/packages/Our.Umbraco.Extensions.Search/)
66
[![Our Umbraco project page](https://img.shields.io/badge/our-umbraco-orange.svg)](https://our.umbraco.com/packages/website-utilities/search-extensions/)
77

8+
_Looking for Search Extensions for **Umbraco 9**? Check the [v9/dev](https://github.com/callumbwhyte/umbraco-search-extensions/tree/v9/dev) branch._
89

910
## Getting started
1011

@@ -75,17 +76,17 @@ The `SearchHelper` class contains logic for commonly performed actions when sear
7576
The `Get<T>` method gets all results for a query cast to a given type, including `IPublishedContent`.
7677

7778
```
78-
var query = _searcher.CreatePublishedQuery();
79+
var query = searcher.CreatePublishedQuery();
7980
80-
var results = _searchHelper.Get<T>(query, out int totalResults);
81+
var results = searchHelper.Get<T>(query, out int totalResults);
8182
```
8283

8384
The `Page<T>` method efficiently gets a given number of items *(`perPage`)* at a specific position *(`page`)* in the results for a query An optional type constraint can be added to also return paged results cast to `IPublishedContent`.
8485

8586
```
86-
var query = _searcher.CreatePublishedQuery();
87+
var query = searcher.CreatePublishedQuery();
8788
88-
var results = _searchHelper.Page<T>(query, int page, int perPage, out int totalResults);
89+
var results = searchHelper.Page<T>(query, int page, int perPage, out int totalResults);
8990
```
9091

9192
All helper methods provide the total number of results found as an `out` parameter.
@@ -116,12 +117,14 @@ Search Extensions introduces several new field types into Examine – `json`, `l
116117
Defining which fields in the index use which types is done through the `IExamineManager`:
117118

118119
```
119-
if (_examineManager.TryGetIndex("ExternalIndex", out IIndex index))
120+
if (examineManager.TryGetIndex("ExternalIndex", out IIndex index))
120121
{
121122
index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("fieldName", "fieldType"));
122123
}
123124
```
124125

126+
#### Core fields
127+
125128
Umbraco's "path" field is automatically indexed as a list and so a content item with the path `-1,1050,1100` can be queried like this:
126129

127130
```
@@ -172,7 +175,7 @@ It is possible to index a subset of a JSON object's properties by supplying a pa
172175
Register a new `ValueTypeFactory` in `IExamineManager` implementing the `json` type, and define the path as a parameter, before assigning it to a field:
173176

174177
```
175-
if (_examineManager.TryGetIndex("ExternalIndex", out IIndex index))
178+
if (examineManager.TryGetIndex("ExternalIndex", out IIndex index))
176179
{
177180
index.FieldValueTypeCollection.ValueTypeFactories.AddOrUpdate("position", new DelegateFieldValueTypeFactory(x =>
178181
{
@@ -190,7 +193,7 @@ There are advanced cases where indexing a value as multiple field types might be
190193
The `MultipleValueTypeFactory` assigns a chain of field types to a field and applies them in sequence:
191194

192195
```
193-
if (_examineManager.TryGetIndex("ExternalIndex", out IIndex index))
196+
if (examineManager.TryGetIndex("ExternalIndex", out IIndex index))
194197
{
195198
index.FieldValueTypeCollection.ValueTypeFactories.AddOrUpdate("locationData", new MultipleValueTypeFactory(x =>
196199
new IIndexFieldValueType[]
@@ -224,6 +227,6 @@ The package logo uses the [Magnifying Glass](https://thenounproject.com/term/sea
224227

225228
## License
226229

227-
Copyright &copy; 2021 [Callum Whyte](https://callumwhyte.com/), and other contributors
230+
Copyright &copy; 2022 [Callum Whyte](https://callumwhyte.com/), and other contributors
228231

229232
Licensed under the [MIT License](LICENSE.md).

src/Our.Umbraco.Extensions.Search/NestedQueryExtensions.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ public static class NestedQueryExtensions
1212
/// <remarks>
1313
/// If no <paramref name="templateId"/> is given, queries for documents without a template ID assigned
1414
/// </remarks>
15-
public static INestedBooleanOperation HasTemplate(this INestedQuery query, int templateId = 0)
15+
public static INestedBooleanOperation HasTemplate(this INestedQuery query, int? templateId = null)
1616
{
17-
return query.Field("templateID", templateId.ToString());
17+
if (templateId == null)
18+
{
19+
return query.GroupedNot(new[] { "templateID" }, "0");
20+
}
21+
22+
return query.Field("templateID", templateId?.ToString());
1823
}
1924

2025
/// <summary>

src/Our.Umbraco.Extensions.Search/QueryExtensions.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ public static class QueryExtensions
1212
/// <remarks>
1313
/// If no <paramref name="templateId"/> is given, queries for documents without a template ID assigned
1414
/// </remarks>
15-
public static IBooleanOperation HasTemplate(this IQuery query, int templateId = 0)
15+
public static IBooleanOperation HasTemplate(this IQuery query, int? templateId = null)
1616
{
17-
return query.Field("templateID", templateId.ToString());
17+
if (templateId == null)
18+
{
19+
return query.GroupedNot(new[] { "templateID" }, "0");
20+
}
21+
22+
return query.Field("templateID", templateId?.ToString());
1823
}
1924

2025
/// <summary>
@@ -33,7 +38,7 @@ public static IBooleanOperation IsPublished(this IQuery query)
3338
/// </remarks>
3439
public static IBooleanOperation IsVisible(this IQuery query)
3540
{
36-
return query.Field("umbracoNaviHide", "0");
41+
return query.GroupedNot(new[] { "umbracoNaviHide" }, "1");
3742
}
3843

3944
/// <summary>

src/Our.Umbraco.Extensions.Search/SearcherExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public static IBooleanOperation CreatePublishedQuery(this ISearcher searcher, st
1414
.CreateQuery(category, defaultOperation)
1515
.IsPublished();
1616

17-
query.AndNot(x => x.IsVisible());
17+
query.And().IsVisible();
1818

19-
query.AndNot(x => x.HasTemplate());
19+
query.And().HasTemplate();
2020

2121
return query;
2222
}

0 commit comments

Comments
 (0)