<commit_before>/*
 * Copyright (c) 2019 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package jp.toastkid.article_viewer.article.list

import androidx.annotation.UiThread
import jp.toastkid.article_viewer.R
import jp.toastkid.article_viewer.article.ArticleRepository
import jp.toastkid.article_viewer.tokenizer.NgramTokenizer
import jp.toastkid.lib.preference.PreferenceApplier
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext

/**
 * @author toastkidjp
 */
class ArticleSearchUseCase(
        private val articleRepository: ArticleRepository,
        private val viewModel: ArticleListFragmentViewModel?,
        private val adapter: Adapter,
        private val preferencesWrapper: PreferenceApplier
) {

    private val tokenizer = NgramTokenizer()

    /**
     * [CompositeDisposable].
     */
    private val disposables = Job()

    fun search(keyword: String?) {
        if (keyword.isNullOrBlank()) {
            return
        }

        /*CoroutineScope(Dispatchers.Main).launch(disposables) {
            val results = withContext(Dispatchers.IO) {
                articleRepository.search("${tokenizer(keyword, 2)}")
            }
            applyArticle(results)
        }*/
        adapter.search("${tokenizer(keyword, 2)}")
    }

    fun filter(keyword: String?) {
        if (!preferencesWrapper.useTitleFilter()) {
            return
        }
<commit_msg>refactor #606 Remove unused comment out.<commit_after>/*
 * Copyright (c) 2019 toastkidjp.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package jp.toastkid.article_viewer.article.list

import androidx.annotation.UiThread
import jp.toastkid.article_viewer.R
import jp.toastkid.article_viewer.article.ArticleRepository
import jp.toastkid.article_viewer.tokenizer.NgramTokenizer
import jp.toastkid.lib.preference.PreferenceApplier
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext

/**
 * @author toastkidjp
 */
class ArticleSearchUseCase(
        private val articleRepository: ArticleRepository,
        private val viewModel: ArticleListFragmentViewModel?,
        private val adapter: Adapter,
        private val preferencesWrapper: PreferenceApplier
) {

    private val tokenizer = NgramTokenizer()

    /**
     * [CompositeDisposable].
     */
    private val disposables = Job()

    fun search(keyword: String?) {
        if (keyword.isNullOrBlank()) {
            return
        }

        adapter.search("${tokenizer(keyword, 2)}")
    }

    fun filter(keyword: String?) {
        if (!preferencesWrapper.useTitleFilter()) {
            return
        }

{'fraction_non_alphanumeric': 0.09073420968259058, 'fraction_numerical': 0.007053542802180186, 'mean_word_length': 3.2916093535075652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5632467', 'n_tokens_mistral': 925, 'n_tokens_neox': 873, 'n_words': 210}