Skip to content

Commit

Permalink
Release 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
callumbwhyte committed May 29, 2022
1 parent 66eb858 commit 72325b7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 21 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

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

## [2.0.0] - 2022-05-30
### Added
* Initial release of Search Extensions for Umbraco 9+

## [1.5.1] - 2022-02-29
### Fixed
* `CreatePublishedQuery` returns content without templates and with `umbracoNaviHide` set
Expand Down Expand Up @@ -75,7 +79,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/) and this
### Added
* Initial release of Search Extensions for Umbraco 8.1

[Unreleased]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.5.1...HEAD
[Unreleased]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-2.0.0...HEAD
[2.0.0]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.5.1...release-2.0.0
[1.5.1]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.5.0...release-1.5.1
[1.5.0]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.4.1...release-1.5.0
[1.4.1]: https://github.com/callumbwhyte/umbraco-search-extensions/compare/release-1.4.0...release-1.4.1
Expand Down
74 changes: 54 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
[![NuGet release](https://img.shields.io/nuget/v/Our.Umbraco.Extensions.Search.svg)](https://www.nuget.org/packages/Our.Umbraco.Extensions.Search/)
[![Our Umbraco project page](https://img.shields.io/badge/our-umbraco-orange.svg)](https://our.umbraco.com/packages/website-utilities/search-extensions/)

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

## Getting started

This package is supported on Umbraco 8.1+.
This package is supported on Umbraco 9+.

### Installation

Expand Down Expand Up @@ -114,15 +114,27 @@ foreach (var result in query.Execute())

Search Extensions introduces several new field types into Examine – `json`, `list`, `UDI` and `picker` – to ensure Umbraco data is correctly indexed and queryable.

Defining which fields in the index use which types is done through the `IExamineManager`:
Examine allows controlling an index's fields, field types, and [more](https://shazwazza.github.io/Examine/configuration#iconfigurenamedoptions), via [.NET's Named Options pattern](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options):

```
if (examineManager.TryGetIndex("ExternalIndex", out IIndex index))
public class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("fieldName", "fieldType"));
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
if (name == "ExternalIndex")
{
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("fieldName", "fieldType"));
}
}
}
```

The options class must be registered in the [Dependency Injection](https://our.umbraco.com/documentation/reference/using-ioc/) container to apply:

```
builder.Services.ConfigureOptions<ConfigureIndexOptions>();
```

#### Core fields

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:
Expand Down Expand Up @@ -172,17 +184,26 @@ Each property will be created as a field in the index, including any nested prop

It is possible to index a subset of a JSON object's properties by supplying a path in (https://www.newtonsoft.com/json/help/html/QueryJsonSelectTokenJsonPath.htm)[JSON Path format].

Register a new `ValueTypeFactory` in `IExamineManager` implementing the `json` type, and define the path as a parameter, before assigning it to a field:
Register a new `ValueTypeFactory` in the index implementing the `json` type, and define the path as a parameter, before assigning it to a field:

```
if (examineManager.TryGetIndex("ExternalIndex", out IIndex index))
public class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
index.FieldValueTypeCollection.ValueTypeFactories.AddOrUpdate("position", new DelegateFieldValueTypeFactory(x =>
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
new JsonValueType(x, "$[*].position")
}));
index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("locations", "position"));
if (name == "ExternalIndex")
{
options.IndexValueTypesFactory = new Dictionary<string, IFieldValueTypeFactory>(options.IndexValueTypesFactory)
{
["position"] = new DelegateFieldValueTypeFactory(fieldName =>
{
return new JsonValueType(fieldName, "$[*].position");
};
};
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("locations", "position"));
}
}
}
```

Expand All @@ -193,17 +214,30 @@ There are advanced cases where indexing a value as multiple field types might be
The `MultipleValueTypeFactory` assigns a chain of field types to a field and applies them in sequence:

```
if (examineManager.TryGetIndex("ExternalIndex", out IIndex index))
public class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
index.FieldValueTypeCollection.ValueTypeFactories.AddOrUpdate("locationData", new MultipleValueTypeFactory(x =>
new IIndexFieldValueType[]
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
if (name == "ExternalIndex")
{
new JsonValueType(x, "$[*].city"),
new JsonValueType("position", "$[*].position")
options.IndexValueTypesFactory = new Dictionary<string, IFieldValueTypeFactory>(options.IndexValueTypesFactory)
{
["locationData"] = new DelegateFieldValueTypeFactory(fieldName =>
{
return new MultipleValueTypeFactory(
fieldName,
new IIndexFieldValueType[]
{
new JsonValueType(x, "$[*].city"),
new JsonValueType("position", "$[*].position")
}
);
};
};
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("locations", "locationData"));
}
));
index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("locations", "locationData"));
}
}
```

Expand Down

0 comments on commit 72325b7

Please sign in to comment.