Search for any combination of words or characters using the searchDisplay controller in iOS

Hi I have a main array that populates the table and I have a filtered array for the search results. Both of these functions work using the method below. My table display and search array works well, except for the problem below in this code block.

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope

{

[self.filteredListContent removeAllObjects]; // First clear the filtered array.



for (product *new in parserData)
{

    //Description scope
   if ([scope isEqualToString:@"Description"]) 

    {
        NSRange result = [new.description rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];

        if (result.location != NSNotFound)
        {
            [self.filteredListContent addObject:new];
        }
    }


    //Product scope
    if ([scope isEqualToString:@"Product"])

    {
        NSRange result = [new.item rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];

        if (result.location != NSNotFound)
        {
            [self.filteredListContent addObject:new];
        }
    }
}

}

. LMD-2451 TD Professional 3D LCD Monitor. TD Professional, TD Pro, TD , , . , Pro TD, . , , , ? -, . , .

NSMutableArray * parserData;// NSMutableArray * filterListContent;//

.

+3
1

componentsSeperatedByString:@" " , ( ) 2 , @"Pro" @"TD". rangeOfString:, new.item.

//Product scope
if ([scope isEqualToString:@"Product"])
{
    // Split into search text into separate "words"
    NSArray * searchComponents = [searchText componentsSeparatedByString: @" "];
    BOOL foundSearchText = YES;

    // Check each word to see if it was found
    for (NSString * searchComponent in searchComponents) {
        NSRange result = [new.item rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
        foundSearchText &= (result.location != NSNotFound);
    }

    // If all search words found, add to the array
    if (foundSearchText)
    {
        [self.filteredListContent addObject: new];
    }
}
+2

All Articles