~ubuntu-branches/ubuntu/precise/kde4libs/precise

« back to all changes in this revision

Viewing changes to nepomuk/query/querybuilderdata_p.h

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2011-10-12 13:40:27 UTC
  • Revision ID: package-import@ubuntu.com-20111012134027-rebgte0abxwkqaze
Tags: 4:4.7.2-0ubuntu2
Added kubuntu_nepomuk_unicode.diff to fix nepomuk queries as recommended
by upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "query_p.h"
33
33
#include "groupterm_p.h"
34
34
 
 
35
namespace {
 
36
/// A hack to avoid passing extended chars to the bif:search_excerpts method which cannot handle
 
37
/// utf8 chars which use more than one char, ie. wide chars.
 
38
/// Thus, we simply truncate each term at the first wide char.
 
39
QStringList stripExtendedCharsHack(const QStringList& terms) {
 
40
    QStringList newTerms;
 
41
    foreach(const QString& term, terms) {
 
42
        int i = 0;
 
43
        while(i < term.length()) {
 
44
            if(term[i].unicode() > 0x7f) {
 
45
                break;
 
46
            }
 
47
            ++i;
 
48
        }
 
49
        if(i > 0) {
 
50
            newTerms.append(term.left(i));
 
51
        }
 
52
    }
 
53
    return newTerms;
 
54
}
 
55
}
 
56
 
35
57
namespace Nepomuk {
36
58
    namespace Query {
37
59
        class QueryBuilderData
246
268
                    for( QHash<QString, QStringList>::const_iterator it = m_fullTextSearchTerms.constBegin();
247
269
                         it != m_fullTextSearchTerms.constEnd(); ++it ) {
248
270
                        const QString& varName = it.key();
249
 
                        const QStringList& terms = it.value();
250
 
                        // bif:search_excerpt wants a vector of all search terms
251
 
                        excerptParts
252
 
                                << QString::fromLatin1("bif:search_excerpt(bif:vector(bif:charset_recode('%1', '_WIDE_', 'UTF-8')), %2)")
253
 
                            .arg( terms.join(QLatin1String("','")),
254
 
                                  varName );
 
271
                        const QStringList terms = stripExtendedCharsHack(it.value());
 
272
                        if(terms.count()) {
 
273
                            // bif:search_excerpt wants a vector of all search terms
 
274
                            excerptParts
 
275
                                    << QString::fromLatin1("bif:search_excerpt(bif:vector('%1'), %2)")
 
276
                                       .arg( terms.join(QLatin1String("','")),
 
277
                                             varName );
 
278
                        }
255
279
                    }
256
280
 
257
 
                    return QString::fromLatin1("(bif:concat(%1)) as ?_n_f_t_m_ex_")
258
 
                        .arg(excerptParts.join(QLatin1String(",")));
 
281
                    if(excerptParts.count()) {
 
282
                        return QString::fromLatin1("(bif:concat(%1)) as ?_n_f_t_m_ex_")
 
283
                                .arg(excerptParts.join(QLatin1String(",")));
 
284
                    }
 
285
                    else {
 
286
                        return QString();
 
287
                    }
259
288
                }
260
289
                else {
261
290
                    return QString();