-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding console app to implement, test search
- Loading branch information
Showing
9 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace SearchComponent | ||
{ | ||
/// <summary> | ||
/// http://www.bilyachat.com/2015/07/search-like-google-with-elasticsearch.html | ||
/// Implementing solution from http://www.bilyachat.com using ElaticsearchCrud | ||
/// </summary> | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var personCitySearchProvider = new PersonCitySearchProvider(); | ||
|
||
// create a new index and type mapping in elasticseach | ||
personCitySearchProvider.CreateIndex(); | ||
//Console.ReadLine(); | ||
|
||
// create a new index and type mapping in elasticseach | ||
personCitySearchProvider.CreateMapping(); | ||
Console.ReadLine(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("googleStyleSearch")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("c88df104-b6f2-4760-8654-d171bdc060fb")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>c88df104-b6f2-4760-8654-d171bdc060fb</ProjectGuid> | ||
<RootNamespace>SearchComponent</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
9 changes: 9 additions & 0 deletions
9
samples/SearchComponent/SearchProvider/IPersonCitySearchProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SearchComponent | ||
{ | ||
public interface IPersonCitySearchProvider | ||
{ | ||
void CreateIndex(); | ||
|
||
void CreateTestData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace SearchComponent | ||
{ | ||
public class PersonCity | ||
{ | ||
public long Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public string FamilyName { get; set; } | ||
|
||
public string Info { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
samples/SearchComponent/SearchProvider/PersonCityMapping.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using ElasticsearchCRUD; | ||
|
||
namespace SearchComponent | ||
{ | ||
public class PersonCityMapping : ElasticsearchMapping | ||
{ | ||
public override string GetIndexForType(Type type) | ||
{ | ||
return "personcity"; | ||
} | ||
|
||
public override string GetDocumentType(Type type) | ||
{ | ||
return "personcitys"; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
samples/SearchComponent/SearchProvider/PersonCityMappingDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using ElasticsearchCRUD.ContextAddDeleteUpdate.CoreTypeAttributes; | ||
|
||
namespace SearchComponent | ||
{ | ||
public class PersonCityMappingDto | ||
{ | ||
public long Id { get; set; } | ||
|
||
[ElasticsearchString(CopyToList = new[] { "autocomplete", "didYouMean" })] | ||
public string Name { get; set; } | ||
|
||
[ElasticsearchString(CopyToList = new[] { "autocomplete", "didYouMean" })] | ||
public string FamilyName { get; set; } | ||
|
||
[ElasticsearchString(CopyToList = new[] { "autocomplete", "didYouMean" })] | ||
public string Info { get; set; } | ||
|
||
[ElasticsearchString(Analyzer = "didYouMean")] | ||
public string did_you_mean { get; set; } | ||
|
||
[ElasticsearchString(Analyzer = "autocomplete")] | ||
public string autocomplete { get; set; } | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
samples/SearchComponent/SearchProvider/PersonCitySearchProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System.Collections.Generic; | ||
using ElasticsearchCRUD; | ||
using ElasticsearchCRUD.ContextAddDeleteUpdate.IndexModel.MappingModel; | ||
using ElasticsearchCRUD.ContextAddDeleteUpdate.IndexModel.SettingsModel; | ||
using ElasticsearchCRUD.ContextAddDeleteUpdate.IndexModel.SettingsModel.Analyzers; | ||
using ElasticsearchCRUD.ContextAddDeleteUpdate.IndexModel.SettingsModel.Filters; | ||
using ElasticsearchCRUD.Model; | ||
using ElasticsearchCRUD.Tracing; | ||
|
||
namespace SearchComponent | ||
{ | ||
public class PersonCitySearchProvider : IPersonCitySearchProvider | ||
{ | ||
private readonly IElasticsearchMappingResolver _elasticsearchMappingResolver = new ElasticsearchMappingResolver(); | ||
private const string ConnectionString = "http://localhost:9200"; | ||
private readonly ElasticsearchContext _context; | ||
|
||
public PersonCitySearchProvider() | ||
{ | ||
_elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(PersonCityMappingDto), new PersonCityMapping()); | ||
_context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)) | ||
{ | ||
TraceProvider = new ConsoleTraceProvider() | ||
}; | ||
} | ||
|
||
public void CreateIndex() | ||
{ | ||
_context.IndexCreate<PersonCityMappingDto>(CreateNewIndexDefinition()); | ||
} | ||
|
||
public void CreateMapping() | ||
{ | ||
_context.IndexCreateTypeMapping<PersonCityMappingDto>(new MappingDefinition()); | ||
} | ||
|
||
private IndexDefinition CreateNewIndexDefinition() | ||
{ | ||
return new IndexDefinition | ||
{ | ||
IndexSettings = | ||
{ | ||
Analysis = new Analysis | ||
{ | ||
Filters = | ||
{ | ||
CustomFilters = new List<AnalysisFilterBase> | ||
{ | ||
new StemmerTokenFilter("stemmer"), | ||
new ShingleTokenFilter("autocompleteFilter") | ||
{ | ||
MaxShingleSize = 5, | ||
MinShingleSize = 2 | ||
}, | ||
new StopTokenFilter("stopwords") | ||
} | ||
}, | ||
Analyzer = | ||
{ | ||
Analyzers = new List<AnalyzerBase> | ||
{ | ||
new CustomAnalyzer("didYouMean") | ||
{ | ||
Tokenizer = DefaultTokenizers.Standard, | ||
Filter = new List<string> {DefaultTokenFilters.Lowercase}, | ||
CharFilter = new List<string> {DefaultCharFilters.HtmlStrip} | ||
}, | ||
new CustomAnalyzer("autocomplete") | ||
{ | ||
Tokenizer = DefaultTokenizers.Standard, | ||
Filter = new List<string> {DefaultTokenFilters.Lowercase, "autocompleteFilter"}, | ||
CharFilter = new List<string> {DefaultCharFilters.HtmlStrip} | ||
}, | ||
new CustomAnalyzer("default") | ||
{ | ||
Tokenizer = DefaultTokenizers.Standard, | ||
Filter = new List<string> {DefaultTokenFilters.Lowercase, "stopwords", "stemmer"}, | ||
CharFilter = new List<string> {DefaultCharFilters.HtmlStrip} | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
} | ||
}, | ||
}; | ||
|
||
} | ||
|
||
public void CreateTestData() | ||
{ | ||
var jm = new PersonCity { Id = 1, FamilyName = "Moore", Info = "Muenich", Name = "John"}; | ||
_context.AddUpdateDocument(jm, jm.Id); | ||
var jj = new PersonCity { Id = 2, FamilyName = "Jones", Info = "Münich", Name = "Johny" }; | ||
_context.AddUpdateDocument(jj, jj.Id); | ||
var pm = new PersonCity { Id = 3, FamilyName = "Murphy", Info = "Munich", Name = "Paul" }; | ||
_context.AddUpdateDocument(pm, pm.Id); | ||
var sm = new PersonCity { Id = 4, FamilyName = "McGurk", Info = "munich", Name = "Séan" }; | ||
_context.AddUpdateDocument(sm, sm.Id); | ||
var sob = new PersonCity { Id = 5, FamilyName = "O'Brien", Info = "Not a much use, bit of a problem", Name = "Sean" }; | ||
_context.AddUpdateDocument(sob, sob.Id); | ||
var tmc = new PersonCity { Id = 6, FamilyName = "McCauley", Info = "Couldn't a ask for anyone better", Name = "Tadhg" }; | ||
_context.AddUpdateDocument(tmc, tmc.Id); | ||
var id7 = new PersonCity { Id = 7, FamilyName = "Martini", Info = "Köniz", Name = "Christian" }; | ||
_context.AddUpdateDocument(id7, id7.Id); | ||
var id8 = new PersonCity { Id = 8, FamilyName = "Lee", Info = "Basel Stadt", Name = "Phil" }; | ||
_context.AddUpdateDocument(id8, id8.Id); | ||
var id9 = new PersonCity { Id = 9, FamilyName = "Wil", Info = "Basel Stadt", Name = "Nicole" }; | ||
_context.AddUpdateDocument(id9, id9.Id); | ||
var id10 = new PersonCity { Id = 10, FamilyName = "Mario", Info = "Basel in some small town", Name = "Tim" }; | ||
_context.AddUpdateDocument(id10, id10.Id); | ||
var id11 = new PersonCity { Id = 11, FamilyName = "Martin", Info = "Biel", Name = "Scott" }; | ||
_context.AddUpdateDocument(id11, id11.Id); | ||
var id12 = new PersonCity { Id = 12, FamilyName = "Newman", Info = "Lyss", Name = "Tim" }; | ||
_context.AddUpdateDocument(id12, id12.Id); | ||
var id13 = new PersonCity { Id = 13, FamilyName = "Lamb", Info = "Thun", Name = "Carla" }; | ||
_context.AddUpdateDocument(id13, id13.Id); | ||
var id14 = new PersonCity { Id = 14, FamilyName = "Goldi", Info = "Zug", Name = "Ida" }; | ||
_context.AddUpdateDocument(id14, id14.Id); | ||
_context.SaveChanges(); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"version": "1.0.0-*", | ||
"buildOptions": { | ||
"emitEntryPoint": true | ||
}, | ||
|
||
"dependencies": { | ||
"ElasticsearchCrud": "2.3.3-2-beta", | ||
"Microsoft.NETCore.App": { | ||
"type": "platform", | ||
"version": "1.0.1" | ||
} | ||
}, | ||
|
||
"frameworks": { | ||
"netcoreapp1.0": { | ||
"imports": "dnxcore50" | ||
} | ||
} | ||
} |