Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Default luceneQuery to true in Azure Search Service (#603)
Browse files Browse the repository at this point in the history
This is necessary for hijack to work properly. Old search defaulted it to true.
Address NuGet/NuGetGallery#7360
  • Loading branch information
joelverhagen committed Jul 19, 2019
1 parent 58faaad commit 4125a7a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task<V2SearchResponse> V2SearchAsync(
string semVerLevel = null,
string q = null,
string sortBy = null,
bool luceneQuery = false,
bool luceneQuery = true,
bool debug = false)
{
await EnsureInitializedAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Specialized;

namespace BasicSearchTests.FunctionalTests.Core.TestSupport
Expand All @@ -20,6 +19,8 @@ public class V2SearchBuilder : QueryBuilder

public string SortBy { get; set; }

public bool? LuceneQuery { get; set; }

public V2SearchBuilder() : base("/search/query?") { }

protected override NameValueCollection GetQueryString()
Expand Down Expand Up @@ -50,6 +51,11 @@ protected override NameValueCollection GetQueryString()
queryString["sortBy"] = SortBy;
}

if (LuceneQuery.HasValue)
{
queryString["luceneQuery"] = LuceneQuery.ToString();
}

return queryString;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,58 @@ public async Task CountOnlyReturnsCountOfSearchResults()
Assert.Null(results.Data);
}

/// <summary>
/// This is the query pattern used by gallery to handle "FindPackagesById()?id={id}" OData queries.
/// </summary>
[Fact]
public async Task ODataFindPackagesById()
{
var results = await V2SearchAsync(new V2SearchBuilder
{
Query = $"Id:\"{Constants.TestPackageId}\"",
Skip = 0,
Take = 100,
SortBy = "relevance",
IncludeSemVer2 = true,
Prerelease = true,
IgnoreFilter = true,
LuceneQuery = null,
});

Assert.NotNull(results);
Assert.True(results.TotalHits >= 1);
Assert.NotEmpty(results.Data);
foreach (var result in results.Data)
{
Assert.Equal(Constants.TestPackageId, result.PackageRegistration.Id);
}
}

/// <summary>
/// This is the query pattern used by gallery to handle "Packages(Id='{id}',Version='{version}')" OData queries.
/// </summary>
[Fact]
public async Task ODataSpecificPackage()
{
var results = await V2SearchAsync(new V2SearchBuilder
{
Query = $"Id:\"{Constants.TestPackageId}\" AND Version:\"{Constants.TestPackageVersion}\"",
Skip = 0,
Take = 1,
SortBy = "relevance",
IncludeSemVer2 = true,
Prerelease = true,
IgnoreFilter = true,
LuceneQuery = null,
});

Assert.NotNull(results);
Assert.Equal(1, results.TotalHits);
var package = Assert.Single(results.Data);
Assert.Equal(Constants.TestPackageId, package.PackageRegistration.Id);
Assert.Equal(Constants.TestPackageVersion, package.NormalizedVersion);
}

[Fact]
public async Task ResultsHonorPreReleaseField()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public async Task HasDefaultParameters()
Assert.False(lastRequest.IncludePrerelease);
Assert.False(lastRequest.IncludeSemVer2);
Assert.Null(lastRequest.Query);
Assert.False(lastRequest.LuceneQuery);
Assert.True(lastRequest.LuceneQuery);
Assert.False(lastRequest.ShowDebug);
}

Expand Down

0 comments on commit 4125a7a

Please sign in to comment.