allow pagination for search keywords
[fanfix.git] / src / be / nikiroo / fanfix / searchable / Fanfiction.java
index bcc4759d1390f4f765963136eeb23b890fd07559..90f25eec473ba3657aac8de15224161b2faace11 100644 (file)
@@ -77,7 +77,7 @@ class Fanfiction extends BasicSearchable {
                if (storiesName != null) {
                        SearchableTag tag = new SearchableTag(null, storiesName, false);
                        for (String id : stories.keySet()) {
-                               tag.add(new SearchableTag(id, stories.get(id), true, false));
+                               tag.add(new SearchableTag(id, stories.get(id), false, false));
                        }
                        tags.add(tag);
                }
@@ -94,7 +94,7 @@ class Fanfiction extends BasicSearchable {
        }
 
        @Override
-       protected void fillTag(SearchableTag tag) throws IOException {
+       public void fillTag(SearchableTag tag) throws IOException {
                if (tag.getId() == null || tag.isComplete()) {
                        return;
                }
@@ -126,7 +126,11 @@ class Fanfiction extends BasicSearchable {
                                                                nr = nr.substring(0, nr.length() - 1);
                                                        }
                                                        nr = nr.trim();
-                                                       subtag.setCount(toNumber(nr));
+
+                                                       // TODO: fix toNumber/fromNumber
+                                                       nr = nr.replaceAll("\\.[0-9]*", "");
+
+                                                       subtag.setCount(StringUtils.toNumber(nr));
                                                }
                                        }
                                }
@@ -136,38 +140,11 @@ class Fanfiction extends BasicSearchable {
                tag.setComplete(true);
        }
 
-       /**
-        * @deprecated use {@link StringUtils} when updated
-        */
-       @Deprecated
-       private static long toNumber(String value) {
-               // TODO: use StringUtils instead after update
-               long count = 0l;
-               if (value != null) {
-                       try {
-                               if (value.toLowerCase().endsWith("m")) {
-                                       count = Long.parseLong(value.substring(0,
-                                                       value.length() - 1).trim());
-                                       count *= 1000000;
-                               } else if (value.toLowerCase().endsWith("k")) {
-                                       count = Long.parseLong(value.substring(0,
-                                                       value.length() - 1).trim());
-                                       count *= 1000;
-                               } else {
-                                       count = Long.parseLong(value);
-                               }
-                       } catch (NumberFormatException pe) {
-                       }
-               }
-
-               return count;
-       }
-
        @Override
-       public List<MetaData> search(String search) throws IOException {
+       public List<MetaData> search(String search, int page) throws IOException {
                String encoded = URLEncoder.encode(search.toLowerCase(), "utf-8");
                return getStories(BASE_URL + "search/?ready=1&type=story&keywords="
-                               + encoded, null, null);
+                               + encoded + "&ppage=" + page, null, null);
        }
 
        @Override
@@ -190,7 +167,7 @@ class Fanfiction extends BasicSearchable {
                        Document doc = load(url, false);
 
                        // Update the pages number if needed
-                       if (tag.getPages() < 0) {
+                       if (tag.getPages() < 0 && tag.isLeaf()) {
                                tag.setPages(getPages(doc));
                        }
 
@@ -216,11 +193,8 @@ class Fanfiction extends BasicSearchable {
         *            the document
         * 
         * @return the number of pages or -1 if unknown
-        * 
-        * @throws IOException
-        *             in case of I/O errors
         */
-       private int getPages(Document doc) throws IOException {
+       private int getPages(Document doc) {
                int pages = -1;
 
                if (doc != null) {