Compare commits
No commits in common. "db73af3bdd802be00b51b9f6c5370aa99af2a847" and "bec3ac52a9efeb71782834da03d7bf05bf836124" have entirely different histories.
db73af3bdd
...
bec3ac52a9
@ -61,28 +61,21 @@ public class Mangasee : MangaConnector
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string[] _filterWords = {"a", "the", "of", "as", "to", "no", "for", "on", "with", "be", "and", "in", "wa", "at", "be", "ni"};
|
||||
private string ToFilteredString(string input) => string.Join(' ', input.ToLower().Split(' ').Where(word => _filterWords.Contains(word)));
|
||||
private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults)
|
||||
{
|
||||
Dictionary<SearchResult, int> similarity = new();
|
||||
foreach (SearchResult sr in unfilteredSearchResults)
|
||||
{
|
||||
List<int> scores = new();
|
||||
string filteredPublicationString = ToFilteredString(publicationTitle);
|
||||
string filteredSString = ToFilteredString(sr.s);
|
||||
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredSString, filteredPublicationString));
|
||||
foreach (string srA in sr.a)
|
||||
{
|
||||
string filteredAString = ToFilteredString(srA);
|
||||
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredAString, filteredPublicationString));
|
||||
}
|
||||
foreach (string se in sr.a)
|
||||
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(se.ToLower(), publicationTitle.ToLower()));
|
||||
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(sr.s.ToLower(), publicationTitle.ToLower()));
|
||||
similarity.Add(sr, scores.Sum() / scores.Count);
|
||||
}
|
||||
|
||||
List<SearchResult> ret = similarity.OrderBy(s => s.Value).Take(10).Select(s => s.Key).ToList();
|
||||
ret.AddRange(similarity.Where(s => s.Value < 5).Select(s => s.Key));
|
||||
return ret.ToArray();
|
||||
SearchResult[] similarity90 = similarity.Where(s => s.Value < 10).Select(s => s.Key).ToArray();
|
||||
|
||||
return similarity90;
|
||||
}
|
||||
|
||||
public override Manga? GetMangaFromId(string publicationId)
|
||||
|
@ -712,10 +712,6 @@ public class Server : GlobalBase
|
||||
|
||||
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||
{
|
||||
if (response.OutputStream.CanWrite == false)
|
||||
{
|
||||
Log($"No response sent to request: Stream closed before response could be sent.");
|
||||
}
|
||||
//Log($"Response: {statusCode} {content}");
|
||||
response.StatusCode = (int)statusCode;
|
||||
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
|
||||
@ -723,43 +719,43 @@ public class Server : GlobalBase
|
||||
response.AddHeader("Access-Control-Max-Age", "1728000");
|
||||
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||
|
||||
try
|
||||
if (content is not Stream)
|
||||
{
|
||||
if (content is not Stream)
|
||||
response.ContentType = "application/json";
|
||||
try
|
||||
{
|
||||
response.ContentType = "application/json";
|
||||
response.OutputStream.Write(content is not null
|
||||
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||
: Array.Empty<byte>());
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
else if (content is FileStream stream)
|
||||
catch (HttpListenerException e)
|
||||
{
|
||||
string contentType = stream.Name.Split('.')[^1];
|
||||
switch (contentType.ToLower())
|
||||
{
|
||||
case "gif":
|
||||
response.ContentType = "image/gif";
|
||||
break;
|
||||
case "png":
|
||||
response.ContentType = "image/png";
|
||||
break;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
response.ContentType = "image/jpeg";
|
||||
break;
|
||||
case "log":
|
||||
response.ContentType = "text/plain";
|
||||
break;
|
||||
}
|
||||
|
||||
stream.CopyTo(response.OutputStream);
|
||||
stream.Close();
|
||||
Log(e.ToString());
|
||||
}
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
catch (HttpListenerException e)
|
||||
else if(content is FileStream stream)
|
||||
{
|
||||
Log(e.ToString());
|
||||
string contentType = stream.Name.Split('.')[^1];
|
||||
switch (contentType.ToLower())
|
||||
{
|
||||
case "gif":
|
||||
response.ContentType = "image/gif";
|
||||
break;
|
||||
case "png":
|
||||
response.ContentType = "image/png";
|
||||
break;
|
||||
case "jpg":
|
||||
case "jpeg":
|
||||
response.ContentType = "image/jpeg";
|
||||
break;
|
||||
case "log":
|
||||
response.ContentType = "text/plain";
|
||||
break;
|
||||
}
|
||||
stream.CopyTo(response.OutputStream);
|
||||
response.OutputStream.Close();
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user