Creates custom YesSql indexes in Orchard Core, covering MapIndex models, IndexProvider patterns, index declarations, migrations, and querying with ISession.QueryIndex().
Ships in orchardcore. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an Orchard Core expert. Generate code for custom YesSql indexes that follows Orchard Core conventions and CrestApps project structure.
context.For<TIndex>(), and only when it is true: .ExclusiveToDocumentType() when only documents of the provider's type (for example ContentItem) write records to the index, and .SingleRecordPerDocument() when the map returns at most one record per document. A content item index usually is exclusive; it is single-record only when it never returns several rows for one content item version (not when it returns one row per tag, term or picked item). See Declaring What an Index Holds.IQuery<T>.NoDuplicates() is obsolete in YesSql 6.3; use SkipDeduplication()."ContentItemId" and "Published" when creating or altering YesSql index tables; do not use nameof(...) inside CreateMapIndexTableAsync() or AlterIndexTableAsync().MapIndex tables already include a DocumentId column automatically. Never add or alter DocumentId manually in CreateMapIndexTableAsync() or AlterIndexTableAsync().public long DocumentId { get; set; } to the index model and let YesSql populate it automatically.ContentItemIndex indexes, which led with DocumentId, with indexes led by the filtered columns (ContentItemId, ContentType, Owner, ContentItemVersionId) followed by DocumentId, Published and Latest: a filter can only seek on an index that starts with its column. Joins on DocumentId already seek on the IDX_FK_* index YesSql creates.ContentItemId and ItemId are typically 26 characters long; define indexed string id columns with .WithLength(26).TextHelper.Truncate(value, maxLength) (namespace OrchardCore, package OrchardCore.Abstractions), as the built-in field and content indexes do since 4.0: it keeps whole Unicode text elements (emoji, surrogate pairs, combining marks) instead of splitting them like value[..maxLength].MapIndex tables with .Column<YourEnum>("Status").&& / ||, ordering, paging, and simple projections.?:), if-style branching inside expression lambdas, or other unsupported runtime logic in ISession.Query(...) / QueryIndex(...) predicates.src/Core/{{FeatureName}}.Core/
Indexes/
{{LookupName}}Index.cs
src/Modules/{{FeatureName}}/
Migrations/
{{FeatureName}}Migrations.cs
Startup.cs
using OrchardCore.ContentManagement;
using YesSql.Indexes;
namespace CrestApps.Sports.Core.Indexes;
public sealed class ClubTeamsIndex : MapIndex
{
public string ClubContentItemId { get; set; }
public string TeamContentItemId { get; set; }
public bool Published { get; set; }
}
public sealed class ClubTeamsIndexProvider : IndexProvider<ContentItem>
{
public override void Describe(DescribeContext<ContentItem> context)
{
// Only content items write records, and a team version maps at most one record.
context.For<ClubTeamsIndex>()
.ExclusiveToDocumentType()
.SingleRecordPerDocument()
.Map(contentItem =>
{
if (contentItem.ContentType != ContentTypes.Team)
{
return null;
}
var clubContentItemId = contentItem.GetContentPickerValue("TeamPart", "Club");
if (string.IsNullOrWhiteSpace(clubContentItemId))
{
return null;
}
return new ClubTeamsIndex
{
ClubContentItemId = clubContentItemId,
TeamContentItemId = contentItem.ContentItemId,
Published = contentItem.Published,
};
});
}
}
using OrchardCore.ContentManagement;
using YesSql.Indexes;
public sealed class DrillsIndex : MapIndex
{
public string DrillContentItemId { get; set; }
public string SkillContentItemId { get; set; }
public bool Published { get; set; }
}
public sealed class DrillsIndexProvider : IndexProvider<ContentItem>
{
public override void Describe(DescribeContext<ContentItem> context)
{
// Exclusive to content items, but not single-record: one row per selected skill.
context.For<DrillsIndex>()
.ExclusiveToDocumentType()
.Map(contentItem =>
{
if (contentItem.ContentType != ContentTypes.Drill)
{
return null;
}
var skillIds = contentItem
.GetContentPickerValues("DrillPart", "Skills")
.Where(id => !string.IsNullOrWhiteSpace(id))
.Distinct(StringComparer.Ordinal)
.ToArray();
if (skillIds.Length == 0)
{
return null;
}
return skillIds.Select(skillId => new DrillsIndex
{
DrillContentItemId = contentItem.ContentItemId,
SkillContentItemId = skillId,
Published = contentItem.Published,
});
});
}
}
A query joining a map index groups its matches by document (to return each document once) and counts distinct documents, so a page reads every match before it can be sorted. Declarations let YesSql skip that work:
| Declaration | Meaning | Effect |
|---|---|---|
.ExclusiveToDocumentType() | Only documents of the provider's type have records in the index. | A count reads the index tables without joining the Document table. |
.SingleRecordPerDocument() | The map returns at most one record per document; saving throws if it returns more. | A query joining only single-record indexes isn't grouped, so a page stops as soon as it is full when a database index serves its order, and its count uses count(*). |
context.For<ProductIndex>()
.ExclusiveToDocumentType()
.SingleRecordPerDocument()
.When(contentItem => contentItem.Has<ProductPart>())
.Map(contentItem => new ProductIndex
{
ContentItemId = contentItem.ContentItemId,
Price = contentItem.As<ProductPart>().Price,
});
SingleRecordPerDocument(), or when several providers produce the same index for one document type. The Document table is still joined when a provider of another document type produces the index, or a filter is raw SQL.query.NoIndexOptimizations() runs a query as if its indexes declared nothing. Use it when the declarations make a query slower, for example a text search where the database walks the index of the sort order looking for rare matches (the content items admin list search and the content picker searches do this).query.SkipDeduplication() (replaces the obsolete NoDuplicates()) skips the grouping for a query that joins a multi-record index but matches only one of its records per document. Nothing verifies it, and the count then uses count(*), so a document matched several times is counted several times.DocumentId can make an exclusive count slower: lead SQL indexes with the filtered columns and end them with DocumentId.Built-in indexes declaring both: ContentItemIndex, ContainedPartIndex, LocalizedContentItemIndex, UserIndex, WorkflowIndex, DataPipelineRunIndex, AuditTrailEventIndex and NotificationIndex. A query that joins only these (for example ContentItemIndex alone) is no longer grouped by document; joining any other index, such as TaxonomyIndex or your own undeclared index, brings the grouping back.
using CrestApps.Sports.Calendar.Indexes;
using OrchardCore.Data.Migration;
namespace CrestApps.Sports.Calendar.Migrations;
internal sealed class SportEventMigrations : DataMigration
{
public async Task<int> UpdateFrom1Async()
{
await SchemaBuilder.CreateMapIndexTableAsync<SportEventPartIndex>(table => table
.Column<string>("ContentItemId", column => column.WithLength(26))
.Column<bool>("Published")
.Column<DateTime>("EventDateUtc")
.Column<DateTime?>("EndDateUtc")
);
await SchemaBuilder.AlterIndexTableAsync<SportEventPartIndex>(table => table
.CreateIndex(
"IDX_SportEventPartIndex_EventDateUtc",
"Published",
"EventDateUtc")
.CreateIndex(
"IDX_SportEventPartIndex_EndDateUtc",
"Published",
"EndDateUtc")
);
return 2;
}
}
public enum SportEventStatus
{
Draft,
Published,
}
public sealed class SportEventPartIndex : MapIndex
{
public long DocumentId { get; set; }
public string ContentItemId { get; set; }
public SportEventStatus Status { get; set; }
}
await SchemaBuilder.CreateMapIndexTableAsync<SportEventPartIndex>(table => table
.Column<string>("ContentItemId", column => column.WithLength(26))
.Column<SportEventStatus>("Status")
);
using CrestApps.Sports.Core.Indexes;
using CrestApps.Sports.Drills.Migrations;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Data.Migration;
using OrchardCore.Modules;
using YesSql.Indexes;
namespace CrestApps.Sports.Drills;
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddIndexProvider<DrillsIndexProvider>();
// DrillsMigrations creates the DrillsIndex table, as in the migration example above.
services.AddDataMigration<DrillsMigrations>();
}
}
using CrestApps.Sports.Core.Indexes;
using YesSql;
public sealed class SportsContentService
{
private readonly ISession _session;
public SportsContentService(ISession session)
{
_session = session;
}
public async Task<IEnumerable<string>> GetDrillIdsBySkillAsync(string skillContentItemId)
{
var rows = await _session
.QueryIndex<DrillsIndex>(x => x.Published && x.SkillContentItemId == skillContentItemId)
.ListAsync();
return rows.Select(x => x.DrillContentItemId);
}
}
A MapIndex makes a good backing store for a custom data source: derive a RecordDataSet<TIndex> that pages through ISession.QueryIndex<TIndex>() in a stable order (for example by Id), and apply DataConditions.Keys(...)/DataConditions.DateRange(...) to the index query. Implement IAggregateRecordDataSet to answer counts and sums with a GROUP BY on the index table. See orchardcore-data-sources, and orchardcore-data-formulas for how pipeline filters arrive as DataConditions.
YesSql options (command page size, query gating, identity column size, ...) are configured in the OrchardCore:YesSql section (formerly OrchardCore_YesSql, still read but deprecated in 4.0); see orchardcore-data.
Orchard Core 4.0 uses YesSql 6.3.0. Index providers, MapIndex/ReduceIndex, SchemaBuilder and QueryIndex APIs are unchanged; 6.3 adds the index declarations above, SkipDeduplication() and NoIndexOptimizations(), and creates the indexes that a data migration adds to an existing table without blocking writes (online on SQL Server editions that support it, ALGORITHM=INPLACE, LOCK=NONE on MySQL; PostgreSQL and SQLite still block). Set OrchardCore:YesSql:ConcurrentIndexCreationEnabled to false to create them the regular way. YesSql also emits telemetry: with orchardcore-opentelemetry, add YesSql to Tracing:Sources and Metrics:Meters to see a span per command, db.client.operation.duration, and the yessql.session.commands histogram that exposes N+1 query patterns. IncludeQueryTextInTelemetry (default false) adds the SQL text to those spans; raw SQL fragments passed to a query are included verbatim, so leave it off when telemetry leaves your trust boundary.
null and non-null columns, prefer two YesSql queries with supported predicates over a single predicate that uses a ternary.ExclusiveToDocumentType() and SingleRecordPerDocument() on new map indexes when they hold; never declare SingleRecordPerDocument() on an index that returns one row per tag, term or picked item.DocumentId explicitly to a MapIndex migration table, because YesSql creates that column automatically.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
orchard-core, yessql, custom-index, index-provider, map-index
/orchardcore:orchardcore-yessql-indexesfrom orchardcore
npx claudepluginhub crestapps/crestapps.agentskills --plugin orchardcore140 skills in this plugin
/orchardcore-adminGuidance for the Orchard Core admin panel, including admin controllers and routes, admin menu registration with AdminNavigationProvider, ocat editor forms grouped in cards, admin pages rendering Model.Editor, the UI text casing standard, TheAdmin layout and menu colors, admin branding, the Navbar shape, the Ctrl+K quick navigation palette and QuickNavigationSource, AdminSettings such as MenuBehavior, ShowBreadcrumb, DisplayQuickNavigation, DisplayTitlesInTopbar and ActionsLayout, the AdminDashboard shape, settings pages, and admin filters and zones. Use this skill when requests mention the Orchard Core admin panel, TheAdmin, admin controllers, admin menu registration, an icon on an admin menu item, the AdminSettings recipe step, quick navigation, navigation menu behavior, the admin URL prefix, UI text casing. Strong matches include OrchardCore.Admin, AdminSettings, AdminPermissions, AdminOptions, AdminAttribute, SiteDisplayDriver, IDisplayManager./orchardcore-admin-dashboardSkill for creating admin dashboard widgets in Orchard Core. Covers the DashboardWidget stereotype, DashboardPart position and sizing, the built-in HtmlDashboardWidget, ContentsMetadata and ContentsTags widget types, custom widget content types via recipe or migration, arranging widgets in Manage Dashboard mode, widget template customization, provisioning widgets with recipes, dashboard permissions, the DashboardBreadcrumbProvider Dashboard ancestor, and the AdminDashboardContent shape used when the feature is disabled. Use this skill when requests mention Orchard Core Admin Dashboard, Create and Configure Dashboard Widgets, Enabling Admin Dashboard, Widget Configuration Properties, dashboard widget recipes, Dashboard breadcrumb, or related implementation, setup, or troubleshooting work. Strong matches include OrchardCore.AdminDashboard, DashboardPart, DashboardBreadcrumbProvider, AccessAdminDashboard, ManageAdminDashboard.Other plugins' skills for the same job