Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:37:57+00:00 2026-06-06T00:37:57+00:00

I’m working on a search function that finds the song where the search matches

  • 0

I’m working on a search function that finds the song where the search matches the artist name and the track name. If this topic interests you and have an ideal method of solving this your input would be greatly appreciated. This is more of a logic question than a programming knowledge question.

Here is my current code.

searchPlaylist: function(a,b){
    var retArr = [];
    if (typeof a === 'string') a = eval(a);
    $.each(b, function(i,v){
        if (typeof v['id'] !== "string" || typeof v['artist'] !== "string" || typeof v['track'] !== "string") return;
        var artist = v['artist'].replace(/[^a-zA-Z 0-9]+/g,'').replace('   ',' ').replace('  ',' ');
        var track = v['track'].replace(/[^a-zA-Z 0-9]+/g,'').replace('   ',' ').replace('  ',' ');
        if (artist.match(a) || track.match(a)) retArr.push(i);
    });
    aC.searchLength = retArr.length;
    return retArr;
}

And here is how I call the function.

doSearch: function(){
    var val = $.trim($("#sB").val().replace(/[^a-zA-Z 0-9]+/g,'').replace('   ',' ').replace('  ',' '));
    if (1 < val.length && val != search) {
        aC.search = val;
        var rlength = aC.searchLength;
        aC.searchResults = aC.searchPlaylist("/" + aC.search + "/i", aC.playlist);
        if (aC.searchLength > 0) $("#sresultcount").text(aC.searchLength);
        if (rlength != aC.searchLength) {
            aC.loadPlaylist($.grep(aC.playlist, function(v,i){
                return $.inArray(i,aC.searchResults) > -1;
            }));
        }           
    } else if (0 == val.length) {
        aC.search = "";
        aC.searchLength = 0;
        $("#sresultcount").empty();
        aC.loadPlaylist(aC.playlist);
    }
}

The aC.searchPlaylist function is passed a RegEx statement for the search and the second argument is the variable of the array where the playlist is stored.

Here is the structure of the playlist array.

aC.playlist = [
    {"id":"bd6ve0ydHVo","artist":"0SM","track":"The Landing feat. Alex G - Original Mix","img":"http://i.ytimg.com/vi/bd6ve0ydHVo/default.jpg","duration":322},
    {"id":"KIijaPllLNI","artist":"2 Chainz","track":"No Lie - Explicit Version","img":"http://i.ytimg.com/vi/KIijaPllLNI/default.jpg","duration":240},
    {"id":"esBlVulbkQQ","artist":"2 LIVE CREW","track":"We Want Some P--sy","img":"http://i.ytimg.com/vi/esBlVulbkQQ/default.jpg","duration":170},
    {"id":"5sc_nQiuDN0","artist":"2 LIVE CREW","track":"Face Down A-- Up","img":"http://i.ytimg.com/vi/5sc_nQiuDN0/default.jpg","duration":115},
    {"id":"42vxicGNumM","artist":"2 LIVE CREW","track":"Me So Horny","img":"http://i.ytimg.com/vi/42vxicGNumM/default.jpg","duration":284},
    {"id":"42boE4fc5X4","artist":"2 LIVE CREW","track":"Hoochie Mama","img":"http://i.ytimg.com/vi/42boE4fc5X4/default.jpg","duration":180},
    {"id":"sNRa1M39RRY","artist":"2Pac","track":"I Ain't Mad At Cha","img":"http://i.ytimg.com/vi/sNRa1M39RRY/default.jpg","duration":233},
    {"id":"2cjv7hEAytU","artist":"2Pac","track":"Me Against The World","img":"http://i.ytimg.com/vi/2cjv7hEAytU/default.jpg","duration":283},
    {"id":"8p9jSRxguAA","artist":"2Pac","track":"Ambitionz Az A Ridah","img":"http://i.ytimg.com/vi/8p9jSRxguAA/default.jpg","duration":276},
    {"id":"W69SSLfRJho","artist":"2Pac","track":"Life Goes On","img":"http://i.ytimg.com/vi/W69SSLfRJho/default.jpg","duration":302},
    {"id":"W6S7dAsIzIU","artist":"2Pac","track":"All Eyez On Me","img":"http://i.ytimg.com/vi/W6S7dAsIzIU/default.jpg","duration":318},
    {"id":"khkx7yXzGhc","artist":"2Pac","track":"2 Of Amerikaz Most Wanted - (Explicit)","img":"http://i.ytimg.com/vi/khkx7yXzGhc/default.jpg","duration":316}
];

Here is what I’m thinking the results should be.

The search term could be one of the following:

live crew – want some
OR
live crew want some

I generally prefer the second option because I remove special characters so the hyphen in the first example would get removed.

As you can tell the dilemma once you split the string up into an array based on spaces how do we search in artist or track name. (I don’t think it’s a good idea to search all available combinations.)

HnS Music Discovery

Thanks in advance. Your opinion will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:37:58+00:00Added an answer on June 6, 2026 at 12:37 am
    searchPlaylist: function(a,b){
        var retArr = [], search = a.split(' ');
        $.each(b, function(i,v){
            if (typeof v['id'] !== "string" || typeof v['artist'] !== "string" || typeof v['track'] !== "string") return;
            var artist = v['artist'].replace(/[^a-zA-Z 0-9]+/g,'').replace('   ',' ').replace('  ',' ');
            var track = v['track'].replace(/[^a-zA-Z 0-9]+/g,'').replace('   ',' ').replace('  ',' ');
            var song = artist + " " + track;
            var rg = new RegExp('^(?=.*?'+search.join(")(?=.*?")+')',"i");
            if (song.match(rg)) retArr.push(i);
        });
        aC.searchLength = retArr.length;
        return retArr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.