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

Retail search samples with tests (new) #1628

Merged
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
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ applications/sudokumb @SurferJeffAtGoogle @amanda-tarafa @jskeet
securitycenter/ @hsanchez94 @amanda-tarafa @jskeet

dlp/ @pheonixblade9 @amanda-tarafa @jskeet

retail/ @chenlei1216 @amanda-tarafa @jskeet
37 changes: 37 additions & 0 deletions retail/interactive-tutorial/Retail.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RetailSearch.Samples", "RetailSearch.Samples\RetailSearch.Samples.csproj", "{9B7EDAE3-1A54-4DEE-815C-1A3652282044}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RetailSearch.Samples.Tests", "RetailSearch.Samples.Tests\RetailSearch.Samples.Tests.csproj", "{95A91660-6768-4CB1-B986-AF629D85840D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Runner", "Runner\Runner.csproj", "{9446A7B9-379D-4912-9285-6E3DF5BD887F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9B7EDAE3-1A54-4DEE-815C-1A3652282044}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B7EDAE3-1A54-4DEE-815C-1A3652282044}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B7EDAE3-1A54-4DEE-815C-1A3652282044}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B7EDAE3-1A54-4DEE-815C-1A3652282044}.Release|Any CPU.Build.0 = Release|Any CPU
{95A91660-6768-4CB1-B986-AF629D85840D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95A91660-6768-4CB1-B986-AF629D85840D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95A91660-6768-4CB1-B986-AF629D85840D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95A91660-6768-4CB1-B986-AF629D85840D}.Release|Any CPU.Build.0 = Release|Any CPU
{9446A7B9-379D-4912-9285-6E3DF5BD887F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9446A7B9-379D-4912-9285-6E3DF5BD887F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9446A7B9-379D-4912-9285-6E3DF5BD887F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9446A7B9-379D-4912-9285-6E3DF5BD887F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08B8FBFD-43D4-4AC8-AB5B-8810B9CCB0F1}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="JUnitTestLogger" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RetailSearch.Samples\RetailSearch.Samples.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using Xunit;

namespace RetailSearch.Samples.Tests
{
public class SearchSimpleQueryTest
{
[Fact]
public void TestSearchSimpleQuery()
{
const string ExpectedProductTitle = "Hoodie";

var firstPage = SearchSimpleQueryTutorial.Search().First();

Assert.Contains(firstPage, result => result.Product.Title.Contains(ExpectedProductTitle));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using Xunit;

namespace RetailSearch.Samples.Tests
{
public class SearchWithBoostSpecTest
{
[Fact]
public void TestSearchWithBoostSpec()
{
const string ExpectedProductTitle = "Tee";

var firstPage = SearchWithBoostSpecTutorial.Search().First();

Assert.Contains(firstPage, result => result.Product.Title.Contains(ExpectedProductTitle));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using Xunit;

namespace RetailSearch.Samples.Tests
{
public class SearchWithFacetSpecTest
{
[Fact]
public void TestSearchWithFacetSpec()
{
const string ExpectedProductTitle = "Tee";
const string ExpectedFacetKey = "colorFamilies";

var firstPage = SearchWithFacetSpecTutorial.Search().First();

Assert.Contains(firstPage.Facets, facet => facet.Key == ExpectedFacetKey);
Assert.Contains(firstPage, result => result.Product.Title.Contains(ExpectedProductTitle));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2021 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using Xunit;

namespace RetailSearch.Samples.Tests
{
public class SearchWithFilteringTest
{
[Fact]
public void TestSearchWithFiltering()
{
const string ExpectedProductTitleName = "Tee";
const string ExpectedProductColor = "Black";

var firstPage = SearchWithFilteringTutorial.Search().First();

Assert.Contains(firstPage, result => result.Product.Title.Contains(ExpectedProductTitleName) && result.Product.Title.Contains(ExpectedProductColor));
Assert.Contains(firstPage, result => result.Product.ColorInfo.ColorFamilies.Contains(ExpectedProductColor));
amanda-tarafa marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2021 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using Xunit;

namespace RetailSearch.Samples.Tests
{
public class SearchWithOrderingTest
{
[Fact]
public void TestSearchWithOrdering()
{
var firstPage = SearchWithOrderingTutorial.Search().First();

var firstProduct = firstPage.Results[0].Product;
var secondProduct = firstPage.Results[1].Product;

Assert.True(firstProduct.PriceInfo.Price >= secondProduct.PriceInfo.Price);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Linq;
using Xunit;

namespace RetailSearch.Samples.Tests
{
public class SearchWithQueryExpansionTest
{
[Fact]
public void TestSearchWithQueryExpansion()
{
const string ExpectedProductTitle = "Google Youth Hero Tee Grey";

var searchResultPages = SearchWithQueryExpansionTutorial.Search();

var topPages = searchResultPages.Take(3).ToList();
var firstPage = topPages[0];
var thirdPage = topPages[2];

Assert.Contains(firstPage, result => result.Product.Title.Contains(ExpectedProductTitle));
Assert.Contains(thirdPage, result => !result.Product.Title.Contains(ExpectedProductTitle));
}
}
}
24 changes: 24 additions & 0 deletions retail/interactive-tutorial/RetailSearch.Samples/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2022 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace RetailSearch.Samples
{
class Program
{
static void Main(string[] args)
{
Runner.Program.RunScript(args);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Cloud.Retail.V2" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Runner\Runner.csproj" />
</ItemGroup>

</Project>
Loading