0
0

Compare commits

..

3 Commits

Author SHA1 Message Date
2a759b8d39 Update sql script
All checks were successful
Test API / build (push) Successful in 2m48s
2024-01-23 23:30:48 +03:00
3580e84f53 Remove RAUTITAN from tests 2024-01-23 23:30:48 +03:00
709d58aa8b Add index to DB 2024-01-23 23:30:47 +03:00
11 changed files with 47 additions and 24 deletions

View File

@ -14,12 +14,14 @@ CREATE TABLE "Products" (
"ProductLines" text[] NOT NULL, "ProductLines" text[] NOT NULL,
"IsOnWarehouse" boolean NOT NULL, "IsOnWarehouse" boolean NOT NULL,
"ProductMeasure" integer NOT NULL, "ProductMeasure" integer NOT NULL,
"DeliveryMakeUp" double precision NULL, "DeliveryMakeUp" double precision,
"Price" numeric NOT NULL, "Price" numeric NOT NULL,
CONSTRAINT "PK_Products" PRIMARY KEY ("Id") CONSTRAINT "PK_Products" PRIMARY KEY ("Id")
); );
CREATE INDEX "IX_Products_Name" ON "Products" USING GIN (to_tsvector('russian', "Name"));
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20230511043408_Init', '7.0.5'); VALUES ('20240117210635_Init', '8.0.0');
COMMIT; COMMIT;

View File

@ -13,8 +13,8 @@ public class RautitanFittingsTests : ProductQueryModifierTests
public void SupportingClipTest(string query, string modified) public void SupportingClipTest(string query, string modified)
=> Execute(productType: "Желоб", query, modified); => Execute(productType: "Желоб", query, modified);
[TestCase("Тройник 20-16-16", "Тройник RAUTITAN -PLATINUM 20-16-16")] [TestCase("Тройник 20-16-16", "Тройник -PLATINUM 20-16-16")]
[TestCase("Тройник 20x16x16", "Тройник RAUTITAN -PLATINUM 20-16-16")] [TestCase("Тройник 20x16x16", "Тройник -PLATINUM 20-16-16")]
public void TPieceTest(string query, string modified) public void TPieceTest(string query, string modified)
=> Execute(productType: "Тройник RAUTITAN", query, modified); => Execute(productType: "Тройник RAUTITAN", query, modified);
@ -30,7 +30,7 @@ public class RautitanFittingsTests : ProductQueryModifierTests
public void AdapterInternalTest(string query, string modified) public void AdapterInternalTest(string query, string modified)
=> Execute(productType: "Переходник на внутреннюю резьбу", query, modified); => Execute(productType: "Переходник на внутреннюю резьбу", query, modified);
[TestCase("Угольник 90°, 40 PX", "Угольник RAUTITAN -PLATINUM 90 40")] [TestCase("Угольник 90°, 40 PX", "Угольник -PLATINUM 90 40")]
public void ElbowTest(string query, string modified) public void ElbowTest(string query, string modified)
=> Execute(productType: "Угольник RAUTITAN", query, modified); => Execute(productType: "Угольник RAUTITAN", query, modified);
@ -47,12 +47,12 @@ public class RautitanFittingsTests : ProductQueryModifierTests
public void ScrewcapElbowTest(string query, string modified) public void ScrewcapElbowTest(string query, string modified)
=> Execute(productType: "Угольник с накидной гайкой", query, modified); => Execute(productType: "Угольник с накидной гайкой", query, modified);
[TestCase("Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25 RX+", "Тройник RAUTITAN с внутр. резьбой на боков. проходе 25-Rp 1/2-25")] [TestCase("Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25 RX+", "Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25")]
[TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник RAUTITAN настенный с внутренней резьбой 16-Rp1/2-16")] [TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник настенный с внутренней резьбой 16-Rp1/2-16")]
public void ThreadTPieceInternalTest(string query, string modified) public void ThreadTPieceInternalTest(string query, string modified)
=> Execute(productType: "Тройник RAUTITAN резьбовой внутренний", query, modified); => Execute(productType: "Тройник RAUTITAN резьбовой внутренний", query, modified);
[TestCase("Тройник RAUTITAN RX+ с наружной резьбой 20-20-R 3/4", "Тройник RAUTITAN с наружной резьбой 20-20-R 3/4")] [TestCase("Тройник RAUTITAN RX+ с наружной резьбой 20-20-R 3/4", "Тройник с наружной резьбой 20-20-R 3/4")]
public void ThreadTPieceExternalTest(string query, string modified) public void ThreadTPieceExternalTest(string query, string modified)
=> Execute(productType: "Тройник RAUTITAN резьбовой наружный", query, modified); => Execute(productType: "Тройник RAUTITAN резьбовой наружный", query, modified);

View File

