change search syntax
authorNiki Roo <niki@nikiroo.be>
Sat, 13 Apr 2019 11:32:18 +0000 (13:32 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 13 Apr 2019 11:32:18 +0000 (13:32 +0200)
README-fr.md
README.md
src/be/nikiroo/fanfix/Main.java
src/be/nikiroo/fanfix/bundles/resources_core.properties
src/be/nikiroo/fanfix/bundles/resources_core_fr.properties
src/be/nikiroo/fanfix/reader/Reader.java
src/be/nikiroo/fanfix/reader/cli/CliReader.java
src/be/nikiroo/fanfix/reader/tui/TuiReaderApplication.java

index cb76040b15f8c20c58677486cb288407c1673811..1021769f48cbf0c8e3c16e9f82d4842b42472bf2 100644 (file)
@@ -10,6 +10,10 @@ Fanfix est un petit programme Java qui peut télécharger des histoires sur inte
 - ```fanfix``` --convert [*URL*] [*output_type*] [*target*] (+info)
 - ```fanfix``` --read [*id*] ([*chapter number*])
 - ```fanfix``` --read-url [*URL*] ([*chapter number*])
+- ```fanfix``` --search
+- ```fanfix``` --search [*where*] [*keywords*] (page [*page*]) (item [*item*])
+- ```fanfix``` --tag
+- ```fanfix``` --tag [*index 1*]... (page [*page*]) (item [*item*])
 - ```fanfix``` --list
 - ```fanfix``` --set-reader [*GUI* | *TUI* | *CLI*]
 - ```fanfix``` --server [*key*] [*port*]
@@ -85,6 +89,10 @@ Les arguments suivants sont aussi supportés :
 - ```--convert [URL] [output_type] [target] (+info)```: convertir l'histoire vers le fichier donné, et forcer l'ajout d'un fichier .info si +info est utilisé
 - ```--read [id] ([chapter number])```: afficher l'histoire "id"
 - ```--read-url [URL] ([chapter number])```: convertir l'histoire et la lire à la volée, sans la sauver
+- ```--search```: liste les sites supportés (```where```)
+- ```--search [where] [keywords] (page [page]) (item [item])```: lance une recherche et affiche les résultats de la page ```page``` (page 1 par défaut), et de l'item ```item``` spécifique si demandé
+- ```--tag [where]```: liste tous les tags supportés par ce site web
+- ```--tag [index 1]... (page [page]) (item [item])```: affine la recherche, tag par tag, et affiche si besoin les sous-tags, les histoires ou les infos précises de l'histoire demandée
 - ```--list```: lister les histoires presentes dans la librairie et leurs IDs
 - ```--set-reader [reader type]```: changer le type de lecteur pour la commande en cours sur CLI, TUI ou GUI
 - ```--server [key] [port]```: démarrer un serveur d'histoires sur ce port
index 22e0b60f40342ab5f2b472c4df324ad6a550aa20..bc003c73634e203d234cf8c5aba4e6daf7699c6b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -10,6 +10,10 @@ Fanfix is a small Java program that can download stories from some supported web
 - ```fanfix``` --convert [*URL*] [*output_type*] [*target*] (+info)
 - ```fanfix``` --read [*id*] ([*chapter number*])
 - ```fanfix``` --read-url [*URL*] ([*chapter number*])
+- ```fanfix``` --search
+- ```fanfix``` --search [*where*] [*keywords*] (page [*page*]) (item [*item*])
+- ```fanfix``` --tag
+- ```fanfix``` --tag [*index 1*]... (page [*page*]) (item [*item*])
 - ```fanfix``` --list
 - ```fanfix``` --set-reader [*GUI* | *TUI* | *CLI*]
 - ```fanfix``` --server [*key*] [*port*]
@@ -85,6 +89,10 @@ The following arguments are also allowed:
 - ```--convert [URL] [output_type] [target] (+info)```: convert the story at URL into target, and force-add the .info and cover if +info is passed
 - ```--read [id] ([chapter number])```: read the given story denoted by ID from the library
 - ```--read-url [URL] ([chapter number])```: convert on the fly and read the story at URL, without saving it
+- ```--search```: list the supported websites (```where```)
+- ```--search [where] [keywords] (page [page]) (item [item])```: search on the supported website and display the given results page of stories it found, or the story details if asked
+- ```--tag [where]```: list all the tags supported by this website
+- ```--tag [index 1]... (page [page]) (item [item])```: search for the given stories or subtags, tag by tag, and display information about a specific page of results or about a specific item if requested
 - ```--list```: list the stories present in the library and their associated IDs
 - ```--set-reader [reader type]```: set the reader type to CLI, TUI or GUI for this command
 - ```--server [key] [port]```: start a story server on this port
index d5a5debe253fb4a6d570c9791d1e5fbdda57d917..6fc49c549764cbba0a7439086c49e79e981af3ad 100644 (file)
@@ -35,7 +35,7 @@ import be.nikiroo.utils.serial.server.ServerObject;
  */
 public class Main {
        private enum MainAction {
-               IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, STOP_SERVER, REMOTE, SET_SOURCE, SET_TITLE, SET_AUTHOR, SEARCH, SEARCH_TAG
+               IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, STOP_SERVER, REMOTE, SET_SOURCE, SET_TITLE, SET_AUTHOR, SEARCH, TAG
        }
 
        /**
@@ -61,11 +61,14 @@ public class Main {
         * </li>
         * <li>--read-url [URL] ([chapter number]): convert on the fly and read the
         * story, without saving it</li>
-        * <li>--search WEBSITE [free text] ([page] ([item])): search for the given terms, 
-        * show the given page (page 0 means "how many page do we have", starts at page 1)</li>
-        * <li>--search-tag WEBSITE ([tag 1] [tag2...] ([page] ([item]))): list the known 
-        * tags or search the stories for the given tag(s), show the given page of results
-        * (page 0 means "how many page do we have", starts at page 1)</li>
+        * <li>--search: list the supported websites (where)</li>
+        * <li>--search [where] [keywords] (page [page]) (item [item]): search on
+        * the supported website and display the given results page of stories it
+        * found, or the story details if asked</li>
+        * <li>--tag [where]: list all the tags supported by this website</li>
+        * <li>--tag [index 1]... (page [page]) (item [item]): search for the given
+        * stories or subtags, tag by tag, and display information about a specific
+        * page of results or about a specific item if requested</li>
         * <li>--list ([type]): list the stories present in the library</li>
         * <li>--set-source [id] [new source]: change the source of the given story</li>
         * <li>--set-title [id] [new title]: change the title of the given story</li>
@@ -97,7 +100,7 @@ public class Main {
                Integer port = null;
                SupportType searchOn = null;
                String search = null;
-               List<String> tags = new ArrayList<String>();
+               List<Integer> tags = new ArrayList<Integer>();
                Integer page = null;
                Integer item = null;
 
@@ -215,13 +218,13 @@ public class Main {
                        case SEARCH:
                                if (searchOn == null) {
                                        searchOn = SupportType.valueOfAllOkUC(args[i]);
-                                       
+
                                        if (searchOn == null) {
                                                Instance.getTraceHandler().error(
                                                                "Website not known: <" + args[i] + ">");
                                                exitCode = 255;
                                        }
-                                       
+
                                        if (BasicSearchable.getSearchable(searchOn) == null) {
                                                Instance.getTraceHandler().error(
                                                                "Website not supported: " + searchOn);
@@ -229,45 +232,82 @@ public class Main {
                                        }
                                } else if (search == null) {
                                        search = args[i];
-                               } else if (page == null) {
+                               } else if (page != null && page == -1) {
                                        try {
                                                page = Integer.parseInt(args[i]);
-                                       } catch (NumberFormatException e) {
-                                               Instance.getTraceHandler().error(
-                                                               new Exception("Incorrect page number: <"
-                                                                               + args[i] + ">", e));
-                                               exitCode = 255;
+                                       } catch (Exception e) {
+                                               page = -2;
                                        }
-                               } else if (item == null) {
+                               } else if (item != null && item == -1) {
                                        try {
                                                item = Integer.parseInt(args[i]);
-                                       } catch (NumberFormatException e) {
-                                               Instance.getTraceHandler().error(
-                                                               new Exception("Incorrect item number: <"
-                                                                               + args[i] + ">", e));
+                                       } catch (Exception e) {
+                                               item = -2;
+                                       }
+                               } else if (page == null || item == null) {
+                                       if (page == null && "page".equals(args[i])) {
+                                               page = -1;
+                                       } else if (item == null && "item".equals(args[i])) {
+                                               item = -1;
+                                       } else {
                                                exitCode = 255;
                                        }
                                } else {
                                        exitCode = 255;
                                }
                                break;
-                       case SEARCH_TAG:
+                       case TAG:
                                if (searchOn == null) {
                                        searchOn = SupportType.valueOfAllOkUC(args[i]);
-                                       
+
                                        if (searchOn == null) {
                                                Instance.getTraceHandler().error(
                                                                "Website not known: <" + args[i] + ">");
                                                exitCode = 255;
                                        }
-                                       
+
                                        if (BasicSearchable.getSearchable(searchOn) == null) {
                                                Instance.getTraceHandler().error(
                                                                "Website not supported: " + searchOn);
                                                exitCode = 255;
                                        }
+                               } else if (page == null && item == null) {
+                                       if ("page".equals(args[i])) {
+                                               page = -1;
+                                       } else if ("item".equals(args[i])) {
+                                               item = -1;
+                                       } else {
+                                               try {
+                                                       int index = Integer.parseInt(args[i]);
+                                                       tags.add(index);
+                                               } catch (NumberFormatException e) {
+                                                       Instance.getTraceHandler().error(
+                                                                       "Invalid tag index: " + args[i]);
+                                                       exitCode = 255;
+                                               }
+                                       }
+                               } else if (page != null && page == -1) {
+                                       try {
+                                               page = Integer.parseInt(args[i]);
+                                       } catch (Exception e) {
+                                               page = -2;
+                                       }
+                               } else if (item != null && item == -1) {
+                                       try {
+                                               item = Integer.parseInt(args[i]);
+                                       } catch (Exception e) {
+                                               item = -2;
+                                       }
+                               } else if (page == null || item == null) {
+                                       if (page == null && "page".equals(args[i])) {
+                                               page = -1;
+                                       } else if (item == null && "item".equals(args[i])) {
+                                               item = -1;
+                                       } else {
+                                               exitCode = 255;
+                                       }
                                } else {
-                                       tags.add(args[i]);
+                                       exitCode = 255;
                                }
                                break;
                        case HELP:
@@ -429,18 +469,20 @@ public class Main {
                                exitCode = read(urlString, chapString, false);
                                break;
                        case SEARCH:
-                               if (searchOn == null || search == null) {
+                               page = page == null ? 1 : page;
+                               if (page < 0) {
+                                       Instance.getTraceHandler().error("Incorrect page number");
                                        exitCode = 255;
                                        break;
                                }
-                               
-                               if (page == null) {
-                                       page = 1;
-                               }
-                               if (item == null) {
-                                       item = 0;
+
+                               item = item == null ? 0 : item;
+                               if (item < 0) {
+                                       Instance.getTraceHandler().error("Incorrect item number");
+                                       exitCode = 255;
+                                       break;
                                }
-                               
+
                                if (BasicReader.getReader() == null) {
                                        Instance.getTraceHandler()
                                                        .error(new Exception(
@@ -448,38 +490,44 @@ public class Main {
                                        exitCode = 10;
                                        break;
                                }
-                               
-                               try {
-                                       BasicReader.getReader().search(searchOn, search, page, item);
-                               } catch (IOException e1) {
-                                       Instance.getTraceHandler().error(e1);
+
+                               if (searchOn == null || search == null) {
+                                       // TODO: do on reader!!!
+                                       for (SupportType type : SupportType.values()) {
+                                               if (BasicSearchable.getSearchable(type) != null) {
+                                                       System.out.println(type);
+                                               }
+                                       }
+                               } else {
+                                       try {
+                                               BasicReader.getReader().search(searchOn, search, page,
+                                                               item);
+                                       } catch (IOException e1) {
+                                               Instance.getTraceHandler().error(e1);
+                                       }
                                }
-                               
+
                                break;
-                       case SEARCH_TAG:
+                       case TAG:
                                if (searchOn == null) {
                                        exitCode = 255;
                                        break;
                                }
-                               
-                               item = 0;
-                               page = 1;
 
-                               try {
-                                       page = Integer.parseInt(tags.get(tags.size()-1));
-                                       tags.remove(tags.size() - 1);
-                                       
-                                       try {
-                                               int tmp = Integer.parseInt(tags.get(tags.size()-1));
-                                               tags.remove(tags.size() - 1);
-                                               
-                                               item = page;
-                                               page = tmp;
-                                       } catch (Exception e) {
-                                       }
-                               } catch (Exception e) {
+                               page = page == null ? 1 : page;
+                               if (page < 0) {
+                                       Instance.getTraceHandler().error("Incorrect page number");
+                                       exitCode = 255;
+                                       break;
                                }
-                               
+
+                               item = item == null ? 0 : item;
+                               if (item < 0) {
+                                       Instance.getTraceHandler().error("Incorrect item number");
+                                       exitCode = 255;
+                                       break;
+                               }
+
                                if (BasicReader.getReader() == null) {
                                        Instance.getTraceHandler()
                                                        .error(new Exception(
@@ -487,13 +535,14 @@ public class Main {
                                        exitCode = 10;
                                        break;
                                }
-                               
+
                                try {
-                                       BasicReader.getReader().searchTag(searchOn, page, item, tags.toArray(new String[]{}));
+                                       BasicReader.getReader().searchTag(searchOn, page, item,
+                                                       tags.toArray(new Integer[] {}));
                                } catch (IOException e1) {
                                        Instance.getTraceHandler().error(e1);
                                }
-                               
+
                                break;
                        case HELP:
                                syntax(true);
index 6a08973286267c44d6a6db68b817c53aa631feb7..e244122258e1dc656404e29c35a48603d09c648b 100644 (file)
@@ -20,7 +20,14 @@ HELP_SYNTAX = Valid options:\n\
 \t\tgiven page (page 0 means "how many page do we have", starts at page 1)\n\
 \t--search-tag WEBSITE ([tag 1] [tag2...] ([page] ([item]))): list the known tags or \n\
 \t\tsearch the stories for the given tag(s), show the given page of results\n\
-\t\t(page 0 means "how many page do we have", starts at page 1)\n\
+\t--search: list the supported websites (where)\n\
+\t--search [where] [keywords] (page [page]) (item [item]): search on the supported \n\
+\t\twebsite and display the given results page of stories it found, or the story \n\
+\t\tdetails if asked\n\
+\t--tag [where]: list all the tags supported by this website\n\
+\t--tag [index 1]... (page [page]) (item [item]): search for the given stories or \n\
+\t\tsubtags, tag by tag, and display information about a specific page of results or \n\
+\t\tabout a specific item if requested\n\
 \t--list ([type]) : list the stories present in the library\n\
 \t--set-source [id] [new source]: change the source of the given story\n\
 \t--set-title [id] [new title]: change the title of the given story\n\
index 149391e7320648574c2ce77847df1481fba242ee..71c0411b26b7b62e7c571839eb71b20a17703d31 100644 (file)
@@ -15,11 +15,14 @@ HELP_SYNTAX = Options reconnues :\n\
 \t--convert [URL] [output_type] [target] (+info): convertir l'histoire vers le fichier donné, et forcer l'ajout d'un fichier .info si +info est utilisé\n\
 \t--read [id] ([chapter number]): afficher l'histoire "id"\n\
 \t--read-url [URL] ([chapter number]): convertir l'histoire et la lire à la volée, sans la sauver\n\
-\t--search WEBSITE [texte libre] ([page] ([item])): cherche des histoires, affiche la\n\
-\t\tpage de résultats demandée (la page 0 affiche le nombre de pages, la première page est la page 1)\n\
-\t--search-tag WEBSITE ([tag 1] [tag2...] ([page] ([item]))): list the known tags or \n\
-\t\tcherche des histoires avec le/les tag(s) demandé(s), affiche la page de résultats demandée\n\
-\t\t(la page 0 affiche le nombre de pages, la première page est la page 1)\n\
+\t--search: liste les sites supportés (where)\n\
+\t--search [where] [keywords] (page [page]) (item [item]): lance une recherche et \n\
+\t\taffiche les résultats de la page page (page 1 par défaut), et de l'item item \n\
+\t\tspécifique si demandé\n\
+\t--tag [where]: liste tous les tags supportés par ce site web\n\
+\t--tag [index 1]... (page [page]) (item [item]): affine la recherche, tag par tag,\n\
+\t\tet affiche si besoin les sous-tags, les histoires ou les infos précises de \n\
+\t\tl'histoire demandée\n\
 \t--list ([type]): lister les histoires presentes dans la librairie et leurs IDs\n\
 \t--set-source [id] [nouvelle source]: change la source de l'histoire\n\
 \t--set-title [id] [nouveau titre]: change le titre de l'histoire\n\
index 59ed024f42380a8a50f2b3e5fa199146d9092459..fa170e44fcc64a3233ec2c09cba93fb31e84cb07 100644 (file)
@@ -208,19 +208,19 @@ public interface Reader {
         *            the website to search on
         * @param page
         *            the page of results to show (0 = request the maximum number of
-        *            pages, pages start at 1)
+        *            pages, pages <b>start at 1</b>)
         * @param item
         *            the item to select (0 = do not select a specific item but show
-        *            all the page, items start at 1)
+        *            all the page, items <b>start at 1</b>)
         * @param tags
-        *            the tags display names to search for (this is a tag
+        *            the tags indices to search for (this is a tag
         *            <b>hierarchy</b>, <b>NOT</b> a multiple tags choice)
         * 
         * @throws IOException
         *             in case of I/O error
         */
        public void searchTag(SupportType searchOn, int page, int item,
-                       String... tags) throws IOException;
+                       Integer... tags) throws IOException;
 
        /**
         * Open the {@link Story} with an external reader (the program should be
index 03cb22738b37b1f25cb4ff9c5c73d2d4bcb5ff82..6d9841830982533247e20dfcc8c5f2b9461a61af 100644 (file)
@@ -109,23 +109,26 @@ class CliReader extends BasicReader {
 
        @Override
        public void searchTag(SupportType searchOn, int page, int item,
-                       String... tags) throws IOException {
+                       Integer... tags) throws IOException {
                BasicSearchable search = BasicSearchable.getSearchable(searchOn);
                List<SearchableTag> stags = search.getTags();
+               String fqnTag = "";
 
                SearchableTag stag = null;
-               for (String tag : tags) {
-                       stag = null;
-                       for (int i = 0; i < stags.size(); i++) {
-                               if (stags.get(i).getName().equalsIgnoreCase(tag)) {
-                                       stag = stags.get(i);
-                                       break;
-                               }
+               for (Integer tagIndex : tags) {
+                       // ! 1-based index !
+                       if (tagIndex == null || tagIndex <= 0 | tagIndex > stags.size()) {
+                               throw new IOException("Index out of bounds: " + tagIndex);
                        }
 
+                       stag = stags.get(tagIndex - 1);
                        if (stag != null) {
                                search.fillTag(stag);
                                stags = stag.getChildren();
+                               if (!fqnTag.isEmpty()) {
+                                       fqnTag += " / ";
+                               }
+                               fqnTag += stag.getName();
                        } else {
                                stags = new ArrayList<SearchableTag>();
                                break;
@@ -171,34 +174,12 @@ class CliReader extends BasicReader {
                                                } else {
                                                        SearchableTag subtag = subtags.get(item - 1);
 
-                                                       String sp = "";
-                                                       if (subtag.getParent() != null) {
-                                                               List<String> parents = new ArrayList<String>();
-                                                               for (SearchableTag parent = subtag.getParent(); parent != null; parent = parent
-                                                                               .getParent()) {
-                                                                       parents.add(parent.getName());
-                                                               }
-                                                               for (String parent : parents) {
-                                                                       if (!sp.isEmpty()) {
-                                                                               sp += " / ";
-                                                                       }
-                                                                       sp += parent;
-                                                               }
-                                                       }
-
                                                        // TODO: i18n
                                                        String stories = "stories";
                                                        String num = StringUtils.formatNumber(subtag
                                                                        .getCount());
-                                                       if (sp.isEmpty()) {
-                                                               System.out.println(String.format(
-                                                                               "%d/%d: %s, %s %s", page, item,
-                                                                               subtag.getName(), num, stories));
-                                                       } else {
-                                                               System.out.println(String.format(
-                                                                               "%d/%d: %s (%s), %s %s", page, item,
-                                                                               subtag.getName(), sp, num, stories));
-                                                       }
+                                                       System.out.println(String.format("%s (%s), %s %s",
+                                                                       subtag.getName(), fqnTag, num, stories));
                                                }
                                        } else {
                                                System.out.println("Invalid item: only " + count
@@ -206,13 +187,18 @@ class CliReader extends BasicReader {
                                        }
                                } else {
                                        if (metas != null) {
-                                               int i = 0;
+                                               // TODO i18n
+                                               System.out.println(String.format("Content of %s: ",
+                                                               fqnTag));
+                                               int i = 1;
                                                for (MetaData meta : metas) {
-                                                       System.out
-                                                                       .println((i + 1) + ": " + meta.getTitle());
+                                                       System.out.println(i + ": " + meta.getTitle());
                                                        i++;
                                                }
                                        } else {
+                                               // TODO i18n
+                                               System.out.println(String.format("Subtags of %s: ",
+                                                               fqnTag));
                                                int i = 1;
                                                for (SearchableTag subtag : subtags) {
                                                        String total = "";
@@ -235,8 +221,12 @@ class CliReader extends BasicReader {
                                }
                        }
                } else {
+                       // TODO i18n
+                       System.out.println("Known tags: ");
+                       int i = 1;
                        for (SearchableTag s : stags) {
-                               System.out.println(s.getName());
+                               System.out.println(String.format("%d: %s", i, s.getName()));
+                               i++;
                        }
                }
        }
index 177c12ab867094cbd61292d88314662a569b0ecc..85b1abcfb44f7af7419b757f21865b3f4ed8c3d2 100644 (file)
@@ -125,14 +125,15 @@ class TuiReaderApplication extends TApplication implements Reader {
        public void setChapter(int chapter) {
                reader.setChapter(chapter);
        }
-       
+
        @Override
-       public void search(SupportType searchOn, String keywords, int page, int item) {
-               reader.search(searchOn, keywords, page,item);   
+       public void search(SupportType searchOn, String keywords, int page, int item) throws IOException {
+               reader.search(searchOn, keywords, page, item);
        }
-       
+
        @Override
-       public void searchTag(SupportType searchOn, int page, int item, String... tags) {
+       public void searchTag(SupportType searchOn, int page, int item,
+                       Integer... tags) throws IOException {
                reader.searchTag(searchOn, page, item, tags);
        }