<?php

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Web\Classes\Search;


class StopWords
{
  private $dbUtil;

  public function __construct(?\Kufer\Web\Classes\Db\DBDirectUtility $pDbUtil = null)
  {
    if ($pDbUtil === null) {
      $this->dbUtil = new \Kufer\Web\Classes\Db\DBDirectUtility();
    } else {
      $this->dbUtil = $pDbUtil;
    }
  }

  
  public function getStopWords()
  {
    
    
    
    
    
    
    $stopwords = $this->readStopWordsFromFile();
    array_walk($stopwords, function(&$item, $key) {
      $item = trim($item);
    });
    
    
    return $stopwords;
  }

  private function readStopWordsFromFile()
  {
    $fileName = \ConstantOperations::getPathForKuferWebResource('stopwords_DE.txt');
    if (file_exists($fileName)) {
      return file($fileName);
    } else {
      return array();
    }
  }

  
  public function writeStopWordsToDb()
  {
    throw new \Exception('noch nicht verfügbar');
    $stopwords = $this->readStopWordsFromFile();
    $this->dbUtil->efficientInsertValuesIntoSingleColumnTable('web_stopwords', 'stopword', $stopwords);
  }
}