-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of text search in the api
- Loading branch information
1 parent
cf8054e
commit d1347a3
Showing
11 changed files
with
378 additions
and
35 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
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
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,35 @@ | ||
/* | ||
Copyright 2020, Augurk | ||
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; | ||
using System.Collections.Generic; | ||
|
||
namespace Augurk.Entities.Search | ||
{ | ||
public class FeatureMatch | ||
{ | ||
public string FeatureName { get; set; } | ||
|
||
public string ProductName { get; set; } | ||
|
||
public string GroupName { get; set; } | ||
|
||
public string Version { get; set; } | ||
|
||
public IEnumerable<string> Tags { get; set; } | ||
|
||
public string MatchingText { get; set; } | ||
} | ||
} |
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,36 @@ | ||
/* | ||
Copyright 2020, Augurk | ||
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.Collections.Generic; | ||
|
||
namespace Augurk.Entities.Search | ||
{ | ||
/// <summary> | ||
/// A container for search results. | ||
/// </summary> | ||
public class SearchResults | ||
{ | ||
/// <summary> | ||
/// Gets or sets the title of this feature. | ||
/// </summary> | ||
public string SearchQuery { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a collection of features that match. | ||
/// </summary> | ||
public IEnumerable<FeatureMatch> FeatureMatches { get; set; } | ||
} | ||
} |
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
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
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
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,69 @@ | ||
/* | ||
Copyright 2020, Augurk | ||
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 Augurk.Api.Managers; | ||
using Augurk.Entities; | ||
using Augurk.Entities.Search; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Augurk.Api.Controllers.V2 | ||
{ | ||
/// <summary> | ||
/// ApiController for retrieving the available features. | ||
/// </summary> | ||
[ApiVersion("2.0")] | ||
[Route("api/v{apiVersion:apiVersion}/search")] | ||
public class SearchController : Controller | ||
{ | ||
private readonly IFeatureManager _featureManager; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SearchController"/>. | ||
/// </summary> | ||
public SearchController(IFeatureManager featureManager) | ||
{ | ||
_featureManager = featureManager ?? throw new ArgumentNullException(nameof(featureManager)); | ||
} | ||
|
||
/// <summary> | ||
/// Searches for items matching the searchquery. | ||
/// </summary> | ||
/// <param name="query">The query on which the search should be based.</param> | ||
/// <returns>Returns a range of <see cref="FeatureDescription"/> instance describing the features.</returns> | ||
[Route("")] | ||
[HttpGet] | ||
public async Task<SearchResults> GetFeaturesForProductAndGroupAsync([FromQuery(Name = "q")]string query) | ||
{ | ||
// Search for features | ||
var featureMatches = await _featureManager.Search(query); | ||
|
||
// Prepare the results | ||
var results = new SearchResults | ||
{ | ||
SearchQuery = query, | ||
FeatureMatches = featureMatches.ToList() | ||
}; | ||
|
||
return results; | ||
} | ||
} | ||
} |
Oops, something went wrong.