aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-10-13 20:32:25 -0400
committerGitHub <noreply@github.com>2017-10-13 20:32:25 -0400
commit62b628b2d0fb8d0c76592bcd5347e5bcec6106c4 (patch)
treeeb43713ea751d9302bd7fd1b6a0610c2bb45c7fc /app/src/main/kotlin/com
parent4ad2d23ceccc23f8b11b0a5e712a1f08722611df (diff)
downloadfrost-62b628b2d0fb8d0c76592bcd5347e5bcec6106c4.tar.gz
frost-62b628b2d0fb8d0c76592bcd5347e5bcec6106c4.tar.bz2
frost-62b628b2d0fb8d0c76592bcd5347e5bcec6106c4.zip
Improve search parse (#401)
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt15
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt8
2 files changed, 13 insertions, 10 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt
index 0d542a80..37c09299 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt
@@ -47,23 +47,18 @@ private class SearchParserImpl : FrostParserBase<List<FrostSearch>>() {
val container: Element = doc.getElementById("BrowseResultsContainer")
?: doc.getElementById("root")
?: return null
- val hrefSet = mutableSetOf<String>()
/**
- * When mapping items, some links are duplicated because they are nested below a main one
- * We will filter out search items whose links are already in the list
*
* Removed [data-store*=result_id]
*/
return container.select("a.touchable.primary[href]").filter(Element::hasText).mapNotNull {
- val item = FrostSearch(it.attr("href").formattedFbUrlCss,
- it.select("._uok").first()?.text() ?: it.text(),
- it.select("._1tcc").first()?.text())
- if (hrefSet.contains(item.href)) return@mapNotNull null
- hrefSet.add(item.href)
- item
- }
+ FrostSearch(it.attr("href").formattedFbUrlCss,
+ it.select(".title").first()?.text() ?: "",
+ it.select(".subtitle").first()?.ownText())
+ }.filter { it.title.isNotBlank() }
}
+
override fun textToDoc(text: String): Document? = Jsoup.parse(text)
override fun debugImpl(data: List<FrostSearch>, result: MutableList<String>) {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 112269c1..6d6c5381 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -32,6 +32,7 @@ import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.*
import com.pitchedapps.frost.utils.iab.IS_FROST_PRO
import org.jsoup.Jsoup
+import org.jsoup.nodes.Element
import java.io.IOException
import java.util.*
@@ -223,3 +224,10 @@ fun frostJsoup(url: String)
fun frostJsoup(cookie: String?, url: String)
= Jsoup.connect(url).cookie(FACEBOOK_COM, cookie).userAgent(USER_AGENT_BASIC).get()!!
+fun Element.first(vararg select: String): Element? {
+ select.forEach {
+ val e = select(it)
+ if (e.size > 0) return e.first()
+ }
+ return null
+} \ No newline at end of file