Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated demo project #298

Merged
merged 7 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Examine.Web.Demo/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
153 changes: 0 additions & 153 deletions src/Examine.Web.Demo/Controllers/HomeController.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,24 @@
using System.Collections.Generic;
using System.Linq;
using Bogus;
using Lucene.Net.Facet.Range;

namespace Examine.Web.Demo.Controllers
{
public class BogusDataService
{
public const int MaxCount = 27000;

/// <summary>
/// Return a ton of people
/// </summary>
/// <returns></returns>
public IEnumerable<ValueSet> GetAllData()
=> Enumerable.Range(1, MaxCount)
public IEnumerable<ValueSet> GenerateData(int count)
{
return Enumerable.Range(1, count)
.Select(x => new Person())
.Select((person, index) => new ValueSet(
index.ToString(),
"person",
PersonValues(person)));

public IEnumerable<ValueSet> GetRandomItems(int count)
{
var random = new Random(DateTime.Now.Second);

return Enumerable.Range(1, count)
.Select(x => new Person())
.Select((person, index) => new ValueSet(
random.Next(1, MaxCount).ToString(),
"person",
PersonValues(person)));
}

private IDictionary<string, IEnumerable<object>> PersonValues(Person person)
Expand Down
103 changes: 103 additions & 0 deletions src/Examine.Web.Demo/Data/IndexService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System.Diagnostics;
using Examine.Lucene.Providers;
using Examine.Search;
using Examine.Web.Demo.Controllers;
using Examine.Web.Demo.Data.Models;
using Lucene.Net.Search;

namespace Examine.Web.Demo.Data
{
public class IndexService
{
private readonly IExamineManager _examineManager;
private readonly BogusDataService _bogusDataService;

public IndexService(IExamineManager examineManager, BogusDataService bogusDataService) {
_examineManager = examineManager;
_bogusDataService = bogusDataService;
}

public void RebuildIndex(string indexName, int dataSize)
{
var index = GetIndex(indexName);

index.CreateIndex();

var data = _bogusDataService.GenerateData(dataSize);

index.IndexItems(data);
}

public IndexInformation GetIndexInformation(string indexName)
{
var index = GetIndex(indexName);

if (index is IIndexStats indexStats)
{
var fields = indexStats.GetFieldNames();
return new IndexInformation(
indexStats.GetDocumentCount(),
fields.ToList());
}
else
{
throw new InvalidOperationException($"Failed to get index stats on {indexName}");
}
}

public void AddToIndex(string indexName, int dataSize)
{
var index = GetIndex(indexName);

var data = _bogusDataService.GenerateData(dataSize);

index.IndexItems(data);
}

public IEnumerable<IIndex> GetAllIndexes()
{
return _examineManager.Indexes;
}

public ISearchResults SearchNativeQuery(string indexName, string query)
{
var index = GetIndex(indexName);

var searcher = index.Searcher;
var criteria = searcher.CreateQuery();
return criteria.NativeQuery(query).Execute();
}

public ISearchResults SearchNativeQueryAcrossIndexes(string query)
{
if (!_examineManager.TryGetSearcher("MultiIndexSearcher", out var multiIndexSearcher))
{
throw new InvalidOperationException("Failed to get MultiIndexSearcher");
}

var searcher = multiIndexSearcher;
var criteria = searcher.CreateQuery();
return criteria.NativeQuery(query).Execute();
}

public ISearchResults GetAllIndexedItems(string indexName, int skip, int take)
{
var index = GetIndex(indexName);

var searcher = index.Searcher;
var criteria = searcher.CreateQuery();
return criteria.All().Execute(QueryOptions.SkipTake(skip, take));
}

private IIndex GetIndex(string indexName)
{
if (!_examineManager.TryGetIndex(indexName, out var index))
{
throw new ArgumentException($"Index '{indexName}' not found");
}

return index;
}
}

}
16 changes: 16 additions & 0 deletions src/Examine.Web.Demo/Data/Models/IndexInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Examine.Web.Demo.Data.Models
{
public class IndexInformation
{
public IndexInformation(long documentCount, List<string> fields)
{
DocumentCount = documentCount;
Fields = fields;
FieldCount = fields.Count;
}

public long DocumentCount { get; }
public List<string> Fields { get; }
public int FieldCount { get; set; }
}
}
41 changes: 9 additions & 32 deletions src/Examine.Web.Demo/Examine.Web.Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE;DEBUG;FULLDEBUG</DefineConstants>
<CodeAnalysisRuleSet>SecurityRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IsPackable>false</IsPackable>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Examine\**" />
<Content Remove="Examine\**" />
<EmbeddedResource Remove="Examine\**" />
<None Remove="Examine\**" />
<PackageReference Include="Bogus" Version="34.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Examine.Core\Examine.Core.csproj" />
<ProjectReference Include="..\Examine.Host\Examine.csproj" />
<ProjectReference Include="..\Examine.Lucene\Examine.Lucene.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="33.0.2" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00016" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Modernizr" Version="1.7" />
</ItemGroup>
</Project>

</Project>
9 changes: 0 additions & 9 deletions src/Examine.Web.Demo/Models/IndexInfo.cs

This file was deleted.

Loading