Update test program.

This commit is contained in:
Jim 2021-10-01 13:22:59 +01:00
parent b8c3972f54
commit 4df2f55922
1 changed files with 27 additions and 34 deletions

View File

@ -19,55 +19,48 @@ import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import moe.nekojimi.musicsearcher.providers.MetaSearcher;
import moe.nekojimi.musicsearcher.providers.Searcher; import moe.nekojimi.musicsearcher.providers.Searcher;
/** /**
* *
* @author jim * @author jim
*/ */
public class Main public class Main
{ {
private static final Map<String, Searcher> searchers = new HashMap<>(); private static final Map<String, Searcher> searchers = new HashMap<>();
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) throws IOException public static void main(String[] args) throws IOException
{ {
// System.out.println("Hello world!"); // System.out.println("Hello world!");
YamlInput input = Yaml.createYamlInput(new File("searchproviders.yml"));
YamlSequence seq = input.readYamlSequence();
for (int i = 0; i < seq.size(); i++)
{
try
{
YamlMapping map = seq.yamlMapping(i);
String type = map.string("type");
Class<? extends Searcher> clazz = (Class<? extends Searcher>) Class.forName("moe.nekojimi.musicsearcher.providers." + type);
Constructor<? extends Searcher> constructor = clazz.getConstructor(YamlMapping.class);
Searcher searcher = constructor.newInstance(map);
searchers.put(searcher.getName(), searcher);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
System.out.println(searchers); System.out.println(searchers);
String query = "everybodys circulation"; String query = "eminem lose yourself";
for (Searcher searcher: searchers.values())
MetaSearcher metaSearch = MetaSearcher.loadYAML(new File("searchproviders.yml"));
try
{ {
System.out.println("Searching " + searcher.getName() + " for " + query); List<Result> results = metaSearch.searchAndWait(Query.fullText(query));
try // for (Searcher searcher: searchers.values())
{ // {
List<Result> results = searcher.searchAndWait(Query.fullText(query)); // System.out.println("Searching " + searcher.getName() + " for " + query);
for (Result result: results) // try
{ // {
System.out.println("\t" + result); // List<Result> results = searcher.searchAndWait(Query.fullText(query));
} for (Result result : results)
} catch (InterruptedException | ExecutionException ex) { System.out.println("\t" + result);
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); // } catch (InterruptedException | ExecutionException ex) {
} // Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
} catch (ExecutionException | InterruptedException ex)
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} }