Skip to main content
Topic: Advanced Search Plugin (Read 5388 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Advanced Search Plugin

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?

Advanced Search Plugin

Reply #1
I can't really answer your question, but maybe the mini SDK for foo_dbsearch can be useful? Hence making it as a foo_dbsearch extension.

Advanced Search Plugin

Reply #2
Quote
I can't really answer your question, but maybe the mini SDK for foo_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.

Advanced Search Plugin

Reply #3
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.

Advanced Search Plugin

Reply #4
just a hint:

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

A riddle is a short sword attached to the next 2000 years.

Advanced Search Plugin

Reply #5
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]

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...

Advanced Search Plugin

Reply #6
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]

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.

Advanced Search Plugin

Reply #7
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)

Advanced Search Plugin

Reply #8
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

Advanced Search Plugin

Reply #9
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
[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.

Advanced Search Plugin

Reply #10
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? :/
~

Advanced Search Plugin

Reply #11
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.

Advanced Search Plugin

Reply #12
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]


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?

Advanced Search Plugin

Reply #13
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

 
SimplePortal 1.0.0 RC1 © 2008-2019