Skip to content

Commit

Permalink
Feature/text search (#210)
Browse files Browse the repository at this point in the history
Initial implementation of text search in the api
  • Loading branch information
marktaling committed Apr 28, 2020
1 parent cf8054e commit d1347a3
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 35 deletions.
31 changes: 27 additions & 4 deletions src/Augurk.Entities/Background.cs
@@ -1,20 +1,23 @@
/*
Copyright 2014, Mark Taling
Copyright 2014, 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;
using System.Linq;
using System.Text;

namespace Augurk.Entities
{
Expand All @@ -38,5 +41,25 @@ public class Background
/// Gets or sets the steps of this background.
/// </summary>
public IEnumerable<Step> Steps { get; set; }

/// <summary>
/// Creates a textual representation of this background.
/// </summary>
/// <returns>A <see cref="System.String"/> representation of this <see cref="Background"/> instance.</returns>
public override string ToString()
{
if (Steps == null || !Steps.Any())
{
return String.Empty;
}

var sb = new StringBuilder();
foreach(var step in Steps)
{
sb.AppendLine(step.ToString());
}

return sb.ToString();
}
}
}
31 changes: 27 additions & 4 deletions src/Augurk.Entities/Scenario.cs
@@ -1,20 +1,23 @@
/*
Copyright 2014, Mark Taling
Copyright 2014, 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;
using System.Linq;
using System.Text;

namespace Augurk.Entities
{
Expand Down Expand Up @@ -47,5 +50,25 @@ public class Scenario
/// Gets or sets the example sets for this scenario.
/// </summary>
public IEnumerable<ExampleSet> ExampleSets { get; set; }

/// <summary>
/// Creates a textual representation of this background.
/// </summary>
/// <returns>A <see cref="System.String"/> representation of this <see cref="Scenario"/> instance.</returns>
public override string ToString()
{
if (Steps == null || !Steps.Any())
{
return String.Empty;
}

var sb = new StringBuilder();
foreach(var step in Steps)
{
sb.AppendLine(step.ToString());
}

return sb.ToString();
}
}
}
35 changes: 35 additions & 0 deletions src/Augurk.Entities/Search/FeatureMatch.cs
@@ -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; }
}
}
36 changes: 36 additions & 0 deletions src/Augurk.Entities/Search/SearchResults.cs
@@ -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; }
}
}
16 changes: 12 additions & 4 deletions src/Augurk.Entities/Step.cs
@@ -1,19 +1,22 @@
/*
Copyright 2014, Mark Taling
Copyright 2014, 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.Text;

namespace Augurk.Entities
{
/// <summary>
Expand Down Expand Up @@ -45,5 +48,10 @@ public class Step
/// Gets or sets the table argument for this step.
/// </summary>
public Table TableArgument { get; set; }

public override string ToString()
{
return $"{Keyword} {Content} {(TableArgument == null ? "" : Environment.NewLine)}{TableArgument?.ToString()}";
}
}
}
29 changes: 25 additions & 4 deletions src/Augurk.Entities/Table.cs
@@ -1,20 +1,22 @@
/*
Copyright 2014, Mark Taling
Copyright 2014, 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;
using System.Text;

namespace Augurk.Entities
{
Expand All @@ -32,5 +34,24 @@ public class Table
/// Gets or sets the rows for this table.
/// </summary>
public IEnumerable<IEnumerable<string>> Rows { get; set; }

public override string ToString()
{
var sb = new StringBuilder();

sb.Append("|");
sb.Append(String.Join("|", Columns));
sb.Append("|");
sb.Append(Environment.NewLine);

foreach(var row in Rows){
sb.Append("|");
sb.Append(String.Join("|", row));
sb.Append("|");
sb.Append(Environment.NewLine);
}

return sb.ToString();
}
}
}
10 changes: 5 additions & 5 deletions src/Augurk/Controllers/V2/FeatureController.cs
@@ -1,12 +1,12 @@
/*
Copyright 2017-2019, Augurk
Copyright 2017-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.
Expand Down Expand Up @@ -36,7 +36,7 @@ public class FeatureController : Controller
private readonly Analyzer _analyzer;

/// <summary>
/// Initializes a new instance of the <see cref="FeatureV2Controller"/>.
/// Initializes a new instance of the <see cref="FeatureController"/>.
/// </summary>
public FeatureController(IFeatureManager featureManager, IAnalysisReportManager analysisReportManager)
{
Expand Down
69 changes: 69 additions & 0 deletions src/Augurk/Controllers/V2/SearchController.cs
@@ -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;
}
}
}

0 comments on commit d1347a3

Please sign in to comment.