Esempio n. 1
0
    void SpellCheckWorker::processSpellingQuery(const std::shared_ptr<SpellCheckItem> &item) {
        const bool neededSuggestions = item->needsSuggestions();
        auto &queryItems = item->getQueries();
        const auto wordAnalysisFlags = item->getWordAnalysisFlags();
        const bool shouldCheckSpelling = Common::HasFlag(wordAnalysisFlags, Common::WordAnalysisFlags::Spelling);
        const bool shouldStemWord = Common::HasFlag(wordAnalysisFlags, Common::WordAnalysisFlags::Stemming);
        bool anyWrong = false;

        if (!neededSuggestions) {
            const size_t size = queryItems.size();
            Q_ASSERT(size > 0);
            for (size_t i = 0; i < size; ++i) {
                auto &queryItem = queryItems.at(i);
                bool isOk = true;

                if (shouldCheckSpelling) {
                    isOk = checkQuerySpelling(queryItem);
                }

                if (shouldStemWord) {
                    stemWord(queryItem);
                }

                anyWrong = anyWrong || !isOk;
            }

            if (shouldStemWord && !item->getIsOnlyOneKeyword()) {
                findSemanticDuplicates(queryItems);
            }

            item->accountResults();
            item->submitSpellCheckResult();
        } else {
            for (auto &queryItem: queryItems) {
                if (!queryItem->m_IsCorrect) {
                    findSuggestions(queryItem->m_Word);
                }
            }
        }

        if (anyWrong) {
            item->requestSuggestions();
            this->submitItem(item);
        }
    }
Esempio n. 2
0
 virtual char * handleWord(char * word) {
   if (word != NULL) {
     return stemWord(word);
   }
   return word;
 }