Skip to content

Commit 9a26cec

Browse files
authored
Merge pull request #298 from nikcio/demo/update-project
Updated demo project
2 parents 8e32c4d + d264662 commit 9a26cec

File tree

122 files changed

+54992
-44090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+54992
-44090
lines changed

src/Examine.Web.Demo/App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>

src/Examine.Web.Demo/Controllers/HomeController.cs

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/Examine.Web.Demo/Controllers/BogusDataService.cs renamed to src/Examine.Web.Demo/Data/BogusDataService.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,24 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Bogus;
5+
using Lucene.Net.Facet.Range;
56

67
namespace Examine.Web.Demo.Controllers
78
{
89
public class BogusDataService
910
{
10-
public const int MaxCount = 27000;
11-
1211
/// <summary>
1312
/// Return a ton of people
1413
/// </summary>
1514
/// <returns></returns>
16-
public IEnumerable<ValueSet> GetAllData()
17-
=> Enumerable.Range(1, MaxCount)
15+
public IEnumerable<ValueSet> GenerateData(int count)
16+
{
17+
return Enumerable.Range(1, count)
1818
.Select(x => new Person())
1919
.Select((person, index) => new ValueSet(
2020
index.ToString(),
2121
"person",
2222
PersonValues(person)));
23-
24-
public IEnumerable<ValueSet> GetRandomItems(int count)
25-
{
26-
var random = new Random(DateTime.Now.Second);
27-
28-
return Enumerable.Range(1, count)
29-
.Select(x => new Person())
30-
.Select((person, index) => new ValueSet(
31-
random.Next(1, MaxCount).ToString(),
32-
"person",
33-
PersonValues(person)));
3423
}
3524

3625
private IDictionary<string, IEnumerable<object>> PersonValues(Person person)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System.Diagnostics;
2+
using Examine.Lucene.Providers;
3+
using Examine.Search;
4+
using Examine.Web.Demo.Controllers;
5+
using Examine.Web.Demo.Data.Models;
6+
using Lucene.Net.Search;
7+
8+
namespace Examine.Web.Demo.Data
9+
{
10+
public class IndexService
11+
{
12+
private readonly IExamineManager _examineManager;
13+
private readonly BogusDataService _bogusDataService;
14+
15+
public IndexService(IExamineManager examineManager, BogusDataService bogusDataService) {
16+
_examineManager = examineManager;
17+
_bogusDataService = bogusDataService;
18+
}
19+
20+
public void RebuildIndex(string indexName, int dataSize)
21+
{
22+
var index = GetIndex(indexName);
23+
24+
index.CreateIndex();
25+
26+
var data = _bogusDataService.GenerateData(dataSize);
27+
28+
index.IndexItems(data);
29+
}
30+
31+
public IndexInformation GetIndexInformation(string indexName)
32+
{
33+
var index = GetIndex(indexName);
34+
35+
if (index is IIndexStats indexStats)
36+
{
37+
var fields = indexStats.GetFieldNames();
38+
return new IndexInformation(
39+
indexStats.GetDocumentCount(),
40+
fields.ToList());
41+
}
42+
else
43+
{
44+
throw new InvalidOperationException($"Failed to get index stats on {indexName}");
45+
}
46+
}
47+
48+
public void AddToIndex(string indexName, int dataSize)
49+
{
50+
var index = GetIndex(indexName);
51+
52+
var data = _bogusDataService.GenerateData(dataSize);
53+
54+
index.IndexItems(data);
55+
}
56+
57+
public IEnumerable<IIndex> GetAllIndexes()
58+
{
59+
return _examineManager.Indexes;
60+
}
61+
62+
public ISearchResults SearchNativeQuery(string indexName, string query)
63+
{
64+
var index = GetIndex(indexName);
65+
66+
var searcher = index.Searcher;
67+
var criteria = searcher.CreateQuery();
68+
return criteria.NativeQuery(query).Execute();
69+
}
70+
71+
public ISearchResults SearchNativeQueryAcrossIndexes(string query)
72+
{
73+
if (!_examineManager.TryGetSearcher("MultiIndexSearcher", out var multiIndexSearcher))
74+
{
75+
throw new InvalidOperationException("Failed to get MultiIndexSearcher");
76+
}
77+
78+
var searcher = multiIndexSearcher;
79+
var criteria = searcher.CreateQuery();
80+
return criteria.NativeQuery(query).Execute();
81+
}
82+
83+
public ISearchResults GetAllIndexedItems(string indexName, int skip, int take)
84+
{
85+
var index = GetIndex(indexName);
86+
87+
var searcher = index.Searcher;
88+
var criteria = searcher.CreateQuery();
89+
return criteria.All().Execute(QueryOptions.SkipTake(skip, take));
90+
}
91+
92+
private IIndex GetIndex(string indexName)
93+
{
94+
if (!_examineManager.TryGetIndex(indexName, out var index))
95+
{
96+
throw new ArgumentException($"Index '{indexName}' not found");
97+
}
98+
99+
return index;
100+
}
101+
}
102+
103+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Examine.Web.Demo.Data.Models
2+
{
3+
public class IndexInformation
4+
{
5+
public IndexInformation(long documentCount, List<string> fields)
6+
{
7+
DocumentCount = documentCount;
8+
Fields = fields;
9+
FieldCount = fields.Count;
10+
}
11+
12+
public long DocumentCount { get; }
13+
public List<string> Fields { get; }
14+
public int FieldCount { get; set; }
15+
}
16+
}
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
23
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
5-
</PropertyGroup>
6-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
7-
<OutputPath>bin\</OutputPath>
8-
<DefineConstants>TRACE;DEBUG;FULLDEBUG</DefineConstants>
9-
<CodeAnalysisRuleSet>SecurityRules.ruleset</CodeAnalysisRuleSet>
10-
</PropertyGroup>
11-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
12-
<DebugType>none</DebugType>
13-
<OutputPath>bin\</OutputPath>
14-
</PropertyGroup>
15-
<PropertyGroup>
16-
<TargetFramework>net5.0</TargetFramework>
17-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
18-
<IsPackable>false</IsPackable>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
197
</PropertyGroup>
8+
209
<ItemGroup>
21-
<Compile Remove="Examine\**" />
22-
<Content Remove="Examine\**" />
23-
<EmbeddedResource Remove="Examine\**" />
24-
<None Remove="Examine\**" />
10+
<PackageReference Include="Bogus" Version="34.0.2" />
2511
</ItemGroup>
12+
2613
<ItemGroup>
27-
<ProjectReference Include="..\Examine.Core\Examine.Core.csproj" />
2814
<ProjectReference Include="..\Examine.Host\Examine.csproj" />
29-
<ProjectReference Include="..\Examine.Lucene\Examine.Lucene.csproj" />
30-
</ItemGroup>
31-
<ItemGroup>
32-
<PackageReference Include="Bogus" Version="33.0.2" />
33-
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
34-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
35-
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00016" />
36-
</ItemGroup>
37-
<ItemGroup>
38-
<PackageReference Include="Modernizr" Version="1.7" />
3915
</ItemGroup>
40-
</Project>
16+
17+
</Project>

src/Examine.Web.Demo/Models/IndexInfo.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)