logo
down
shadow

How to Filter a search using key words in Swift


How to Filter a search using key words in Swift

By : Stephen Page
Date : October 17 2020, 03:08 PM
wish help you to fix your issue I'm already aware of using categories to filter a search in a swift table, I am looking to filter a search where there may be multiple key words for one particular search.
code :
import UIKit

class Video {

    var videoName: String
    var videoTags: [String]

    init(name: String, tags: [String]) {
        self.videoName = name
        self.videoTags = tags

    }
}

var videos: [Video] = [Video(name: "First Video", tags: ["First", "Advice"]),Video(name: "Second Video", tags: ["Second", "Tutorial"]), Video(name: "Third Video", tags: ["Third", "Tutorial"])]

func filterVideos(tag: String)-> [Video] {
    return videos.filter { (video) -> Bool in
        for _tag in video.videoTags {
            if _tag.lowercased().contains(tag.lowercased()) {
                return true
            }
        }
        return false
    }
}

let filtered = filterVideos(tag: "Tuto") // <= this will contain Second Video And Third Video


Share : facebook icon twitter icon
How to search for only whole words in a Swift String

How to search for only whole words in a Swift String


By : Crescom
Date : March 29 2020, 07:55 AM
With these it helps Update
I thought of a better solution than my previous answer so I updated it. The original answer will follow for anyone that prefers so.
code :
"(?<=[^A-Za-z0-9]|^)[A-Za-z0-9]+(?=[^A-Za-z0-9]|$)"
"(?<=[^A-Za-z]|^)[A-Za-z]+(?=[^A-Za-z]|$)"
"(?<=[^A-Za-z]|^)\(searchString)(?=[^A-Za-z]|$)"
"\\s[a-zA-Z1-9]*\\s"
let regex = try! NSRegularExpression(pattern: "\\s\(searchString)\\s" ,options: .caseInsensitive)    
"(?<=\\s)[A-Za-z0-9]*(?=\\s)"
Search multiple words in one string in swift

Search multiple words in one string in swift


By : Dattaprasad Dhuri
Date : March 29 2020, 07:55 AM
like below fixes the issue I have a long string in swift3 and want to check if it contains word1 and word2. It could also be more than 2 search words. I found out following solution: , If you are looking for less code:
code :
let text = "Hello Swift-world"
let wordList = ["Hello", "world"]

let success = !wordList.contains(where: { !text.contains($0) })
print(success)
Filter search on multiple words, iOS, Swift

Filter search on multiple words, iOS, Swift


By : Jenny Ruddock
Date : March 29 2020, 07:55 AM
To fix this issue Using this you can also achieve a search with inverse order ("Blue Ball" -> "Ball Blue").
code :
let splitText = searchText.split(separator: " ")
let filteredObjects = objects.filter {
    var include = false

    for text in splitText {
        if let s = $0["object"], text.contains(s) {
            include = true
            continue
        }

        if let s = $0["color"], text.contains(s) {
            include = true
            continue
        }

        return false
     }

     return include
}
Live Search Filter with Multiple Words, Use AND instead of OR

Live Search Filter with Multiple Words, Use AND instead of OR


By : user1990830
Date : March 29 2020, 07:55 AM
Does that help I have a live search autocomplete filter that I'm using to weed out a directory of people. Using this search, I want people to be able to search using multiple words, which will further reduce the number of results they get.
code :
rows.filter(function(i, v) {
  var truth = true;

  for (var d = 0; d < data.length; ++d) {
    //remain true so long as all of the filters are found
    //if even one is not found, it will stay false
    truth = truth && $(this).is(":contains('" + data[d] + "')");
  }

  return truth;
})

//OR you could just flip your logic and return false if any of the
//filters are not found

rows.filter(function(i, v) {
  for (var d = 0; d < data.length; ++d) {
    if (!$(this).is(":contains('" + data[d] + "')")) {
      return false;
    }
  }
  
  return true;
})
Filter out common words for search query

Filter out common words for search query


By : user3748490
Date : March 29 2020, 07:55 AM
wish helps you Um, won't Google do this for you? Send all those dirty, filthy words to Google and let them clean them up for you.
Related Posts Related Posts :
  • Swift Navigation bar background color white does not work
  • How properly filterSuccessfulStatusCodes in RxMoya
  • EXIF data read and write
  • Two singletons referencing each other prevent the initialization from ending
  • UTC to local time conversion not working in Swift 2
  • Angle between 2 Lines in 3D
  • Cannot convert value of type URL.Type to expected argument type 'URL'
  • Mismatching types when trying to assign to optional property
  • The type of self in Swift and its use with respect to two-phase initialization
  • Firestore: How to get random documents in a collection
  • Swift Package Manager (SPM): Error importing library
  • ARKit – Ball is not passing through "SCNTorus" hole
  • AVAssetExport fails "cannot decode"
  • Carthage: Multiple build commands for output file framework
  • add last custom collectionViewcell to collectionView swift 3
  • iOS silent push not work when APP in background
  • Set Variable of Launcher View Controller on Task Completion
  • Scroll an NSTextView to bottom after adding text
  • UICollectionView Video Performance
  • Finding The First Non-repeating Character algorithm Swift 4 (Looping over string only once)
  • Playing music in Swift: Unexpectedly found nil while unwrapping an Optional value
  • NSImage Getting Resized when I draw Text on it
  • Firebase Firestore - OR query alternative
  • Misplaced Information on 2 PickerView
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com