Projekt

Obecné

Profil

« Předchozí | Další » 

Revize fad86102

Přidáno uživatelem Jan Šedivý před téměř 6 roky(ů)

Re #7328 označování hledaných slov ve výsledcích

Zobrazit rozdíly:

app/FrontModule/component/Transliteration/TransliterationSearchResultList.latte
63 63
        </a>
64 64
        <div>
65 65
            <span class="linefound">{$result->line_number}.</span>
66
            <span>{$result->transliteration}</span>
66
            <span>{$result->transliteration|noescape}</span>
67 67
        </div>
68 68

  
69 69
    {/foreach}
app/FrontModule/component/Transliteration/TransliterationSearchResultList.php
10 10
use App\Utils\Form;
11 11
use App\Utils\Paginator;
12 12
use Nette\Application\UI\Control;
13
use Tracy\Debugger;
14 13

  
15 14
class TransliterationSearchResultList extends Control
16 15
{
......
20 19
    /** @var TransliterationRepository */
21 20
    private $transliterationRepository;
22 21

  
23
    /** @var PaginatorControl */
22
    /** @var Paginator */
24 23
    private $paginator;
25 24

  
26 25
    /**
......
66 65
    {
67 66
        $this->template->setFile(__DIR__ . '/TransliterationSearchResultList.latte');
68 67

  
69
        $this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize());
68
        $this->resultRows = $this->transliterationRepository->transliterationsFulltextSearch($this->searchTerms, $this->paginator->getOffset(), $this->paginator->getPageSize())->fetchAll();
70 69
        $this->paginator->setPageCount($this->totalCount);
70
        $this->highlight();
71 71

  
72 72
        $this->template->resultRows = $this->resultRows;
73 73
        $this->template->paginator = $this->paginator;
74 74
        $this->template->render();
75 75
    }
76 76

  
77
    public function highlight()
78
    {
79
        foreach ($this->resultRows as $resultRow)
80
        {
81
            $resultRow->transliteration = str_replace("<", "&lt;", $resultRow->transliteration);
82
            $resultRow->transliteration = str_replace(">", "&gt;", $resultRow->transliteration);
83

  
84
            $resultRow->transliteration = preg_replace(
85
                "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word1']) . "/",
86
                "<span class='found'>$0</span>",
87
                $resultRow->transliteration);
88

  
89
            //TODO: dořešit označování slov, když se zadají slova co se překrývají tak se tagy mezi sebou ruší,
90
            // viz např. vyhledávání slov 'šu' a 'as'
91

  
92
//            if($this->searchTerms['word2_condition'] === ESearchFormOperators::AND || $this->searchTerms['word2_condition'] === ESearchFormOperators::OR )
93
//            {
94
//                $resultRow->transliteration = preg_replace(
95
//                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word2']) . "/",
96
//                    "<span class='found'>$0</span>",
97
//                    $resultRow->transliteration);
98
//            }
99
//
100
//            if($this->searchTerms['word3_condition'] === ESearchFormOperators::AND || $this->searchTerms['word3_condition'] === ESearchFormOperators::OR )
101
//            {
102
//                $resultRow->transliteration = preg_replace(
103
//                    "/" . $this->transliterationRepository->prepareSearchRegExp($this->searchTerms['word3']) . "/",
104
//                    "<span class='found'>$0</span>",
105
//                    $resultRow->transliteration);
106
//            }
107
        }
108
    }
109

  
77 110
    public function handleChangePage($page, $limit)
78 111
    {
79 112
        $this->paginator = new Paginator($page, $limit);
app/model/repository/TransliterationRepository.php
150 150
     * @param $word string hledané slovo
151 151
     * @return string Regexp
152 152
     */
153
    private function prepareSearchRegExp(string $word)
153
    public function prepareSearchRegExp(string $word)
154 154
    {
155 155
        $splitWord = preg_split('//u',$word, -1, PREG_SPLIT_NO_EMPTY);
156 156
        foreach ($splitWord as &$char)

Také k dispozici: Unified diff