[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/nepomuk-kde/search-api
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2008-04-30 22:22:11
Message-ID: 1209594131.731193.18739.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 802869 by trueg:
Support full property and resource URIs in query strings. Fixed values in quotes. In \
the end the problem was that either QRegExp's \b is broken or I did not understand \
it.
M +53 -7 queryparser.cpp
--- trunk/playground/base/nepomuk-kde/search-api/queryparser.cpp #802868:802869
@@ -32,21 +32,36 @@
*/
namespace {
- QString s_plainTermPattern( "([^\\s\"':=\\<\\>]+|(?:([\"'])[^\"':=\\<\\>]+\\2))" \
); + QString s_plainTermPattern( "([^\\s\"':=\\<\\>]+|(?:([\"'])[^\"']+\\%1))" );
QString s_inExclusionPattern( "([\\+\\-]?)" );
+ QString s_uriPattern( "<([^<>]+)>" );
+ QString s_comparatorPattern( "(:|=|\\<|\\>|\\<=|\\>=)" );
// match a simple search text
// captures: 1 - The optional + or - sign (may be empty)
// 2 - the search text (including optional paranthesis)
- QRegExp s_plainTermRx( "\\b" + s_inExclusionPattern + s_plainTermPattern + "\\b" \
); + QRegExp s_plainTermRx( QString( s_inExclusionPattern + s_plainTermPattern \
).arg( 3 ) );
// match a field search term: fieldname + relation (:, =, etc) + search text \
with optional paranthesis // captures: 1 - The optional + or - sign (may be empty)
// 2 - fieldname
// 3 - relation
// 4 - search text (including optional paranthesis)
- QRegExp s_fieldRx( "\\b" + s_inExclusionPattern + "(\\S+)([:=\\<\\>])" + \
s_plainTermPattern + "\\b" ); + QRegExp s_fieldRx( QString( s_inExclusionPattern + \
"(\\S+)" + s_comparatorPattern + s_plainTermPattern ).arg( 5 ) );
+ // match a property URI search term: property URI + relation (:, =, etc) + \
search text with optional paranthesis + // captures: 1 - The optional + or - sign \
(may be empty) + // 2 - property URI
+ // 3 - relation
+ // 4 - search text (including optional paranthesis)
+ QRegExp s_propertyRx( QString( s_inExclusionPattern + s_uriPattern + \
s_comparatorPattern + s_plainTermPattern ).arg( 5 ) ); +
+ // match a property URI search term: property URI + relation (:, =, etc) + \
resource URI + // captures: 1 - The optional + or - sign (may be empty)
+ // 2 - property URI
+ // 3 - resource URI
+ QRegExp s_resourceRx( QString( s_inExclusionPattern + s_uriPattern + "(?::|=)" + \
s_uriPattern ) ); +
// FIXME: allow comparators in field and values when we have ' or " around them
Nepomuk::Search::Term::Comparator fieldTypeRelationFromString( const QString& s \
) { @@ -70,6 +85,16 @@
return Nepomuk::Search::Term::Equal;
}
}
+
+ QString stripQuotes( const QString& s ) {
+ if ( s[0] == '\'' ||
+ s[0] == '\"' ) {
+ return s.mid( 1 ).left( s.length()-2 );
+ }
+ else {
+ return s;
+ }
+ }
}
@@ -123,11 +148,32 @@
Term term;
if ( pos < query.length() ) {
- if ( s_fieldRx.indexIn( query, pos ) == pos ) {
+ if ( s_resourceRx.indexIn( query, pos ) == pos ) {
// FIXME: honour the +-
- kDebug() << "matched field term at" << pos << s_fieldRx.cap( 2 );
+ kDebug() << "matched resource term at" << pos << s_resourceRx.cap( 0 \
); + term = Term( QUrl( s_resourceRx.cap( 2 ) ), QUrl( \
s_resourceRx.cap( 3 ) ) ); + pos += s_resourceRx.matchedLength();
+ }
+ else if ( s_propertyRx.indexIn( query, pos ) == pos ) {
+ // FIXME: honour the +-
+ kDebug() << "matched property term at" << pos << s_propertyRx.cap( 0 \
); + term.setProperty( QUrl( s_propertyRx.cap( 2 ) ) );
+ term.setValue( stripQuotes( s_propertyRx.cap( 4 ) ) );
+ QString comparator = s_propertyRx.cap( 3 );
+ if( comparator == QChar(':') ) {
+ term.setType( Term::ContainsTerm );
+ }
+ else {
+ term.setType( Term::ComparisonTerm );
+ term.setComparator( fieldTypeRelationFromString( comparator ) );
+ }
+ pos += s_propertyRx.matchedLength();
+ }
+ else if ( s_fieldRx.indexIn( query, pos ) == pos ) {
+ // FIXME: honour the +-
+ kDebug() << "matched field term at" << pos << s_fieldRx.cap( 0 );
term.setField( s_fieldRx.cap( 2 ) );
- term.setValue( s_fieldRx.cap( 4 ) );
+ term.setValue( stripQuotes( s_fieldRx.cap( 4 ) ) );
QString comparator = s_fieldRx.cap( 3 );
if( comparator == QChar(':') ) {
term.setType( Term::ContainsTerm );
@@ -140,7 +186,7 @@
}
else if ( s_plainTermRx.indexIn( query, pos ) == pos ) {
// FIXME: honour the +-
- QString value = s_plainTermRx.cap( 2 );
+ QString value = stripQuotes( s_plainTermRx.cap( 2 ) );
if ( value.length() == d->orKeyword.length() && value.toLower() == \
d->orKeyword ) { inOrBlock = true;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic