Nepomuk-Core
#include <Nepomuk2/Query/QueryParser>
Public Types | |
enum | ParserFlag { NoParserFlags = 0x0, QueryTermGlobbing = 0x1, DetectFilenamePattern = 0x2 } |
Public Member Functions | |
QueryParser () | |
~QueryParser () | |
QList< Types::Property > | matchProperty (const QString &fieldName) const |
Query | parse (const QString &query) const |
Query | parse (const QString &query, ParserFlags flags) const |
Static Public Member Functions | |
static Query | parseQuery (const QString &query) |
static Query | parseQuery (const QString &query, ParserFlags flags) |
Detailed Description
Parser for desktop user queries.
- Warning
- This is NOT a SPARQL parser.
The QueryParser can be used to parse user queries, ie. queries that the user would enter in any search interface, and convert them into Query instances.
The syntax is fairly simple: plain strings match to LiteralTerm terms, URIs need to be N3-encoded, when using white space parenthesis need to be put around properties and values, terms can be excluded via '-'
.
Examples
Query everything that contains the term "nepomuk":
Query everything that contains both the terms "Hello" and "World":
Query everything that contains the term "Hello World":
Query everything that has a tag whose label matches "nepomuk" (actually this is where Query::resolveProperties would match "hastag" to nao:hasTag):
Query everything that has a tag labeled "nepomuk" or a tag labeled "scribo:
Query everything that has a tag labeled "nepomuk" but not a tag labeled "scribo":
The parser can handle one special case of nesting (TODO: implement a "real" parser) which matches all resources that are related to a resource which in turn has a certain property:
- Since
- 4.4
Definition at line 90 of file queryparser.h.
Member Enumeration Documentation
Flags to change the behaviour of the parser.
- Since
- 4.5
Enumerator | |
---|---|
NoParserFlags |
No flags. Default for parse() |
QueryTermGlobbing |
Make each full text term use a '*' wildcard to match longer strings ('foobar' is matched by 'foob*'). Be aware that the query engine needs at least 4 chars to do globbing though. This is disabled by default. |
DetectFilenamePattern |
Try to detect filename pattern like *.mp3 or hello*.txt and create appropriate ComparisonTerm instances using ComparisonTerm::Regexp instead of ComparisonTerm::Contains.
|
Definition at line 108 of file queryparser.h.
Constructor & Destructor Documentation
Nepomuk2::Query::QueryParser::QueryParser | ( | ) |
Create a new query parser.
Definition at line 538 of file queryparser.cpp.
Nepomuk2::Query::QueryParser::~QueryParser | ( | ) |
Destructor.
Definition at line 572 of file queryparser.cpp.
Member Function Documentation
QList< Nepomuk2::Types::Property > Nepomuk2::Query::QueryParser::matchProperty | ( | const QString & | fieldName | ) | const |
Try to match a field name as used in a query string to actual properties.
The matching is cached inside the Query instance for fast subsequent lookups.
Example:
- Returns
- A list of properties that match
fieldName
or an empty list in case nothing was matched.
This method is used by parse() to match properties used in user queries.
Definition at line 578 of file queryparser.cpp.
Nepomuk2::Query::Query Nepomuk2::Query::QueryParser::parse | ( | const QString & | query | ) | const |
Parse a user query.
- Returns
- The parsed query or an invalid Query object in case the parsing failed.
Definition at line 626 of file queryparser.cpp.
Nepomuk2::Query::Query Nepomuk2::Query::QueryParser::parse | ( | const QString & | query, |
ParserFlags | flags | ||
) | const |
Parse a user query.
- Parameters
-
query The query string to parse flags a set of flags influencing the parsing process.
- Returns
- The parsed query or an invalid Query object in case the parsing failed.
- Since
- 4.5
Definition at line 632 of file queryparser.cpp.
|
static |
Convenience method to quickly parse a query without creating an object.
- Returns
- The parsed query or an invalid Query object in case the parsing failed.
Definition at line 815 of file queryparser.cpp.
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters
-
query The query string to parse flags a set of flags influencing the parsing process.
- Since
- 4.6
Definition at line 823 of file queryparser.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.