Skip to Content
It is currently September 27th, 2022, 11:46 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: November 4th, 2021, 4:43 pm 
Offline
Senior User
Senior User

Joined: January 1st, 2009, 8:50 pm
Posts: 147
Running PHP 7.4x, with samPHPweb code... web/playlist.php


My listeners/requesters have been asking me this for years. They want to type in multiple words to help refine their search through my library. They want the words "Anded" together.

Requester wants to search for the Guess Who, but the results show:
Every track with "the" in the title, artist, album (and not just "the" by itself, also anywhere as part of a larger word)
Plus every track with "guess" in the title, artist, album
Plus every track with "who" in the title, artist, album.

We've tried using common search filters, like " , ' , +, & , but the search returns those characters as yet another word to include in the results.

I saw some really old posts here about this, and came across this one,
viewtopic.php?f=22&t=10975&hilit=multiple+word+search
but it's written for the old /php/ style code. Is there anything like this but for the new code?

Thank you,
Terry


Top
 Profile  
Reply with quote  
PostPosted: November 8th, 2021, 5:50 am 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 8306
Location: Cologne (Germany)
Code:
      if (is_array($search_words)) {
         reset($search_words);
         foreach($search_words as $key => $val)  {
            $val = "%$val%";
            $orWhere[] = $db->quoteInto('(title like ?)', $val) . ' OR ' .
                      $db->quoteInto('(artist like ?)', $val) . ' OR ' .
                      $db->quoteInto('(album like ?)', $val);
         }

         $select_where->where(implode(' OR ', $orWhere));
      }

This is the code responsible for searching.
I think the search_words is an array made by splitting whatever you entered at the space character.
Each word is then searched for in title, artist and album and at the end all of these individual searches are connected by ORing them together.

To change this, you'd need to add another loop in front and find "connected" search_words.
If for example you'd like to have quoted strings, you need to find the first word with a quote and then merge all the following words until you find one that ends in a quote.

For combining multiple search terms using AND / using the + symbol, you'd have to split every search_word that contains the + symbol inside the existing foreach loop and then connect all the letters-/numbers-only search_words using AND ($orWhere[] = implode(' AND ', $splitWordsWithoutPlus);)

If you need more help than an abstract description of how to solve this yourself, feel free to get in touch by PM and we can figure out what it'd cost to have me implement that for you.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

Shop for readymade PAL scripts by countrywesterndj - Or get a custom script made by me (or others)

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: November 11th, 2021, 3:41 pm 
Offline
Senior User
Senior User

Joined: January 1st, 2009, 8:50 pm
Posts: 147
Mastacheata wrote:
Code:
      if (is_array($search_words)) {
         reset($search_words);
         foreach($search_words as $key => $val)  {
            $val = "%$val%";
            $orWhere[] = $db->quoteInto('(title like ?)', $val) . ' OR ' .
                      $db->quoteInto('(artist like ?)', $val) . ' OR ' .
                      $db->quoteInto('(album like ?)', $val);
         }

         $select_where->where(implode(' OR ', $orWhere));
      }

This is the code responsible for searching.
I think the search_words is an array made by splitting whatever you entered at the space character.
Each word is then searched for in title, artist and album and at the end all of these individual searches are connected by ORing them together.

To change this, you'd need to add another loop in front and find "connected" search_words.
If for example you'd like to have quoted strings, you need to find the first word with a quote and then merge all the following words until you find one that ends in a quote.

For combining multiple search terms using AND / using the + symbol, you'd have to split every search_word that contains the + symbol inside the existing foreach loop and then connect all the letters-/numbers-only search_words using AND ($orWhere[] = implode(' AND ', $splitWordsWithoutPlus);)

If you need more help than an abstract description of how to solve this yourself, feel free to get in touch by PM and we can figure out what it'd cost to have me implement that for you.


Thank you. I'm having my team come up with how we want it to work (basically the way SAM does it at the server, and maybe a couple of options), and I'll get back to you for a quote.

Terry


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group