HydrogenAudio

Hosted Forums => foobar2000 => Development - (fb2k) => Topic started by: sailorh on 2004-12-16 12:15:06

Title: Advanced Search Plugin
Post by: sailorh on 2004-12-16 12:15:06
I would like to write a plugin that builds on the functionality of the Playlist Search. In particular I want to add this feature:

The user can generate a custom list of "shorthands" for keywords. Then, when the user types in one of those "shorthands" it would perform a search not only for the shorthand by also for the keyword associated with it. Let me give some examples:

You type "ELO" and the Playlist Search also finds results for "Electric Light Orchestra"
You type "CCR" and the Playlist Search also finds results for "Credence Clearwater Revival"

This is convient for abbreviations, but even more convient for foreign words. For example I could type: "Ulfuls" and get "ウルフルズ" (the Japanese equivilant) or "utada hikaru" and get "宇多田ヒカル゛.

So my question is, with the current API would it be possible to implement something like this?
Title: Advanced Search Plugin
Post by: upNorth on 2004-12-16 12:33:57
I can't really answer your question, but maybe the mini SDK for foo_dbsearch (http://www.stud.uni-karlsruhe.de/~uzbs/fb2k/html/#dbsearch) can be useful? Hence making it as a foo_dbsearch extension.
Title: Advanced Search Plugin
Post by: sailorh on 2004-12-17 22:36:34
Quote
I can't really answer your question, but maybe the mini SDK for foo_dbsearch (http://www.stud.uni-karlsruhe.de/~uzbs/fb2k/html/#dbsearch) can be useful? Hence making it as a foo_dbsearch extension.
[a href="index.php?act=findpost&pid=260049"][{POST_SNAPBACK}][/a]


I appreciate the help, but I am kind of lost on this. Is there any documentation for this mini SDK? There are almost no comments to explain stuff. What is the filter_helper? Are all these test_item functions called by Foobar when various searches are performed?

This is my first try at a foobar plugin, so I am pretty confused.

I see an example of Extended Search plugin in the Full SDK. This is kind of what I was thinking, but it would be nice if I could just build onto the deafult search system instead of reimplementing the standard search features.
Title: Advanced Search Plugin
Post by: rexy on 2004-12-17 22:47:45
Well, I'm not really familiar with the extended search plug in or any search plug in, but if it's open source, then it ought to be pretty simple. All you got to do is add a list of conifg variables that would represent the list of aliases (open source plugin foo_albumlist has an easy to copy implementation of a list of config variables with a list control that manipulates it in the preferences window) and then just use the data to replace the aliases with what they represent just after the plug in retreives the data from the search box and voi la.
Title: Advanced Search Plugin
Post by: ssamadhi97 on 2004-12-18 01:57:36
just a hint:

make a new dbsearch preset called "Abbreviation" (or "Abbr." ), set the format to "$abbr(%artist%)" and there you go.

