autocomplete
This commit is contained in:
parent
b8809deaa1
commit
aaa49788dc
4 changed files with 52 additions and 14 deletions
|
|
@ -33,7 +33,7 @@ namespace nuget_host.Controllers
|
|||
this.dbContext = dbContext;
|
||||
}
|
||||
|
||||
|
||||
const string defaultSemVer = "2.0.0";
|
||||
// dotnet add . package -s http://localhost:5000/packages nuget-cli
|
||||
// packages/FindPackagesById()?id='nuget-cli'&semVerLevel=2.0.0
|
||||
|
||||
|
|
@ -43,11 +43,11 @@ namespace nuget_host.Controllers
|
|||
[HttpGet("~/search/index.json")]
|
||||
public IActionResult Index(
|
||||
string q,
|
||||
string semVerLevel = defaultSemVer,
|
||||
bool prerelease = false,
|
||||
string packageType = null,
|
||||
int skip = 0,
|
||||
int take = 25,
|
||||
string semVerLevel = "2.0.0")
|
||||
int take = 25)
|
||||
{
|
||||
if (string.IsNullOrEmpty(q))
|
||||
{
|
||||
|
|
@ -56,14 +56,15 @@ namespace nuget_host.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
var scope = dbContext.Packages
|
||||
var scope = dbContext.Packages
|
||||
.Include(p => p.Versions)
|
||||
.Where(
|
||||
p => (CamelCaseMatch(p.Id, q) || SeparatedByMinusMatch(p.Id, q))
|
||||
&& (prerelease || p.Versions.Any(v => !v.IsPrerelease))
|
||||
&& (packageType == null || p.Versions.Any(v => v.Type == packageType))
|
||||
);
|
||||
var result = new {
|
||||
var result = new
|
||||
{
|
||||
totalHits = scope.Count(),
|
||||
data = scope.Skip(skip).Take(take).ToArray()
|
||||
};
|
||||
|
|
@ -75,13 +76,13 @@ namespace nuget_host.Controllers
|
|||
{
|
||||
// Assert.False (q==null);
|
||||
string query = q;
|
||||
if (query.Length==0) return false;
|
||||
if (query.Length == 0) return false;
|
||||
|
||||
while (id.Length > 0)
|
||||
{
|
||||
int i = 0;
|
||||
while (id.Length > i && char.IsLower(id[i])) i++;
|
||||
if (i==0) break;
|
||||
if (i == 0) break;
|
||||
id = id.Substring(i);
|
||||
if (id.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
|
|
@ -95,5 +96,28 @@ namespace nuget_host.Controllers
|
|||
}
|
||||
return false;
|
||||
}
|
||||
// GET /autocomplete?id=nuget.protocol&prerelease=true
|
||||
[HttpGet("~/autocomplete")]
|
||||
public IActionResult AutoComplete(
|
||||
string id,
|
||||
string semVerLevel = defaultSemVer,
|
||||
bool prerelease = false,
|
||||
string packageType = null,
|
||||
int skip = 0,
|
||||
int take = 25)
|
||||
{
|
||||
return Ok(new
|
||||
{
|
||||
data =
|
||||
dbContext.PackageVersions.Where(
|
||||
v => v.PackageId == id
|
||||
&& (prerelease || !v.IsPrerelease)
|
||||
&& (packageType == null || v.Type == packageType)
|
||||
).Select(v => v.FullString)
|
||||
.Skip(skip).Take(take).ToArray()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue