Skip to content

Commit

Permalink
Serach - autocomplate
Browse files Browse the repository at this point in the history
  • Loading branch information
uleus authored and uleus committed Feb 4, 2021
1 parent e5f1bf1 commit 961e66f
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 66 deletions.
8 changes: 4 additions & 4 deletions Elasticsearch/Search.Elasticsearch/Indexing/IndexBaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ protected static IAnalysis InitCommonAnalyzers(AnalysisDescriptor analysis)
{
return analysis.Analyzers(a => a
.Custom("autocomplete", ca => ca
.Filters("eng_stopwords", "trim", "lowercase")
.Tokenizer("autocomplete")
.Filters("stopwords_eng", "trim", "lowercase")
)
.Custom("autocomplete_search", ca => ca
.Filters("eng_stopwords", "trim", "lowercase")
.Tokenizer("lowercase")
.Tokenizer("standard")
.Filters("stopwords_eng", "trim", "lowercase")
)
)
.Tokenizers(tdesc => tdesc
Expand All @@ -64,7 +64,7 @@ protected static IAnalysis InitCommonAnalyzers(AnalysisDescriptor analysis)
)
)
.TokenFilters(f => f
.Stop("eng_stopwords", lang => lang
.Stop("stopwords_eng", lang => lang
.StopWords("_english_")
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ public class SearchableBaseItem
[Text(Analyzer = "autocomplete", SearchAnalyzer = "autocomplete_search", Name = nameof(Name))]
public string Name { get; set; }

[Text(/*Analyzer = "autocomplete",*/ Name = nameof(Market))]
[Text(Analyzer = "autocomplete", SearchAnalyzer = "autocomplete_search", Name = nameof(Market))]
public string Market { get; set; }

[Text(/*Analyzer = "autocomplete",*/ Name = nameof(State))]
public string State { get; set; }

public SearchableBaseItem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ public class SearchablePropertyItem : SearchableBaseItem
{
public const string TypeName = "searchablepropertyitem";

[Text(/*Analyzer = "autocomplete", */Name = nameof(FormerName))]
[Text(Analyzer = "autocomplete", SearchAnalyzer = "autocomplete_search", Name = nameof(FormerName))]
public string FormerName { get; set; }

[Text(/*Analyzer = "autocomplete", */Name = nameof(StreetAddres))]
[Text(Analyzer = "autocomplete", SearchAnalyzer = "autocomplete_search", Name = nameof(StreetAddres))]
public string StreetAddres { get; set; }

[Text(/*Analyzer = "autocomplete", */Name = nameof(City))]
[Text(Analyzer = "autocomplete", SearchAnalyzer = "autocomplete_search", Name = nameof(City))]
public string City { get; set; }

//[Text(Name=nameof(Lat))]
public float Lat { get; set; }

//[Text(Name = nameof(Lng))]
public float Lng { get; set; }
}
}
9 changes: 4 additions & 5 deletions Elasticsearch/Search.Elasticsearch/Search/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public SearchService(IElasticClientFactoryService aElasticClientFactoryService)
public async Task<SimpleSerachResponse> Search(SimpleSearchRequest aSearchRequest)
{
BoolQuery filterQuery = new BoolQuery();
if (!string.IsNullOrEmpty(aSearchRequest.Filter))
if (!string.IsNullOrEmpty(aSearchRequest.MarketFilterQuery))
{
var filterQueryParts = new List<QueryContainer>();
filterQueryParts.Add(
new MatchQuery()
{
Field = $"{nameof(SearchableBaseItem.Market)}",
Query = aSearchRequest.Filter.ToLower(),
Query = aSearchRequest.MarketFilterQuery.ToLower(),
Fuzziness = Fuzziness.Auto
}
);
Expand All @@ -41,11 +41,10 @@ public async Task<SimpleSerachResponse> Search(SimpleSearchRequest aSearchReques
var results = await _client.SearchAsync<SearchableBaseItem>(s => s
.Size(aSearchRequest.PageSize)
.Skip(aSearchRequest.PageStartIndex)
.Index(Indices.Index(aSearchRequest.Indices))

.Index(Indices.Index(aSearchRequest.Indices))
.Query(q => q
.MultiMatch(m => m
.Query(aSearchRequest.Query.ToLower())
.Query(aSearchRequest.AllStringFiledsQuery.ToLower())
.Fields(ff => ff
.Field($"{nameof(SearchableBaseItem.Name)}")
.Field($"{nameof(SearchableBaseItem.Market)}")
Expand Down
14 changes: 4 additions & 10 deletions Elasticsearch/Search.Elasticsearch/Search/SimpleSearchRequest.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;

namespace Search.Elasticsearch.Search
{

public class SimpleSearchRequest
{
public List<string> Indices { get; set; }


public string Query { get; set; }
public List<string> QueryFields { get; set; }
public string AllStringFiledsQuery { get; set; }


public string Filter { get; set; }
public List<string> FilterFields { get; set; }
public string MarketFilterQuery { get; set; }

public int PageSize { get; set; }
public int PageStartIndex { get; set; }
Expand Down
30 changes: 14 additions & 16 deletions Elasticsearch/Search.IndexData.Exe/DataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using Nancy.Json;
using Newtonsoft.Json;
using RestSharp;
using Search.Elasticsearch.Indexing;
using Search.Elasticsearch.Indexing;
using Search.Elasticsearch.Mapping;
using Search.WebAPI.Exe.Dto;
using System;
using System.Collections.Generic;
using System.IO;

Expand All @@ -24,26 +19,29 @@ public DataProvider()
new SearchablePropertyItem()
{
Id= 1,
Name ="My granny has a wooden super chair",
StreetAddres = "test",
Name ="Forest at Columbia",
Market="Austin",
State ="GS"
State ="GS",
StreetAddres = "3549 Curry Lane",
City = "Marietta AAA"
},
new SearchablePropertyItem()
{
Id = 2,
Name ="prop2",
StreetAddres = "nowa",
Name ="Forest at Columbia AAAA",
StreetAddres = "1000 Merrick Ferry Road",
Market="Austin",
State ="GS"
State ="GS",
City = "Marietta ZZZ"
},
new SearchablePropertyItem()
{
Id = 3,
Name ="prop3",
Name ="Forest AAA Columbia",
StreetAddres = "nowa",
Market="San Francisco",
State ="CA"
Market="1000 Bells Ferry Road",
State ="TX",
City = "Marietta"
},
};

Expand All @@ -52,7 +50,7 @@ public DataProvider()
new SearchableManagementItem()
{
Id = 1,
Name = "Company A",
Name = "Holland Residential",
Market="San Paulo",
State ="TX"
}
Expand Down
7 changes: 0 additions & 7 deletions Elasticsearch/Search.IndexData.Exe/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
using Nest;
using Newtonsoft.Json;
using Search.Elasticsearch.Indexing;
using Search.Elasticsearch.Mapping;
using Search.WebAPI.Exe.Dto;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using static Search.IndexData.Exe.DataProvider;

namespace Search.IndexData.Exe
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RestSharp" Version="106.11.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Search.Elasticsearch\Search.Elasticsearch.csproj" />
</ItemGroup>
Expand Down
14 changes: 2 additions & 12 deletions Elasticsearch/Search.WebAPI.Exe/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,8 @@ public async Task<IActionResult> Search(SearchCriteriaDto aRequest)
{
PageSize = aRequest.PageSize,
PageStartIndex = aRequest.PageStartIndex,
Query = aRequest.Phase,
QueryFields = new List<string>()
{
nameof(SearchableBaseItem.Name),
nameof(SearchableBaseItem.Market),
nameof(SearchableBaseItem.State),
nameof(SearchablePropertyItem.FormerName),
nameof(SearchablePropertyItem.StreetAddres),
nameof(SearchablePropertyItem.City)
},
Filter = aRequest.Market,
FilterFields = new List<string>() { nameof(SearchableBaseItem.Market) },
AllStringFiledsQuery = aRequest.Phase,
MarketFilterQuery = aRequest.Market,
Indices = new List<string>() { Config.IndexPropertyItemName, Config.IndexManagementItemName }
}
);
Expand Down

0 comments on commit 961e66f

Please sign in to comment.