X-Git-Url: https://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsearchable%2FBasicSearchable.java;h=cb0b1712ccb3fc7762354f799a04f65b45d89de8;hb=33c5ceb66e2288d7d752407f2c156473b04d94d9;hp=ecc1da1ef3393f2b8144c8a613b56c8343c3a458;hpb=76ec935e19dbd00dfbcaaeabfc187125f727b5ac;p=fanfix.git
diff --git a/src/be/nikiroo/fanfix/searchable/BasicSearchable.java b/src/be/nikiroo/fanfix/searchable/BasicSearchable.java
index ecc1da1..cb0b171 100644
--- a/src/be/nikiroo/fanfix/searchable/BasicSearchable.java
+++ b/src/be/nikiroo/fanfix/searchable/BasicSearchable.java
@@ -34,6 +34,38 @@ public abstract class BasicSearchable {
support = BasicSupport.getSupport(getType(), null);
}
+ /**
+ * Find the given tag by its hierarchical IDs.
+ *
+ * I.E., it will take the tag A, subtag B, subsubtag C...
+ *
+ * @param ids
+ * the IDs to look for
+ *
+ * @return the appropriate tag fully filled, or NULL if not found
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public SearchableTag getTag(Integer... ids) throws IOException {
+ SearchableTag tag = null;
+ List tags = getTags();
+
+ for (Integer tagIndex : ids) {
+ // ! 1-based index !
+ if (tagIndex == null || tags == null || tagIndex <= 0
+ || tagIndex > tags.size()) {
+ return null;
+ }
+
+ tag = tags.get(tagIndex - 1);
+ fillTag(tag);
+ tags = tag.getChildren();
+ }
+
+ return tag;
+ }
+
/**
* The support type.
*
@@ -83,7 +115,35 @@ public abstract class BasicSearchable {
* @throws IOException
* in case of I/O error
*/
- abstract protected void fillTag(SearchableTag tag) throws IOException;
+ abstract public void fillTag(SearchableTag tag) throws IOException;
+
+ /**
+ * Search for the given term and return the number of pages of results of
+ * stories satisfying this search term.
+ *
+ * @param search
+ * the term to search for
+ *
+ * @return a number of pages
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ abstract public int searchPages(String search) throws IOException;
+
+ /**
+ * Search for the given tag and return the number of pages of results of
+ * stories satisfying this tag.
+ *
+ * @param tag
+ * the tag to search for
+ *
+ * @return a number of pages
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ abstract public int searchPages(SearchableTag tag) throws IOException;
/**
* Search for the given term and return a list of stories satisfying this
@@ -96,13 +156,16 @@ public abstract class BasicSearchable {
*
* @param search
* the term to search for
+ * @param page
+ * the page to use for result pagination, index is 1-based
*
* @return a list of stories that satisfy that search term
*
* @throws IOException
* in case of I/O error
*/
- abstract public List search(String search) throws IOException;
+ abstract public List search(String search, int page)
+ throws IOException;
/**
* Search for the given tag and return a list of stories satisfying this
@@ -113,15 +176,20 @@ public abstract class BasicSearchable {
*
* URL is guaranteed to be usable, LUID will always be NULL.
*
- * @param tagId
+ * @param tag
* the tag to search for
+ * @param page
+ * the page to use for result pagination (see
+ * {@link SearchableTag#getPages()}, remember to check for -1),
+ * index is 1-based
*
* @return a list of stories that satisfy that search term
*
* @throws IOException
* in case of I/O error
*/
- abstract public List search(SearchableTag tag) throws IOException;
+ abstract public List search(SearchableTag tag, int page)
+ throws IOException;
/**
* Load a document from its url.
@@ -154,8 +222,7 @@ public abstract class BasicSearchable {
* in case of I/O error
*/
protected Document load(URL url, boolean stable) throws IOException {
- return DataUtil.load(Instance.getCache().open(url, support, stable),
- "UTF-8", url.toString());
+ return DataUtil.load(Instance.getInstance().getCache().open(url, support, stable), "UTF-8", url.toString());
}
/**
@@ -163,41 +230,44 @@ public abstract class BasicSearchable {
* type, or NULL if it does not exist.
*
* @param type
- * the type, must not be NULL
+ * the type, can be NULL (will just return NULL, since we do not
+ * support it)
*
* @return an implementation that supports it, or NULL
*/
- public static BasicSearchable getSearchable(SupportType type) {
+ static public BasicSearchable getSearchable(SupportType type) {
BasicSearchable support = null;
- switch (type) {
- case FIMFICTION:
- // TODO
- break;
- case FANFICTION:
- support = new Fanfiction(type);
- break;
- case MANGAFOX:
- // TODO
- break;
- case E621:
- // TODO
- break;
- case YIFFSTAR:
- // TODO
- break;
- case E_HENTAI:
- // TODO
- break;
- case MANGA_LEL:
- // TODO
- break;
- case CBZ:
- case HTML:
- case INFO_TEXT:
- case TEXT:
- case EPUB:
- break;
+ if (type != null) {
+ switch (type) {
+ case FIMFICTION:
+ // TODO searchable for FIMFICTION
+ break;
+ case FANFICTION:
+ support = new Fanfiction(type);
+ break;
+ case MANGAHUB:
+ // TODO searchable for MANGAHUB
+ break;
+ case E621:
+ // TODO searchable for E621
+ break;
+ case YIFFSTAR:
+ // TODO searchable for YIFFSTAR
+ break;
+ case E_HENTAI:
+ // TODO searchable for E_HENTAI
+ break;
+ case MANGA_LEL:
+ support = new MangaLel();
+ break;
+ case CBZ:
+ case HTML:
+ case INFO_TEXT:
+ case TEXT:
+ case EPUB:
+ break;
+ }
}
return support;