@ -23,9 +23,9 @@ namespace RhSolutions.Api.Controllers
public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query) public IAsyncEnumerable<Product> SearchProducts([FromQuery] string query)
{ {
return context.Products return context.Products
.Where(p => EF.Functions.ToTsVector( .Where(p => EF.Functions.ToTsVector("russian", p.Name)
"russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines)}))
.Matches(EF.Functions.WebSearchToTsQuery("russian", query))) .Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
.Where(p => p.ProductLines.Contains("RAUTITAN"))
.OrderByDescending(p => p.IsOnWarehouse) .OrderByDescending(p => p.IsOnWarehouse)
.AsAsyncEnumerable(); .AsAsyncEnumerable();
} }

View File

@ -13,7 +13,7 @@ using RhSolutions.Models;
namespace RhSolutions.Api.Migrations namespace RhSolutions.Api.Migrations
{ {
[DbContext(typeof(RhSolutionsContext))] [DbContext(typeof(RhSolutionsContext))]
[Migration("20230511043408_Init")] [Migration("20240117210635_Init")]
partial class Init partial class Init
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -21,7 +21,7 @@ namespace RhSolutions.Api.Migrations
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "7.0.5") .HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -34,7 +34,7 @@ namespace RhSolutions.Api.Migrations
b.Property<double?>("DeliveryMakeUp") b.Property<double?>("DeliveryMakeUp")
.HasColumnType("double precision"); .HasColumnType("double precision");
b.Property<List<string>>("DeprecatedSkus") b.Property<string[]>("DeprecatedSkus")
.IsRequired() .IsRequired()
.HasColumnType("text[]"); .HasColumnType("text[]");
@ -61,6 +61,11 @@ namespace RhSolutions.Api.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("Name")
.HasAnnotation("Npgsql:TsVectorConfig", "russian");
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Name"), "GIN");
b.ToTable("Products"); b.ToTable("Products");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618

View File

@ -18,7 +18,7 @@ namespace RhSolutions.Api.Migrations
Id = table.Column<string>(type: "text", nullable: false), Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false), Name = table.Column<string>(type: "text", nullable: false),
ProductSku = table.Column<string>(type: "text", nullable: false), ProductSku = table.Column<string>(type: "text", nullable: false),
DeprecatedSkus = table.Column<List<string>>(type: "text[]", nullable: false), DeprecatedSkus = table.Column<string[]>(type: "text[]", nullable: false),
ProductLines = table.Column<List<string>>(type: "text[]", nullable: false), ProductLines = table.Column<List<string>>(type: "text[]", nullable: false),
IsOnWarehouse = table.Column<bool>(type: "boolean", nullable: false), IsOnWarehouse = table.Column<bool>(type: "boolean", nullable: false),
ProductMeasure = table.Column<int>(type: "integer", nullable: false), ProductMeasure = table.Column<int>(type: "integer", nullable: false),
@ -29,6 +29,13 @@ namespace RhSolutions.Api.Migrations
{ {
table.PrimaryKey("PK_Products", x => x.Id); table.PrimaryKey("PK_Products", x => x.Id);
}); });
migrationBuilder.CreateIndex(
name: "IX_Products_Name",
table: "Products",
column: "Name")
.Annotation("Npgsql:IndexMethod", "GIN")
.Annotation("Npgsql:TsVectorConfig", "russian");
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -18,7 +18,7 @@ namespace RhSolutions.Api.Migrations
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.HasAnnotation("ProductVersion", "7.0.5") .HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -31,7 +31,7 @@ namespace RhSolutions.Api.Migrations
b.Property<double?>("DeliveryMakeUp") b.Property<double?>("DeliveryMakeUp")
.HasColumnType("double precision"); .HasColumnType("double precision");
b.Property<List<string>>("DeprecatedSkus") b.Property<string[]>("DeprecatedSkus")
.IsRequired() .IsRequired()
.HasColumnType("text[]"); .HasColumnType("text[]");
@ -58,6 +58,11 @@ namespace RhSolutions.Api.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("Name")
.HasAnnotation("Npgsql:TsVectorConfig", "russian");
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Name"), "GIN");
b.ToTable("Products"); b.ToTable("Products");
}); });
#pragma warning restore 612, 618 #pragma warning restore 612, 618

View File

@ -18,5 +18,9 @@ public class RhSolutionsContext : DbContext
.PrimitiveCollection(e => e.DeprecatedSkus) .PrimitiveCollection(e => e.DeprecatedSkus)
.ElementType() .ElementType()
.HasConversion(typeof(SkuConverter)); .HasConversion(typeof(SkuConverter));
} builder.Entity<Product>()
.HasIndex(b => new { b.Name })
.HasMethod("GIN")
.IsTsVectorExpressionIndex("russian");
}
} }

View File

@ -2,7 +2,7 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class Elbow : DrinkingWaterHeatingFitting public class Elbow : DrinkingWaterHeatingFitting
{ {
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM"; protected override string _title { get; } = "Угольник -PLATINUM";
public override bool TryQueryModify(string input, out string output) public override bool TryQueryModify(string input, out string output)
{ {

View File

@ -2,7 +2,7 @@
public class TPiece : DrinkingWaterHeatingFitting public class TPiece : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Тройник RAUTITAN -PLATINUM"; protected override string _title => "Тройник -PLATINUM";
public override bool TryQueryModify(string input, out string output) public override bool TryQueryModify(string input, out string output)
{ {

View File

@ -4,7 +4,7 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ThreadTPieceExternal : DrinkingWaterHeatingFitting public class ThreadTPieceExternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Тройник RAUTITAN с наружной резьбой"; protected override string _title => "Тройник с наружной резьбой";
public override bool TryQueryModify(string input, out string output) public override bool TryQueryModify(string input, out string output)
{ {

View File

@ -18,22 +18,22 @@ public class ThreadTPieceInternal : DrinkingWaterHeatingFitting
{ {
if (diameters[0] < 25) if (diameters[0] < 25)
{ {
output = $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}"; output = $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}";
} }
else else
{ {
output = $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}"; output = $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}";
} }
} }
else else
{ {
if (diameters[0] < 25) if (diameters[0] < 25)
{ {
output = $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}"; output = $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}";
} }
else else
{ {
output = $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}"; output = $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}";
} }
} }
return true; return true;