Title: Advanced Search Plugin
Post by: Phi on 2004-12-18 02:13:47
Quote
Is there any documentation for this mini SDK? There are almost no comments to explain stuff. What is the filter_helper? Are all these test_item functions called by Foobar when various searches are performed?
[{POST_SNAPBACK}][/a] (http://index.php?act=findpost&pid=260416")

Since this is your first plugin, make sure you check out the [a href="http://www.hydrogenaudio.org/forums/index.php?showtopic=18138&view=findpost&p=178456]plugin development tutorial[/url] if you haven't already.

If you run the database search plugin in foobar and look at the last dropdown box on the bottom right, you'll notice these are all filters defined in filter_helper.cpp. So using filter_helper you can include your own filter in this box. Look at the code for the filter_match_exact class for an example of how to create your own filter. What you need to do (provided you inherit from the filter_match_string_base class) is override the test_item method. Here's a template to help you out:
Code: [Select]
class filter_match_blah : public dbsearch::filter_match_string_base
{
public:
  virtual const char * get_name() {return "match blah";}
  virtual bool test_item(unsigned n);
};

// called by dbsearch for each item to be tested, you return true to indicate a match
// (i.e., the current item should be displayed in the dbsearch window)
bool filter_match_blah::test_item(unsigned n)
{
  if (pattern.is_empty()) return false;
  string8 temp;
  the_snapshot->format_title(n, temp, spec, 0);
  if (temp.is_empty()) return false;

  // decision code goes here
  // do whatever you need to do to compare pattern (the string typed in the pattern box in dbsearch) to temp (the next item to be compared)

  if (the_current_item_matches)
     return true;
  else
     return false;
}

static primary_filter_factory<filter_match_blah> sailors_filter;


The last line is important, as it "registers" your new class with foobar (your code won't be executed without it). I hope this helps. I haven't compiled anything like this myself, so I may have messed something up...
Title: Advanced Search Plugin
Post by: sailorh on 2004-12-19 21:50:58
Quote
Quote
Is there any documentation for this mini SDK? There are almost no comments to explain stuff. What is the filter_helper? Are all these test_item functions called by Foobar when various searches are performed?
[{POST_SNAPBACK}][/a] (http://index.php?act=findpost&pid=260416")

Since this is your first plugin, make sure you check out the [a href="http://www.hydrogenaudio.org/forums/index.php?showtopic=18138&view=findpost&p=178456]plugin development tutorial[/url] if you haven't already.

If you run the database search plugin in foobar and look at the last dropdown box on the bottom right, you'll notice these are all filters defined in filter_helper.cpp. So using filter_helper you can include your own filter in this box. Look at the code for the filter_match_exact class for an example of how to create your own filter. What you need to do (provided you inherit from the filter_match_string_base class) is override the test_item method. Here's a template to help you out:
Code: [Select]
class filter_match_blah : public dbsearch::filter_match_string_base
{
public:
  virtual const char * get_name() {return "match blah";}
  virtual bool test_item(unsigned n);
};

// called by dbsearch for each item to be tested, you return true to indicate a match
// (i.e., the current item should be displayed in the dbsearch window)
bool filter_match_blah::test_item(unsigned n)
{
  if (pattern.is_empty()) return false;
  string8 temp;
  the_snapshot->format_title(n, temp, spec, 0);
  if (temp.is_empty()) return false;

  // decision code goes here
  // do whatever you need to do to compare pattern (the string typed in the pattern box in dbsearch) to temp (the next item to be compared)

  if (the_current_item_matches)
     return true;
  else
     return false;
}

static primary_filter_factory<filter_match_blah> sailors_filter;


The last line is important, as it "registers" your new class with foobar (your code won't be executed without it). I hope this helps. I haven't compiled anything like this myself, so I may have messed something up...
[a href="index.php?act=findpost&pid=260449"][{POST_SNAPBACK}][/a]


Thanks a lot for your help everyone. It is really great to see a community that is so helpful for a change. I'll let you know how it goes.
Title: Advanced Search Plugin
Post by: sailorh on 2004-12-19 22:19:03
I got a build error when compiling. It says "service_base_static" is not defined. I searched the foobar sdk and the foo helpers and couldnt find a definition for that class. However, if I change it to service_base it compiles fine. Is this okay? If not what should I do instead?

(btw the error is on line 30 of domain.h)
Title: Advanced Search Plugin
Post by: foosion on 2004-12-19 22:27:18
Please note that foo_dbsearch_mini_sdk-1.2 is not compatible with the (newer) foo_dbsearch 1.3.0wip. If you're interested, I can upload the files required to compile a filter for foo_dbsearch 1.3.0wip. However, the filter interface (and other parts of the API as well) will still change until the final version of 1.3.0. The benefit of writing a filter for foo_dbsearch is that you wouldn't have to deal with a GUI implementation.

Edit: This version of domain.h and the foo_dbsearch_mini_sdk is older than version 0.8.2 of the foobar2000 SDK. I'd better upload that snapshot of the updated dbsearch_api...

Edit 2: dbsearch-1.3wip-src.zip (http://www.stud.uni-karlsruhe.de/~uzbs/fb2k/foo_dbsearch/dbsearch-1.3wip-src.zip)
Title: Advanced Search Plugin
Post by: sailorh on 2004-12-20 04:08:18
Quote
Please note that foo_dbsearch_mini_sdk-1.2 is not compatible with the (newer) foo_dbsearch 1.3.0wip. If you're interested, I can upload the files required to compile a filter for foo_dbsearch 1.3.0wip. However, the filter interface (and other parts of the API as well) will still change until the final version of 1.3.0. The benefit of writing a filter for foo_dbsearch is that you wouldn't have to deal with a GUI implementation.

Edit: This version of domain.h and the foo_dbsearch_mini_sdk is older than version 0.8.2 of the foobar2000 SDK. I'd better upload that snapshot of the updated dbsearch_api...

Edit 2: dbsearch-1.3wip-src.zip (http://www.stud.uni-karlsruhe.de/~uzbs/fb2k/foo_dbsearch/dbsearch-1.3wip-src.zip)
[a href="index.php?act=findpost&pid=260732"][{POST_SNAPBACK}][/a]


Thanks info and for the updated code.

I went ahead and worked on it and I got a compiling version that works now. I was able to build my own custom filter. (although right now the available abbreviations are hard coded).

However, after getting this far I realized the dbsearch plugin doesn't quite do what I was looking for. I like that the Search Playlist feature automatically selects the results and allows you to jump to an item. The dbsearch plugin doesn't seem to do this since the results are not neccesarilly in a playlist.

I'm not sure what I'll do from here. Maybe I will try writing my own search plugin based on the Extended Search example.
Title: Advanced Search Plugin
Post by: lav-chan on 2004-12-20 04:29:25
Maybe i just don't get what you're trying to do, but why can't this be accomplished by just adding like a KEYWORD tag or something? :/
Title: Advanced Search Plugin
Post by: sailorh on 2004-12-20 07:21:47
Quote
Maybe i just don't get what you're trying to do, but why can't this be accomplished by just adding like a KEYWORD tag or something? :/
[a href="index.php?act=findpost&pid=260777"][{POST_SNAPBACK}][/a]


I actually thought about doing that, but that would mean adding a new tag to all the songs I wanted to make an abbreviation for. I suppose that isn't much work thanks to the awesome mass tagger, but still I would prefer to have it part of the search rather than modifying my files.

ssamadhi97 had a pretty good solution that works well, except that it can't handle foreign language cases. The biggest reason I want to have this feature is to be able to enter roomaji (english) characters and have it come up with songs that contain Japanese names. Since it would be difficult to compare roomaji and Japanese directly (due to kanji) I thought a keyword system was the best solution.
Title: Advanced Search Plugin
Post by: peterla on 2006-03-03 13:57:16
Quote
I got a build error when compiling. It says "service_base_static" is not defined. I searched the foobar sdk and the foo helpers and couldnt find a definition for that class. However, if I change it to service_base it compiles fine. Is this okay? If not what should I do instead?

(btw the error is on line 30 of domain.h)
[{POST_SNAPBACK}][/a] (http://index.php?act=findpost&pid=260731")


I get the same compiling error, when trying to make a new filter.


Quote
Please note that foo_dbsearch_mini_sdk-1.2 is not compatible with the (newer) foo_dbsearch 1.3.0wip. If you're interested, I can upload the files required to compile a filter for foo_dbsearch 1.3.0wip. However, the filter interface (and other parts of the API as well) will still change until the final version of 1.3.0. The benefit of writing a filter for foo_dbsearch is that you wouldn't have to deal with a GUI implementation.

Edit: This version of domain.h and the foo_dbsearch_mini_sdk is older than version 0.8.2 of the foobar2000 SDK. I'd better upload that snapshot of the updated dbsearch_api...

Edit 2: [a href="http://www.stud.uni-karlsruhe.de/~uzbs/fb2k/foo_dbsearch/dbsearch-1.3wip-src.zip]dbsearch-1.3wip-src.zip[/url]
[a href="index.php?act=findpost&pid=260732"][{POST_SNAPBACK}][/a]




This version is no longer available on your page. I used version 1.2 from your new page. Is there any newer, working version?
Or is there a way to get it working?
Title: Advanced Search Plugin
Post by: Fifoxtasy on 2006-03-03 15:21:41
Quote
just a hint:

make a new dbsearch preset called "Abbreviation" (or "Abbr." ), set the format to "$abbr(%artist%)" and there you go.

not exactly what you asked for, but it should be pretty useful already
[a href="index.php?act=findpost&pid=260447"][{POST_SNAPBACK}][/a]


GR8!!!! 
thanks