• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • libnepomukcore
  • query
query.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Nepomuk KDE project.
3  Copyright (C) 2008-2012 Sebastian Trueg <trueg@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #include "query.h"
21 #include "query_p.h"
22 #include "term.h"
23 #include "term_p.h"
24 #include "nie.h"
25 #include "nfo.h"
26 #include "querybuilderdata_p.h"
27 #include "literalterm.h"
28 #include "resourceterm.h"
29 #include "andterm.h"
30 #include "orterm.h"
31 #include "negationterm.h"
32 #include "comparisonterm.h"
33 #include "resourcetypeterm.h"
34 #include "resourcetypeterm_p.h"
35 #include "optionalterm.h"
36 #include "queryserializer.h"
37 #include "queryparser.h"
38 #include "util.h"
39 #include "filequery.h"
40 
41 #include <QtCore/QDebug>
42 #include <QtCore/QDateTime>
43 #include <QtCore/QRegExp>
44 #include <QtCore/QVariant>
45 #include <QtCore/QTextStream>
46 
47 #include <Soprano/Node>
48 #include <Soprano/Model>
49 #include <Soprano/QueryResultIterator>
50 #include <Soprano/Vocabulary/RDFS>
51 #include <Soprano/Vocabulary/RDF>
52 #include <Soprano/Vocabulary/NRL>
53 #include <Soprano/Vocabulary/NAO>
54 
55 #include "resourcemanager.h"
56 #include "literal.h"
57 #include "property.h"
58 #include "class.h"
59 
60 #include <kdebug.h>
61 
62 /*
63 ## Full Text Score
64 ## Entity Rank
65 ## Surfaced via SPARQL
66 
67 SELECT ?s ?sc ( <LONG::IRI_RANK> (?s) ) as ?Rank
68 WHERE { ?s ?p ?o .
69 ?o bif:contains 'NEW AND YOR' option (score ?sc). }
70 ORDER BY desc (?
71 */
72 
73 
74 Nepomuk2::Query::Term Nepomuk2::Query::QueryPrivate::createFolderFilter() const
75 {
76  Term mainTerm;
77 
78  if ( !m_includeFolders.isEmpty() ) {
79  QStringList includeFilter;
80  for( QHash<KUrl, bool>::ConstIterator it = m_includeFolders.constBegin();
81  it != m_includeFolders.constEnd(); ++it ) {
82  const QString urlStr = it.key().url(KUrl::AddTrailingSlash);
83  if( it.value() )
84  includeFilter.append( QString::fromLatin1("(^%1)").arg( urlStr ) );
85  else
86  includeFilter.append( QString::fromLatin1("(^%1[^/]*$)").arg( urlStr ) );
87  }
88  mainTerm = mainTerm && ComparisonTerm(
89  Nepomuk2::Vocabulary::NIE::url(),
90  LiteralTerm(includeFilter.join( "|" )),
91  ComparisonTerm::Regexp);
92  }
93 
94  if ( !m_excludeFolders.isEmpty() ) {
95  mainTerm = mainTerm && NegationTerm::negateTerm(
96  ComparisonTerm(
97  Nepomuk2::Vocabulary::NIE::url(),
98  LiteralTerm(QString::fromLatin1("^(%1)").arg( m_excludeFolders.toStringList(KUrl::AddTrailingSlash).join( "|" ) )),
99  ComparisonTerm::Regexp));
100  }
101  return mainTerm;
102 }
103 
104 
105 Nepomuk2::Query::Term Nepomuk2::Query::QueryPrivate::optimizeEvenMore(const Nepomuk2::Query::Term& term) const
106 {
107  using namespace Nepomuk2::Query;
108 
109  //
110  // Merge ResourceTypeTerms which are combined in an OrTerm
111  //
112  if(term.type() == Term::Or) {
113  QList<Term> subTerms = term.toOrTerm().subTerms();
114  QList<ResourceTypeTerm> typeTerms;
115  QList<Term>::iterator it = subTerms.begin();
116  while(it != subTerms.end()) {
117  if(it->type() == Term::ResourceType) {
118  typeTerms << it->toResourceTypeTerm();
119  it = subTerms.erase(it);
120  }
121  else {
122  ++it;
123  }
124  }
125 
126  if(typeTerms.count() > 1) {
127  ResourceTypeTerm newTypeTerm;
128  foreach(const ResourceTypeTerm& rtt, typeTerms) {
129  static_cast<ResourceTypeTermPrivate*>(newTypeTerm.d_ptr.data())->m_types << rtt.type();
130  }
131  subTerms << newTypeTerm;
132  }
133  else if(typeTerms.count() == 1) {
134  subTerms += typeTerms.first();
135  }
136 
137  if(subTerms.count() > 1)
138  return OrTerm(subTerms);
139  else if(subTerms.count() == 1)
140  return subTerms.first();
141  else
142  return OrTerm();
143  }
144 
145  //
146  // For AndTerms we simply need to optimize the subterms
147  //
148  else if(term.type() == Term::And) {
149  AndTerm newAndTerm;
150  //
151  // Another small optimization: we sort all the ComparisonTerms which have a variable name set
152  // at the beginning. This allows to force this variable name in other ComparisonTerms that use
153  // the same property (for details see QueryBuilderData::uniqueVarName)
154  //
155  QList<Term> sortedSubTerms;
156  foreach( const Nepomuk2::Query::Term &t, term.toAndTerm().subTerms() ) {
157  if(t.isComparisonTerm() && !t.toComparisonTerm().variableName().isEmpty()) {
158  sortedSubTerms.prepend(t);
159  }
160  else {
161  sortedSubTerms.append(t);
162  }
163  }
164 
165  foreach(const Term& subTerm, sortedSubTerms) {
166  newAndTerm.addSubTerm(optimizeEvenMore(subTerm));
167  }
168  return newAndTerm;
169  }
170 
171  //
172  // For OptionalTerms we simply need to optimize the subterm
173  //
174  else if(term.type() == Term::Optional) {
175  return OptionalTerm::optionalizeTerm(optimizeEvenMore(term.toOptionalTerm().subTerm()));
176  }
177 
178  //
179  // For NegationTerms we simply need to optimize the subterm
180  //
181  else if(term.type() == Term::Negation) {
182  return NegationTerm::negateTerm(optimizeEvenMore(term.toNegationTerm().subTerm()));
183  }
184 
185  else {
186  return term;
187  }
188 }
189 
190 
191 class Nepomuk2::Query::Query::RequestProperty::Private : public QSharedData
192 {
193 public:
194  Nepomuk2::Types::Property m_property;
195  bool m_optional;
196 };
197 
198 Nepomuk2::Query::Query::RequestProperty::RequestProperty( const Nepomuk2::Types::Property& property,
199  bool optional )
200  : d(new Private())
201 {
202  d->m_property = property;
203  d->m_optional = optional;
204 }
205 
206 Nepomuk2::Query::Query::RequestProperty::RequestProperty( const RequestProperty& other )
207 {
208  d = other.d;
209 }
210 
211 Nepomuk2::Query::Query::RequestProperty::~RequestProperty()
212 {
213 }
214 
215 Nepomuk2::Query::Query::RequestProperty& Nepomuk2::Query::Query::RequestProperty::operator=( const RequestProperty& other )
216 {
217  d = other.d;
218  return *this;
219 }
220 
221 Nepomuk2::Types::Property Nepomuk2::Query::Query::RequestProperty::property() const
222 {
223  return d->m_property;
224 }
225 
226 bool Nepomuk2::Query::Query::RequestProperty::optional() const
227 {
228  return d->m_optional;
229 }
230 
231 bool Nepomuk2::Query::Query::RequestProperty::operator==( const RequestProperty& other ) const
232 {
233  return d->m_property == other.d->m_property && d->m_optional == other.d->m_optional;
234 }
235 
236 
237 Nepomuk2::Query::Query::Query()
238  : d( new QueryPrivate() )
239 {
240 }
241 
242 
243 Nepomuk2::Query::Query::Query( const Query& other )
244 {
245  d = other.d;
246 }
247 
248 
249 Nepomuk2::Query::Query::Query( const Term& term )
250  : d ( new QueryPrivate() )
251 {
252  d->m_term = term;
253 }
254 
255 
256 Nepomuk2::Query::Query::~Query()
257 {
258 }
259 
260 
261 Nepomuk2::Query::Query& Nepomuk2::Query::Query::operator=( const Query& other )
262 {
263  d = other.d;
264  return *this;
265 }
266 
267 
268 Nepomuk2::Query::Query& Nepomuk2::Query::Query::operator=( const Term& term )
269 {
270  d->m_term = term;
271  return *this;
272 }
273 
274 
275 bool Nepomuk2::Query::Query::isValid() const
276 {
277  return( d->m_term.isValid() || isFileQuery() );
278 }
279 
280 
281 bool Nepomuk2::Query::Query::isFileQuery() const
282 {
283  return d->m_isFileQuery;
284 }
285 
286 
287 Nepomuk2::Query::FileQuery Nepomuk2::Query::Query::toFileQuery() const
288 {
289  return FileQuery( *this );
290 }
291 
292 
293 Nepomuk2::Query::Term Nepomuk2::Query::Query::term() const
294 {
295  return d->m_term;
296 }
297 
298 
299 int Nepomuk2::Query::Query::limit() const
300 {
301  return d->m_limit;
302 }
303 
304 
305 int Nepomuk2::Query::Query::offset() const
306 {
307  return d->m_offset;
308 }
309 
310 
311 void Nepomuk2::Query::Query::setTerm( const Term& term )
312 {
313  d->m_term = term;
314 }
315 
316 
317 void Nepomuk2::Query::Query::setLimit( int limit )
318 {
319  d->m_limit = limit;
320 }
321 
322 
323 void Nepomuk2::Query::Query::setOffset( int offset )
324 {
325  d->m_offset = offset;
326 }
327 
328 
329 void Nepomuk2::Query::Query::setFullTextScoringEnabled( bool enabled )
330 {
331  d->m_fullTextScoringEnabled = enabled;
332 }
333 
334 
335 void Nepomuk2::Query::Query::setFullTextScoringSortOrder( Qt::SortOrder order )
336 {
337  d->m_fullTextScoringSortOrder = order;
338 }
339 
340 
341 bool Nepomuk2::Query::Query::fullTextScoringEnabled() const
342 {
343  return d->m_fullTextScoringEnabled;
344 }
345 
346 
347 Qt::SortOrder Nepomuk2::Query::Query::fullTextScoringSortOrder() const
348 {
349  return d->m_fullTextScoringSortOrder;
350 }
351 
352 
353 void Nepomuk2::Query::Query::setQueryFlags( QueryFlags flags )
354 {
355  d->m_flags = flags;
356 }
357 
358 
359 Nepomuk2::Query::Query::QueryFlags Nepomuk2::Query::Query::queryFlags() const
360 {
361  return d->m_flags;
362 }
363 
364 
365 void Nepomuk2::Query::Query::addRequestProperty( const RequestProperty& property )
366 {
367  d->m_requestProperties.append( property );
368 }
369 
370 
371 void Nepomuk2::Query::Query::setRequestProperties( const QList<RequestProperty>& properties )
372 {
373  d->m_requestProperties = properties;
374 }
375 
376 
377 QList<Nepomuk2::Query::Query::RequestProperty> Nepomuk2::Query::Query::requestProperties() const
378 {
379  return d->m_requestProperties;
380 }
381 
382 
383 bool Nepomuk2::Query::Query::operator==( const Query& other ) const
384 {
385  return( d->m_limit == other.d->m_limit &&
386  d->m_offset == other.d->m_offset &&
387  d->m_term == other.d->m_term &&
388  compareQList( d->m_requestProperties, other.d->m_requestProperties ) &&
389  compareHash( d->m_includeFolders, other.d->m_includeFolders ) &&
390  compareQList( d->m_excludeFolders, other.d->m_excludeFolders ) &&
391  d->m_isFileQuery == other.d->m_isFileQuery &&
392  d->m_fileMode == other.d->m_fileMode );
393 }
394 
395 
396 bool Nepomuk2::Query::Query::operator!=( const Query& other ) const
397 {
398  return( d->m_limit != other.d->m_limit ||
399  d->m_offset != other.d->m_offset ||
400  d->m_term != other.d->m_term ||
401  !compareQList( d->m_requestProperties, other.d->m_requestProperties ) ||
402  !compareHash( d->m_includeFolders, other.d->m_includeFolders ) ||
403  !compareQList( d->m_excludeFolders, other.d->m_excludeFolders ) ||
404  d->m_isFileQuery != other.d->m_isFileQuery ||
405  d->m_fileMode != other.d->m_fileMode );
406 }
407 
408 
409 QString Nepomuk2::Query::Query::toSparqlQuery( SparqlFlags sparqlFlags ) const
410 {
411  Term term = d->m_term;
412 
413  // restrict to files if we are a file query
414  if( d->m_isFileQuery ) {
415  Term fileModeTerm;
416  ResourceTypeTerm fileTerm( Vocabulary::NFO::FileDataObject() );
417  ResourceTypeTerm folderTerm( Vocabulary::NFO::Folder() );
418  if( d->m_fileMode == FileQuery::QueryFiles )
419  fileModeTerm = AndTerm( fileTerm, NegationTerm::negateTerm( folderTerm ) );
420  else if( d->m_fileMode == FileQuery::QueryFolders )
421  fileModeTerm = folderTerm;
422  else
423  fileModeTerm = fileTerm;
424  term = AndTerm( term, fileModeTerm, d->createFolderFilter() );
425  }
426 
427 
428  // convert request properties into ComparisonTerms
429  // in ask and count query mode we can omit the optional req props
430  for ( int i = 0; i < d->m_requestProperties.count(); ++i ) {
431  const RequestProperty& rp = d->m_requestProperties[i];
432  ComparisonTerm rpt( rp.property(), Term() );
433  rpt.setVariableName( QString::fromLatin1("reqProp%1").arg(i+1) );
434  if( rp.optional() && !( sparqlFlags&(CreateAskQuery|CreateCountQuery) ) ) {
435  term = term && OptionalTerm::optionalizeTerm( rpt );
436  }
437  else if( !rp.optional() ) {
438  term = term && rpt;
439  }
440  }
441 
442 
443  // optimize whatever we can
444  term = term.optimized();
445 
446  // perform internal optimizations
447  term = d->optimizeEvenMore(term);
448 
449  // actually build the SPARQL query patterns
450  QueryBuilderData qbd( d.constData(), sparqlFlags );
451 
452  if(!term.isValid()) {
453  return QString();
454  }
455 
456  QString termGraphPattern;
457  termGraphPattern = term.d_ptr->toSparqlGraphPattern( QLatin1String( "?r" ), 0, QString(), &qbd );
458  if( termGraphPattern.isEmpty() ) {
459  kDebug() << "Got no valid SPARQL pattern from" << term;
460  return QString();
461  }
462 
463 
464  // build the list of variables to select (in addition to the main result variable ?r)
465  QStringList selectVariables = qbd.customVariables();
466 
467  // add additional scoring variable if requested
468  if( d->m_fullTextScoringEnabled ) {
469  const QString scoringExpression = qbd.buildScoringExpression();
470  if( !scoringExpression.isEmpty() )
471  selectVariables << scoringExpression;
472  }
473 
474  // build the core of the query - the part that never changes
475  // HACK: We only need to show nepomuk uris as results. I've tried using other measures such
476  // as graph groups to hide ontology results, but virtuoso still does not have good support
477  // for those features, and crashes regularly.
478  // Since we are doing this filter on the client end, we may as well do it in the query
479  QString queryBase = QString::fromLatin1( "where { %1 FILTER(REGEX(STR(?r), '^nepomuk:/res')) . }" )
480  .arg( termGraphPattern );
481 
482  // build the final query
483  QString query;
484  if( sparqlFlags & CreateCountQuery ) {
485  if( selectVariables.isEmpty() ) {
486  // when there are no additional variables we can perfectly use count(distinct)
487  query = QString::fromLatin1("select count(distinct ?r) as ?cnt %1 %2")
488  .arg( selectVariables.join( QLatin1String(" " ) ),
489  queryBase );
490  }
491  else {
492  // when there are additional variables we need to do some magic to count the
493  // number of rows instead of a list of counts
494  // we cannot simply leave out the additional variables since that would change
495  // the number of results.
496  query = QString::fromLatin1("select count(%1) as ?cnt %2 where { { select count(*) as %1 ?r %3 } }")
497  .arg(qbd.uniqueVarName(),
498  selectVariables.join( QLatin1String(" " ) ),
499  queryBase );
500  }
501  }
502  else if( sparqlFlags & CreateAskQuery ) {
503  query = QLatin1String( "ask ") + queryBase;
504  }
505  else {
506  QString fullTextExcerptExpression;
507  if( queryFlags()&WithFullTextExcerpt ) {
508  fullTextExcerptExpression = qbd.buildSearchExcerptExpression();
509  }
510  query = QString::fromLatin1( "select distinct ?r %1 %2 %3" )
511  .arg( selectVariables.join( QLatin1String(" " ) ),
512  fullTextExcerptExpression,
513  queryBase );
514  query += qbd.buildOrderString();
515  }
516 
517  // offset and limit
518  if ( d->m_offset > 0 )
519  query += QString::fromLatin1( " OFFSET %1" ).arg( d->m_offset );
520  if ( d->m_limit > 0 )
521  query += QString::fromLatin1( " LIMIT %1" ).arg( d->m_limit );
522 
523  // We never want to show ontology data to the users
524  // FIXME: This has been causing virtuoso to crash on a large number of queries
525  // For now I'm disabling this. We might need to find a better solution. This just sucks.
526  //
527  // Example query (which causes the crash) -
528  //
529  // sparql DEFINE input:inference <nepomukinference>
530  // define input:default-graph-exclude <nepomuk-ontology-group>
531  // select distinct ?r ?reqProp1 where {
532  // { ?r nie:isPartOf <nepomuk:/res/d5cb1ed7-a80b-46b6-8467-35716f5e7188> .
533  // ?r nmo:plainTextMessageContent ?v1 .
534  // FILTER(bif:contains(?v1, "'funcom'")) .
535  // OPTIONAL { ?r <http://akonadi-project.org/ontologies/aneo#akonadiItemId> ?reqProp1 . }
536  // } .
537  // }
538  // query = QLatin1String("define input:default-graph-exclude <nepomuk-ontology-group> ") + query;
539 
540  return query.simplified();
541 }
542 
543 
544 KUrl Nepomuk2::Query::Query::toSearchUrl( SparqlFlags flags ) const
545 {
546  return toSearchUrl( QString(), flags );
547 }
548 
549 
550 // This is a bit dodgy: if there are sparql flags we encode the SPARQL query into the url
551 // otherwise the serialized query (which allows for more power in the kio slave). It would
552 // probably be nicer to somehow put the flags in the URL. But new query items in the URL
553 // would make the URL handling in the kio slave more complicated.... oh, well.
554 KUrl Nepomuk2::Query::Query::toSearchUrl( const QString& customTitle, SparqlFlags flags ) const
555 {
556  // the nepomuksearch:/ KIO slave does not handle count or ask queries
557  flags &= ~CreateCountQuery;
558  flags &= ~CreateAskQuery;
559 
560  Query q( *this );
561 
562  // the nepomuksearch:/ KIO slave does not make use of full text scores. Thus, we avoid the
563  // overhead by disabling them
564  q.setFullTextScoringEnabled( false );
565 
566  KUrl url( QLatin1String("nepomuksearch:/") );
567  if( flags == NoFlags )
568  url.addQueryItem( QLatin1String("encodedquery"), q.toString() );
569  else
570  url.addQueryItem( QLatin1String("sparql"), q.toSparqlQuery( flags ) );
571 
572  QString title(customTitle);
573  if( customTitle.isEmpty() ) {
574  title = titleFromQueryUrl( url );
575  }
576 
577  // replace slashes with the "fraction slash" which is the same KIO::encodeFileName does.
578  // however, we do not want to link to KIO.
579  url.addPath( title.replace('/', QChar(0x2044)) );
580 
581  return url;
582 }
583 
584 
585 Nepomuk2::Query::RequestPropertyMap Nepomuk2::Query::Query::requestPropertyMap() const
586 {
587  RequestPropertyMap rpm;
588  for ( int i = 0; i < d->m_requestProperties.count(); ++i ) {
589  rpm.insert( QString( "reqProp%1" ).arg( i+1 ), d->m_requestProperties[i].property() );
590  }
591  return rpm;
592 }
593 
594 
595 QString Nepomuk2::Query::Query::toString() const
596 {
597  return Nepomuk2::Query::serializeQuery( *this );
598 }
599 
600 
601 Nepomuk2::Query::Query Nepomuk2::Query::Query::optimized() const
602 {
603  Query newQuery( *this );
604  newQuery.setTerm( term().optimized() );
605  return newQuery;
606 }
607 
608 
609 // static
610 Nepomuk2::Query::Query Nepomuk2::Query::Query::fromString( const QString& queryString )
611 {
612  return Nepomuk2::Query::parseQuery( queryString );
613 }
614 
615 
616 namespace {
620  inline QString extractPlainQuery( const KUrl& url ) {
621  if( url.queryItems().contains( "query" ) ) {
622  return url.queryItem( "query" );
623  }
624  else if ( !url.hasQuery() ) {
625  return url.path().section( '/', 0, 0, QString::SectionSkipEmpty );
626  }
627  else {
628  return QString();
629  }
630  }
631 }
632 
633 // static
634 Nepomuk2::Query::Query Nepomuk2::Query::Query::fromQueryUrl( const KUrl& url )
635 {
636  if( url.protocol() != QLatin1String("nepomuksearch") ) {
637  kDebug() << "No nepomuksearch:/ URL:" << url;
638  return Query();
639  }
640 
641  if ( url.queryItems().contains( "sparql" ) ) {
642  kDebug() << "Cannot parse SPARQL query from:" << url;
643  return Query();
644  }
645  else if( url.queryItems().contains( "encodedquery" ) ) {
646  return fromString( url.queryItem( "encodedquery") );
647  }
648  else {
649  Query query = QueryParser::parseQuery( extractPlainQuery(url) );
650  return query;
651  }
652 }
653 
654 
655 // static
656 QString Nepomuk2::Query::Query::sparqlFromQueryUrl( const KUrl& url )
657 {
658  if( url.protocol() != QLatin1String("nepomuksearch") ) {
659  kDebug() << "No nepomuksearch:/ URL:" << url;
660  return QString();
661  }
662 
663  if( url.queryItems().contains( "sparql" ) ) {
664  return url.queryItem( "sparql" );
665  }
666  else {
667  Query query = fromQueryUrl( url );
668  if( query.isValid() ) {
669  query.setRequestProperties( QList<RequestProperty>() << Nepomuk2::Query::Query::RequestProperty( Nepomuk2::Vocabulary::NIE::url(), true ) );
670  return query.toSparqlQuery();
671  }
672  else {
673  return QString();
674  }
675  }
676 }
677 
678 
679 // static
680 QString Nepomuk2::Query::Query::titleFromQueryUrl( const KUrl& url )
681 {
682  if( url.protocol() != QLatin1String("nepomuksearch") ) {
683  kDebug() << "No nepomuksearch:/ URL:" << url;
684  return QString();
685  }
686 
687  // the title is the first section of the path, but only if we have a query
688  if( url.hasQuery() ) {
689  QString title = url.path().section( '/', 0, 0, QString::SectionSkipEmpty );
690  if(!title.isEmpty())
691  return title;
692  }
693 
694  // no title in the path, try to get the user query, i.e. a non-encoded and non-sparql query
695  QString userQuery = extractPlainQuery( url );
696  if ( !userQuery.isEmpty() ) {
697  return i18nc( "@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.",
698  "Query Results from '%1'",
699  userQuery );
700  }
701 
702  // fallback: generic query title
703  return i18nc( "@title UDS_DISPLAY_NAME for a KIO directory listing.",
704  "Query Results");
705 }
706 
707 
708 Nepomuk2::Query::Query Nepomuk2::Query::operator&&( const Query& query, const Term& term )
709 {
710  Query newQuery( query );
711  newQuery.setTerm( query.term() && term );
712  return newQuery;
713 }
714 
715 
716 Nepomuk2::Query::Query Nepomuk2::Query::operator||( const Query& query, const Term& term )
717 {
718  Query newQuery( query );
719  newQuery.setTerm( query.term() || term );
720  return newQuery;
721 }
722 
723 
724 Nepomuk2::Query::Query Nepomuk2::Query::operator!( const Query& query )
725 {
726  Query newQuery( query );
727  newQuery.setTerm( !query.term() );
728  return newQuery;
729 }
730 
731 
732 QDebug operator<<( QDebug dbg, const Nepomuk2::Query::Query& query )
733 {
734  return dbg << query.toString();
735 }
736 
737 
738 uint Nepomuk2::Query::qHash( const Nepomuk2::Query::Query& query )
739 {
740  return qHash( query.term() );
741 }
andterm.h
Nepomuk2::Query::Query::toSparqlQuery
QString toSparqlQuery(SparqlFlags flags=NoFlags) const
Convert the query into a SPARQL query which can be used with the Nepomuk query service or directly in...
Definition: query.cpp:409
class.h
Nepomuk2::Query::Query::toSearchUrl
KUrl toSearchUrl(SparqlFlags flags=NoFlags) const
Convert the query into a URL which can be listed using KIO::DirLister.
Definition: query.cpp:544
Nepomuk2::Query::AndTerm
Match resource that match all sub terms.
Definition: andterm.h:43
Nepomuk2::Query::Term::isComparisonTerm
bool isComparisonTerm() const
Definition: term.cpp:199
Nepomuk2::Query::Term::toOptionalTerm
OptionalTerm toOptionalTerm() const
Interpret this term as a OptionalTerm.
Definition: term.cpp:239
util.h
Nepomuk2::Query::Query::requestPropertyMap
RequestPropertyMap requestPropertyMap() const
Build a request property map as used in QueryServiceClient::sparqlQuery() from the request properties...
Definition: query.cpp:585
Nepomuk2::Query::Query::queryFlags
QueryFlags queryFlags() const
Get the query flags to configure this query.
Definition: query.cpp:359
resourceterm.h
Nepomuk2::Query::Term::Negation
A negation term inverts the meaning of its sub term.
Definition: term.h:127
Nepomuk2::Query::Term
The base class for all term types.
Definition: term.h:64
Nepomuk2::Query::Query::titleFromQueryUrl
static QString titleFromQueryUrl(const KUrl &url)
Extact the title from a nepomuksearch:/ query URL.
Definition: query.cpp:680
Nepomuk2::Query::ComparisonTerm::variableName
QString variableName() const
The variable name set in setVariableName() or an empty string if none has been set.
Definition: comparisonterm.cpp:495
Nepomuk2::Query::Query::toFileQuery
FileQuery toFileQuery() const
Definition: query.cpp:287
Nepomuk2::Query::serializeQuery
QString serializeQuery(const Query &query)
Definition: queryserializer.cpp:352
Nepomuk2::Query::ResourceTypeTerm
Matching resources by type.
Definition: resourcetypeterm.h:48
Nepomuk2::Query::Query::fromString
static Query fromString(const QString &queryString)
Parse a Query that has been encoded as a string via toString().
Definition: query.cpp:610
Nepomuk2::Query::NegationTerm::negateTerm
static Term negateTerm(const Term &term)
Negate term.
Definition: negationterm.cpp:101
Nepomuk2::Query::Query::term
Term term() const
The root term of the query.
Definition: query.cpp:293
Nepomuk2::Query::Query::setRequestProperties
void setRequestProperties(const QList< RequestProperty > &properties)
Set the properties that should be reported with each search result.
Definition: query.cpp:371
QHash
Nepomuk2::Query::Query::requestProperties
QList< RequestProperty > requestProperties() const
Definition: query.cpp:377
Nepomuk2::Query::SimpleTerm::subTerm
Term subTerm() const
The sub term to match against.
Definition: simpleterm.cpp:52
negationterm.h
Nepomuk2::operator<<
QDataStream & operator<<(QDataStream &, const Nepomuk2::SimpleResource &)
Definition: simpleresource.cpp:307
Nepomuk2::Query::GroupTerm::subTerms
QList< Term > subTerms() const
The sub terms that are combined in this group.
Definition: groupterm.cpp:94
Nepomuk2::Query::Term::optimized
Term optimized() const
Optimizes the term without changing its meaning.
Definition: term.cpp:99
Nepomuk2::Query::Term::And
Match all resources that match all sub terms.
Definition: term.h:98
Nepomuk2::Query::qHash
uint qHash(const Nepomuk2::Query::Query &)
Definition: query.cpp:738
Nepomuk2::Query::Query::setLimit
void setLimit(int)
Set the maximum number of results this query should yield.
Definition: query.cpp:317
Nepomuk2::Query::FileQuery::QueryFiles
Definition: filequery.h:168
Nepomuk2::Query::FileQuery::QueryFolders
Definition: filequery.h:169
query.h
Nepomuk2::Query::Query::RequestProperty::optional
bool optional() const
Definition: query.cpp:226
Nepomuk2::Query::ResourceTypeTerm::type
Nepomuk2::Types::Class type() const
The type to match.
Definition: resourcetypeterm.cpp:94
Nepomuk2::Query::Query::offset
int offset() const
The first result that should be retrieved.
Definition: query.cpp:305
Nepomuk2::Query::Term::Optional
An optional term which marks its sub term as optional.
Definition: term.h:136
Nepomuk2::Query::Query::setTerm
void setTerm(const Term &)
Set the root term of the query.
Definition: query.cpp:311
Nepomuk2::Query::Term::toComparisonTerm
ComparisonTerm toComparisonTerm() const
Interpret this term as a ComparisonTerm.
Definition: term.cpp:266
Nepomuk2::Query::Query::addRequestProperty
void addRequestProperty(const RequestProperty &property)
Add a property that should be reported with each search result.
Definition: query.cpp:365
Nepomuk2::Query::RequestPropertyMap
QHash< QString, Nepomuk2::Types::Property > RequestPropertyMap
Convinience definition for request property mappings as used in QueryServiceClient::sparqlQuery() and...
Definition: query.h:41
Nepomuk2::Query::Query::operator!=
bool operator!=(const Query &query) const
Comparison operator.
Definition: query.cpp:396
Nepomuk2::Query::Query::fromQueryUrl
static Query fromQueryUrl(const KUrl &url)
Extract a query from a nepomuksearch:/ query URL.
Definition: query.cpp:634
Nepomuk2::Query::operator&&
Query operator&&(const Query &query, const Term &term)
Logical and operator which combines term into the term of query to match both.
Definition: query.cpp:708
Nepomuk2::Query::Query::sparqlFromQueryUrl
static QString sparqlFromQueryUrl(const KUrl &url)
Extract the SPARQL query from a nepomuksearch:/ query URL.
Definition: query.cpp:656
Nepomuk2::Query::Query::Query
Query()
Create an empty invalid query object.
Definition: query.cpp:237
queryserializer.h
Nepomuk2::Query::Query::operator=
Query & operator=(const Query &)
Assignment operator.
Definition: query.cpp:261
Nepomuk2::Query::Query::optimized
Query optimized() const
Optimizes the query without chaning its meaning.
Definition: query.cpp:601
Nepomuk2::Query::Term::toOrTerm
OrTerm toOrTerm() const
Interpret this term as a OrTerm.
Definition: term.cpp:257
Nepomuk2::Query::FileQuery
A Nepomuk desktop query specialized for file searches.
Definition: filequery.h:44
Nepomuk2::Query::ComparisonTerm
A term matching the value of a property.
Definition: comparisonterm.h:70
Nepomuk2::Query::Query
A Nepomuk desktop query.
Definition: query.h:76
Nepomuk2::Query::Query::RequestProperty
A request property can be added to a Query to retrieve additional information about the results...
Definition: query.h:287
Nepomuk2::Query::OrTerm
Match resource that match at least one of the sub terms.
Definition: orterm.h:43
Nepomuk2::Query::Query::setFullTextScoringEnabled
void setFullTextScoringEnabled(bool enabled)
Nepomuk supports scoring the results based on any full text matching used in the query (full text mat...
Definition: query.cpp:329
Nepomuk2::Types::Property
A property is a resource of type rdf:Property which relates a domain with a range.
Definition: libnepomukcore/types/property.h:52
Nepomuk2::Query::Query::operator==
bool operator==(const Query &query) const
Comparison operator.
Definition: query.cpp:383
Nepomuk2::Query::Term::ResourceType
Matches all resources of a specific type.
Definition: term.h:120
resourcemanager.h
Nepomuk2::Query::Query::RequestProperty::property
Nepomuk2::Types::Property property() const
Definition: query.cpp:221
Nepomuk2::Query::Query::isValid
bool isValid() const
Definition: query.cpp:275
resourcetypeterm.h
Nepomuk2::Query::OptionalTerm::optionalizeTerm
static Term optionalizeTerm(const Term &term)
Mark term as optional.
Definition: optionalterm.cpp:59
Nepomuk2::Query::Query::RequestProperty::RequestProperty
RequestProperty(const Nepomuk2::Types::Property &property, bool optional=true)
Create a new request property.
Definition: query.cpp:198
Nepomuk2::Query::Query::RequestProperty::operator==
bool operator==(const RequestProperty &other) const
Comparison operator.
Definition: query.cpp:231
Nepomuk2::Query::Query::RequestProperty::operator=
RequestProperty & operator=(const RequestProperty &)
Copy operator.
Definition: query.cpp:215
Nepomuk2::Query::Query::setOffset
void setOffset(int offset)
The first result that should be retrieved.
Definition: query.cpp:323
Nepomuk2::Query::QueryParser::parseQuery
static Query parseQuery(const QString &query)
Convenience method to quickly parse a query without creating an object.
Definition: queryparser.cpp:815
Nepomuk2::Query::operator||
Query operator||(const Query &query, const Term &term)
Logical or operator which combines term into the term of query to match either one.
Definition: query.cpp:716
Nepomuk2::Query::Query::isFileQuery
bool isFileQuery() const
Definition: query.cpp:281
comparisonterm.h
compareHash
bool compareHash(const QHash< Key, Value > &h1, const QHash< Key, Value > &h2)
Definition: libnepomukcore/query/util.h:39
literalterm.h
Nepomuk2::Query::Query::~Query
~Query()
Destructor.
Definition: query.cpp:256
Nepomuk2::Query::Query::RequestProperty::~RequestProperty
~RequestProperty()
Destructor.
Definition: query.cpp:211
Nepomuk2::Query::GroupTerm::addSubTerm
void addSubTerm(const Term &term)
Add a sub term to the list of terms that are combined in this group.
Definition: groupterm.cpp:108
Nepomuk2::Query::Term::toAndTerm
AndTerm toAndTerm() const
Interpret this term as a AndTerm.
Definition: term.cpp:248
Nepomuk2::Query::Query::toString
QString toString() const
Encode the Query in a string.
Definition: query.cpp:595
Nepomuk2::Query::Query::setQueryFlags
void setQueryFlags(QueryFlags flags)
Set the query flags to configure this query.
Definition: query.cpp:353
Nepomuk2::Query::Query::fullTextScoringEnabled
bool fullTextScoringEnabled() const
Definition: query.cpp:341
orterm.h
optionalterm.h
term.h
Nepomuk2::Query::ComparisonTerm::setVariableName
void setVariableName(const QString &name)
Set the variable name that is to be used for the variable to match to.
Definition: comparisonterm.cpp:488
Nepomuk2::Query::Query::fullTextScoringSortOrder
Qt::SortOrder fullTextScoringSortOrder() const
Definition: query.cpp:347
literal.h
Nepomuk2::Query::Term::type
Type type() const
Definition: term.cpp:84
Nepomuk2::Query::operator!
Query operator!(const Query &query)
Logical negation operator which negates the meaning of a query.
Definition: query.cpp:724
Nepomuk2::Query::Term::isValid
bool isValid() const
Definition: term.cpp:78
compareQList
bool compareQList(const QList< T > &rp1, const QList< T > &rp2)
Definition: libnepomukcore/query/util.h:27
Nepomuk2::Query::Query::limit
int limit() const
The maximum number of results that this query should yield.
Definition: query.cpp:299
Nepomuk2::Query::Term::Or
Match all resources that match one of the sub terms.
Definition: term.h:105
filequery.h
Nepomuk2::Query::parseQuery
Query parseQuery(const QString &s)
Definition: queryserializer.cpp:411
Nepomuk2::Query::Query::setFullTextScoringSortOrder
void setFullTextScoringSortOrder(Qt::SortOrder order)
Set the full text scoring sort order.
Definition: query.cpp:335
queryparser.h
Nepomuk2::Query::Term::toNegationTerm
NegationTerm toNegationTerm() const
Interpret this term as a NegationTerm.
Definition: term.cpp:230
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal