Archived
1

-Changed Main Split view to fix a graphical bug in the results split area

-Changed the maximum width of the search field
-Fixed a bug: "Network error" when having special characters in query
-Fixed a bug: Returned false results when having a "&" in the query
This commit is contained in:
Kim Wittenburg
2012-06-18 16:19:01 +02:00
parent dd82658055
commit a5d716af91
13 changed files with 791 additions and 623 deletions

View File

@@ -42,11 +42,12 @@ typedef enum {
-(NSArray*) nextResults {
int site = (loadedResults/10) + 1;
NSString *searchPath = [NSString stringWithFormat:@"http://www.magistrix.de/lyrics/search?q=%@&page=%i", [query stringByReplacingOccurrencesOfString:@" " withString:@"+"], site];
NSString *searchPath = [NSString stringWithFormat:@"http://www.magistrix.de/lyrics/search?q=%@&page=%i", [self stringByFormattingQuery:query], site];
NSURL *searchURL = [NSURL URLWithString:searchPath];
NSError *error;
NSString *page = [NSString stringWithContentsOfURL:searchURL encoding:NSUTF8StringEncoding error:&error];
if (error) {
//Network error or invalid query
return nil;
}
PageType pType = [self typeOfPage:page];
@@ -58,13 +59,22 @@ typedef enum {
[self shouldSetResultCountFromPage:page];
return [self searchResultsFromPage:page];
} else if (pType == NoResultsPage) {
resultCount = 0;
return [[NSArray alloc] init];
} else {
NSRunAlertPanel(NSLocalizedString(@"Magistrix.messages.unknownPage.title", @""), NSLocalizedString(@"Magistrix.messages.unknownPage.detail", @""), NSLocalizedString(@"OK", @""), nil, nil);
resultCount = 0;
return [[NSArray alloc] init];
}
}
-(NSString *) stringByFormattingQuery: (NSString *) q {
NSRange stringRange = NSMakeRange(0, [q length]);
//Can replace äöü with aou, no difference in results
NSCharacterSet *characters = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
return [[[[[[q stringByReplacingOccurrencesOfString:@" " withString:@"+"] stringByReplacingOccurrencesOfString:@"Ö" withString:@"o" options:NSCaseInsensitiveSearch range:stringRange] stringByReplacingOccurrencesOfString:@"Ä" withString:@"a" options:NSCaseInsensitiveSearch range:stringRange] stringByReplacingOccurrencesOfString:@"Ü" withString:@"ü" options:NSCaseInsensitiveSearch range:stringRange] stringByReplacingOccurrencesOfString:@"&" withString:@"%26"] stringByTrimmingCharactersInSet:characters];
}
-(PageType) typeOfPage: (NSString *) page {
if ([page rangeOfString:@"<title>Songtext-Suche</title>"].location != NSNotFound) {
if ([page rangeOfString:@"<div class='empty_collection'>"].location != NSNotFound) {
@@ -87,10 +97,10 @@ typedef enum {
int artistEnd = artistEndTag.location;
int songNameStart = NSMaxRange(artistEndTag);
int songNameEnd = headingEnd;
NSString *artist = [page substringWithRange:NSMakeRange(artistStart, artistEnd-artistStart)];
NSString *artist = [self stringByRemovingHTMLTags:[page substringWithRange:NSMakeRange(artistStart, artistEnd-artistStart)]];
NSString *songName = [page substringWithRange:NSMakeRange(songNameStart, songNameEnd-songNameStart)];
//Remove the " Lyric" and the " &ndash; " from the Song name
songName = [[songName substringToIndex:[songName length]-[@" Lyric" length]] substringFromIndex:[@" &ndash; " length]];
songName = [self stringByRemovingHTMLTags:[[songName substringToIndex:[songName length]-[@" Lyric" length]] substringFromIndex:[@" &ndash; " length]]];
NSString *preview = [self lyricsFromPage:page];
return [[SearchResult alloc]initWithName:songName fromArtist:artist preview:preview link:url];
}
@@ -130,7 +140,7 @@ typedef enum {
NSRange artistStartRange = [tag rangeOfString:@">"];
int artistEndIndex = [tag rangeOfString:@"<" options:NSCaseInsensitiveSearch range:[self restRangeFromString:tag subtractingRange:artistStartRange]].location;
int artistStartIndex = NSMaxRange(artistStartRange);
NSString *artist = [tag substringWithRange:NSMakeRange(artistStartIndex, artistEndIndex-artistStartIndex)];
NSString *artist = [self stringByRemovingHTMLTags:[tag substringWithRange:NSMakeRange(artistStartIndex, artistEndIndex-artistStartIndex)]];
NSRange restRange = [self restRangeFromString:tag subtractingRange:NSMakeRange(artistEndIndex, [@"</a>" length])];
NSRange songNameTagStartRange = [tag rangeOfString:@"<a href=\"" options:NSCaseInsensitiveSearch range:restRange];
@@ -139,7 +149,7 @@ typedef enum {
NSURL *link = [self urlFromHref:[tag substringWithRange:NSMakeRange(linkStart, linkEndRage.location-linkStart)]];
int songNameStart = NSMaxRange([tag rangeOfString:@">" options:NSCaseInsensitiveSearch range:[self restRangeFromString:tag subtractingRange:songNameTagStartRange]]);
int songNameEnd = [tag rangeOfString:@"</a>" options:NSCaseInsensitiveSearch range:[self restRangeFromString:tag subtractingRange:songNameTagStartRange]].location;
NSString *songName = [tag substringWithRange:NSMakeRange(songNameStart, songNameEnd-songNameStart)];
NSString *songName = [self stringByRemovingHTMLTags:[tag substringWithRange:NSMakeRange(songNameStart, songNameEnd-songNameStart)]];
int previewStart = songNameEnd + [@"</a>" length] + [@"\n<p>" length];
NSRange previewRestRange = NSMakeRange(previewStart, [tag length]-previewStart);
int previewEnd = [tag rangeOfString:@"</p>" options:NSCaseInsensitiveSearch range:previewRestRange].location;
@@ -156,7 +166,7 @@ typedef enum {
}
-(NSString*) stringByRemovingHTMLTags: (NSString *)string {
return [[[[[[[[[[string stringByReplacingOccurrencesOfString:@"<strong>" withString:@""] stringByReplacingOccurrencesOfString:@"</strong>" withString:@""] stringByReplacingOccurrencesOfString:@"<b>" withString:@""] stringByReplacingOccurrencesOfString:@"</b>" withString:@""] stringByReplacingOccurrencesOfString:@"<i>" withString:@""] stringByReplacingOccurrencesOfString:@"</i>" withString:@""] stringByReplacingOccurrencesOfString:@"<p>" withString:@""] stringByReplacingOccurrencesOfString:@"</p>" withString:@""] stringByReplacingOccurrencesOfString:@"<br />" withString:@""] stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];
return [[[[[[[[[[[string stringByReplacingOccurrencesOfString:@"<strong>" withString:@""] stringByReplacingOccurrencesOfString:@"</strong>" withString:@""] stringByReplacingOccurrencesOfString:@"<b>" withString:@""] stringByReplacingOccurrencesOfString:@"</b>" withString:@""] stringByReplacingOccurrencesOfString:@"<i>" withString:@""] stringByReplacingOccurrencesOfString:@"</i>" withString:@""] stringByReplacingOccurrencesOfString:@"<p>" withString:@""] stringByReplacingOccurrencesOfString:@"</p>" withString:@""] stringByReplacingOccurrencesOfString:@"<br />" withString:@""] stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""] stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
}
-(NSRange) restRangeFromString: (NSString *) page subtractingRange: (NSRange) aRange {