[omapd] r187 committed - added support for faster metadata matching for simple match expression...

0 views
Skip to first unread message

om...@googlecode.com

unread,
Jun 26, 2013, 7:09:09 PM6/26/13
to omapd...@googlegroups.com
Revision: 187
Author: fu...@asguardnetworks.com
Date: Wed Jun 26 16:09:00 2013
Log: added support for faster metadata matching for simple match
expressions; changed string conversion for max-size attribute from long to
long long to fix compliance test failure when running on 32 bit OS
http://code.google.com/p/omapd/source/detail?r=187

Modified:
/branches/lfu/clienthandler.cpp
/branches/lfu/clienthandler.h
/branches/lfu/clientparser.cpp
/branches/lfu/maprequest.cpp
/branches/lfu/maprequest.h
/branches/lfu/subscription.cpp
/branches/lfu/subscription.h

=======================================
--- /branches/lfu/clienthandler.cpp Thu Jun 20 11:23:04 2013
+++ /branches/lfu/clienthandler.cpp Wed Jun 26 16:09:00 2013
@@ -930,7 +930,7 @@

QPair< QList<Meta>, QList<Meta> > result;

- QString filter = Subscription::translateFilter(pubOper._deleteFilter);
+ MetadataFilter filter(pubOper._deleteFilter);

QListIterator<Meta> metaListIt(existingMetaList);
while (metaListIt.hasNext() && !requestError) {
@@ -940,6 +940,7 @@
active subscribers.
*/
QString delMeta = filteredMetadata(aMeta, filter,
pubOper._filterNamespaceDefinitions, requestError);
+
if (! requestError) {
if (delMeta.isEmpty()) {
// Keep this metadata (delete filter did not match)
@@ -1345,14 +1346,14 @@
return haveChanges;
}

-QString ClientHandler::filteredMetadata(const Meta& meta, const QString&
filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error)
+QString ClientHandler::filteredMetadata(const Meta& meta, const
MetadataFilter& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error)
{
QList<Meta> singleMetaList;
singleMetaList.append(meta);
return filteredMetadata(singleMetaList, filter, searchNamespaces,
error);
}

-QString ClientHandler::filteredMetadata(const QList<Meta>& metaList, const
QString& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error)
+QString ClientHandler::filteredMetadata(const QList<Meta>& metaList, const
MetadataFilter& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error)
{
QString resultString("");
bool matchAll = false;
@@ -1382,67 +1383,104 @@
matchAll = true;
}

- QString qString;
- QTextStream queryStream(&qString);
+ if(filter.isSimple())
+ {
+ // the simplified filter will never be empty
+ const SimplifiedFilter* simFilter = filter.getSimplifiedFilter();

- if (!matchAll) {
- QMapIterator<QString, QString> nsIt(searchNamespaces);
- while (nsIt.hasNext()) {
- nsIt.next();
- queryStream << "declare namespace "
- << nsIt.key()
- << " = \""
- << nsIt.value()
- << "\";";
+ // go through each metadata item
+ QListIterator<Meta> metaIt(metaList);
+ while (metaIt.hasNext()) {
+ const Meta& meta = metaIt.next();
+ // and iterate through each filter disjunction element
+ QListIterator<QPair<QString, QString> > filterIt(*simFilter);
+ while (filterIt.hasNext()) {
+ const QPair<QString, QString>& pair = filterIt.next();
+ // element name must match as well as namespace
+ if(pair.second == meta.elementName() &&
searchNamespaces[pair.first] == meta.elementNS())
+ {
+ // qDebug() << "~~ filter " << pair.first << ':' <<
pair.second << " matches " << meta.metaXML();
+ resultString.append(meta.metaXML());
+ break;
+ }
+ }
}

- queryStream << "<metadata>";
- }
+ // If there are no query results, we won't add <metadata>
enclosing element
+ if (! resultString.isEmpty()) {
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterResults))
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Result:"
<< endl << resultString;

- QListIterator<Meta> metaIt(metaList);
- while (metaIt.hasNext()) {
- queryStream << metaIt.next().metaXML();
+ resultString.prepend("<metadata>");
+ resultString.append("</metadata>");
+ }
}
+ else
+ {
+ // run XMLQuery
+ QString qString;
+ QTextStream queryStream(&qString);

- if (!matchAll) {
- queryStream << "</metadata>";
- queryStream << "//"
- << filter;
- }
+ if (!matchAll) {
+ QMapIterator<QString, QString> nsIt(searchNamespaces);
+ while (nsIt.hasNext()) {
+ nsIt.next();
+ queryStream << "declare namespace "
+ << nsIt.key()
+ << " = \""
+ << nsIt.value()
+ << "\";";
+ }

- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterStatements))
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Statement:" <<
endl << qString;
+ queryStream << "<metadata>";
+ }

- QXmlQuery query;
- bool qrc;
+ QListIterator<Meta> metaIt(metaList);
+ while (metaIt.hasNext()) {
+ queryStream << metaIt.next().metaXML();
+ }

- if (!matchAll) {
- query.setQuery(qString);
- qrc = query.evaluateTo(&resultString);
- } else {
- resultString = qString;
- qrc = true;
- }
+ if (!matchAll) {
+ queryStream << "</metadata>";
+ queryStream << "//"
+ << filter.str();
+ }

- // Make sure (resultString.size() == 0) is true for checking if we
have results
- resultString = resultString.trimmed();
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterStatements))
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Statement:"
<< endl << qString;

- if (! qrc) {
- qDebug() << __PRETTY_FUNCTION__ << ":" << "ERROR: Error running
query with filter:" << filter;
- error = MapRequest::IfmapSystemError;
- } else {
- // If there are no query results, we won't add <metadata>
enclosing element
- if (! resultString.isEmpty()) {
- if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterResults))
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Query Result:"
<< endl << resultString;
+ QXmlQuery query;
+ bool qrc;
+
+ if (!matchAll) {
+ query.setQuery(qString);
+ qrc = query.evaluateTo(&resultString);
+ } else {
+ resultString = qString;
+ qrc = true;
+ }
+
+ // Make sure (resultString.size() == 0) is true for checking if we
have results
+ resultString = resultString.trimmed();
+
+ if (! qrc) {
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "ERROR: Error
running query with filter:" << filter.str();
+ error = MapRequest::IfmapSystemError;
+ } else {
+ // If there are no query results, we won't add <metadata>
enclosing element
+ if (! resultString.isEmpty()) {
+ if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLFilterResults))
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Query
Result:" << endl << resultString;

- resultString.prepend("<metadata>");
- resultString.append("</metadata>");
+ resultString.prepend("<metadata>");
+ resultString.append("</metadata>");
+ }
}
}

return resultString;
}
+

void ClientHandler::addIdentifierResult(Subscription &sub, const
Identifier& id, const QList<Meta>& metaList, SearchResult::ResultType
resultType, MapRequest::RequestError &operationError)
{
@@ -1478,11 +1516,13 @@
searchResult->_link = link;

if (!metaList.isEmpty() && ! sub._search.resultFilter().isEmpty()) {
- QString combinedFilter = sub._search.matchLinks();
- if (sub._search.resultFilter().compare("*") != 0) {
- combinedFilter =
Subscription::intersectFilter(sub._search.matchLinks(),
sub._search.resultFilter());
- }
- QString metaString = filteredMetadata(metaList, combinedFilter,
sub._search.filterNamespaceDefinitions(), operationError);
+ // (LFu) - only match result against result filter
+// QString combinedFilter = sub._search.matchLinks();
+// if (sub._search.resultFilter().compare("*") != 0) {
+// combinedFilter =
Subscription::intersectFilter(sub._search.matchLinks(),
sub._search.resultFilter());
+// }
+// QString metaString = filteredMetadata(metaList, combinedFilter,
sub._search.filterNamespaceDefinitions(), operationError);
+ QString metaString = filteredMetadata(metaList,
sub._search.resultFilter(), sub._search.filterNamespaceDefinitions(),
operationError);

if (! metaString.isEmpty()) {
searchResult->_metadata = metaString;
@@ -1817,7 +1857,7 @@
if (isLinkInSub && publishType == Meta::PublishUpdate) {
// Case 2.
subIsDirty = true;
- qDebug() << "~~oneIdInSub: case 2";
+ // qDebug() << "~~oneIdInSub: case 2";
} else if(subIsDirty || (oneIdInSub && publishType ==
Meta::PublishUpdate)) {
// (LFu) - the way this else was written before, it also
covered the case:
// !sub._linkList.contains(link) && publishType ==
Meta::PublishDelete, which we should ignore
=======================================
--- /branches/lfu/clienthandler.h Fri May 24 23:06:39 2013
+++ /branches/lfu/clienthandler.h Wed Jun 26 16:09:00 2013
@@ -78,8 +78,8 @@
void processClientRequest();
void sendResultsOnActivePolls();

- QString filteredMetadata(const QList<Meta>& metaList, const QString&
filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error);
- QString filteredMetadata(const Meta& meta, const QString& filter,
const QMap<QString, QString>& searchNamespaces, MapRequest::RequestError
&error);
+ QString filteredMetadata(const QList<Meta>& metaList, const
MetadataFilter& filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error);
+ QString filteredMetadata(const Meta& meta, const MetadataFilter&
filter, const QMap<QString, QString>& searchNamespaces,
MapRequest::RequestError &error);

void collectSearchGraphMetadata(Subscription &sub,
SearchResult::ResultType resultType, MapRequest::RequestError
&operationError);
void addUpdateAndDeleteMetadata(Subscription &sub,
SearchResult::ResultType resultType, const QSet<Id>& idList, const
QSet<Link>& linkList, MapRequest::RequestError &operationError);
=======================================
--- /branches/lfu/clientparser.cpp Fri May 24 23:06:39 2013
+++ /branches/lfu/clientparser.cpp Wed Jun 26 16:09:00 2013
@@ -801,11 +801,11 @@
specifies a max-size that exceeds what the MAP Server can support,
the MAP Server MUST enforce its own maximum size constraints.
*/
- long maxSize = IFMAP_MAX_SIZE;
+ long long maxSize = IFMAP_MAX_SIZE;
if (attrs.hasAttribute("max-size")) {
QString ms = attrs.value("max-size").toString();
bool ok;
- maxSize = ms.toLong(&ok);
+ maxSize = ms.toLongLong(&ok);
if (ok) {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got search
parameter max-size:" << maxSize;
@@ -837,10 +837,10 @@
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got search
parameter match-links:" << matchLinks;
}
- search.setMatchLinks(Subscription::translateFilter(matchLinks));
+ search.setMatchLinks(matchLinks);
} else {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter match-links:" << search.matchLinks();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter match-links:" << search.matchLinks().str();
}
}

@@ -849,10 +849,10 @@
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
qDebug() << __PRETTY_FUNCTION__ << ":" << "Got search
parameter result-filter:" << resultFilter;
}
-
search.setResultFilter(Subscription::translateFilter(resultFilter));
+ search.setResultFilter(resultFilter);
} else {
if
(_omapdConfig->valueFor("debug_level").value<OmapdConfig::IfmapDebugOptions>().testFlag(OmapdConfig::ShowXMLParsing))
{
- qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter result-filter:" << search.resultFilter();
+ qDebug() << __PRETTY_FUNCTION__ << ":" << "Using default
search parameter result-filter:" << search.resultFilter().str();
}
}

=======================================
--- /branches/lfu/maprequest.cpp Fri Sep 30 14:51:53 2011
+++ /branches/lfu/maprequest.cpp Wed Jun 26 16:09:00 2013
@@ -250,16 +250,111 @@
this->_publishOperations = other._publishOperations;
}

-SearchType::SearchType()
+MetadataFilter::MetadataFilter(const QString& filterStr)
+ : _filter(""), _simFilter(NULL)
+{
+ setFilter(filterStr);
+}
+
+MetadataFilter::MetadataFilter(const MetadataFilter& other)
+{
+ _simFilter = NULL;
+ *this = other;
+}
+
+MetadataFilter::~MetadataFilter()
+{
+ if(_simFilter != NULL) delete _simFilter;
+}
+
+MetadataFilter& MetadataFilter::operator=(const MetadataFilter& other)
+{
+ _filter = other._filter;
+ if(_simFilter != NULL) delete(_simFilter);
+
+ if(other._simFilter != NULL)
+ {
+ _simFilter = new SimplifiedFilter(*other._simFilter);
+ }
+ else
+ {
+ _simFilter = NULL;
+ }
+
+ return *this;
+}
+
+bool MetadataFilter::operator==(const MetadataFilter& other) const
+{
+ return _filter == other._filter &&
+ (_simFilter == NULL
+ ? other._simFilter == NULL
+ : other._simFilter != NULL && *_simFilter ==
*other._simFilter);
+}
+
+bool MetadataFilter::operator==(const QString& filterStr) const
+{
+ return _filter == filterStr;
+}
+
+// (LFu) this code used be the translateFilter() method in class
Subscription
+void MetadataFilter::setFilter(const QString& ifmapFilter)
+{
+ //const char *fnName = "MetadataFilter::setFilter:";
+
+ /* non-predicate expressions joined by "or" need to be translated
+ into a parenthesized expression separated by "|".
+
+ Examples:
+ meta:ip-mac or scada:node
+ --> (meta:ip-mac | scada:node)
+
+ meta:role[@publisher-id = "myPubId" or name="myRole"] or meta:ip-mac
+ --> (meta:role[@publisher-id = "myPubId" or name="myRole"] |
meta:ip-mac)
+
+ standard XPath does not support predicate expressions that begin
with [; need to add *
+ */
+
+ if(!ifmapFilter.isEmpty() && ifmapFilter != "*")
+ {
+ // (LFu) - determine if the filter looks like "ns-1:elem-1 or ...
or ns-n:elem-n"
+ // and provide simplified metadata matching in this case:
+ QRegExp rx("((\\w|-)+:(\\w|-)+)(\\s+(or|OR)\\s+((\\w|-)+:(\\w|
-)+))*");
+ if(rx.exactMatch(ifmapFilter))
+ {
+ _simFilter = new SimplifiedFilter();
+ // qDebug() << "~~regex matches filter: " << ifmapFilter;
+ int pos = 0;
+ QRegExp rx2("((\\w|-)+):((\\w|-)+)(\\s+(or|OR))?");
+ while ((pos = rx2.indexIn(ifmapFilter, pos)) != -1) {
+ _simFilter->append(QPair<QString, QString>(rx2.cap(1),
rx2.cap(3)));
+ // qDebug() << "~~\tns:" << rx2.cap(1) << " elem:" <<
rx2.cap(3);
+ pos += rx2.matchedLength();
+ }
+ }
+ }
+
+ // TODO: Do this with QRegExp
+ _filter = ifmapFilter;
+ if (ifmapFilter.contains(" or ", Qt::CaseInsensitive)) {
+ //qDebug() << fnName << "WARNING! filter translation is woefully
incomplete!";
+ //qDebug() << fnName << "filter before translation:" <<
ifmapFilter;
+ _filter.replace(" or "," | ");
+ _filter.prepend("(");
+ _filter.append(")");
+ //qDebug() << fnName << "filter after translation:" << qtFilter;
+ }
+}
+
+
+SearchType::SearchType()
+ : _resultFilter("*"), _matchLinks("*") // Intepretation of the spec is
that no match-links attribute matches all links
{
_clientSetMaxDepth = false;
_clientSetMaxSize = false;
_clientSetResultFilter = false;
_clientSetMatchLinks = false;
_clientSetTerminalId = false;
- // Intepretation of the spec is that no match-links attribute matches
all links
- _matchLinks = "*";
- _resultFilter = "*";
_terminalId = "";
}

=======================================
--- /branches/lfu/maprequest.h Fri May 24 23:06:39 2013
+++ /branches/lfu/maprequest.h Wed Jun 26 16:09:00 2013
@@ -238,18 +238,43 @@
};
Q_DECLARE_METATYPE(PublishRequest)

+typedef QList<QPair<QString, QString> > SimplifiedFilter;
+
+class MetadataFilter
+{
+public:
+ MetadataFilter(const QString& filterStr);
+ MetadataFilter(const MetadataFilter& other);
+ ~MetadataFilter();
+
+ MetadataFilter& operator=(const MetadataFilter& other);
+ bool operator==(const MetadataFilter& other) const;
+ bool operator==(const QString& filterStr) const;
+
+ bool isEmpty() const { return _filter.isEmpty(); }
+ bool isSimple() const { return _simFilter != NULL; }
+ const QString& str() const { return _filter; }
+
+ const SimplifiedFilter* getSimplifiedFilter() const { return
_simFilter; }
+ void setFilter(const QString& ifmapFilter);
+
+
+private:
+ QString _filter;
+ SimplifiedFilter* _simFilter;
+};
+
class SearchType
{
public:
SearchType();
int maxDepth() const { return _maxDepth; }
int maxSize() const { return _maxSize; }
- const QString& resultFilter() const { return _resultFilter; }
- const QString& matchLinks() const { return _matchLinks; }
+ const MetadataFilter& resultFilter() const { return _resultFilter; }
+ const MetadataFilter& matchLinks() const { return _matchLinks; }
const QString& terminalId() const { return _terminalId; }
const Id& startId() const { return _startId; }
const QMap<QString, QString>& filterNamespaceDefinitions() const {
return _filterNamespaceDefinitions; }
-
bool clientSetMaxDepth() const { return _clientSetMaxDepth; }
bool clientSetMaxSize() const { return _clientSetMaxSize; }
bool clientSetResultFilter() const { return _clientSetResultFilter; }
@@ -258,8 +283,8 @@

void setMaxDepth(int maxDepth) { _maxDepth = maxDepth;
_clientSetMaxDepth = true; }
void setMaxSize(int maxSize) { _maxSize = maxSize; _clientSetMaxSize =
true; }
- void setResultFilter(const QString& resultFilter) { _resultFilter =
resultFilter; _clientSetResultFilter = true; }
- void setMatchLinks(const QString& matchLinks) { _matchLinks =
matchLinks; _clientSetMatchLinks = true; }
+ void setResultFilter(const QString& resultFilter) {
_resultFilter.setFilter(resultFilter); _clientSetResultFilter = true; }
+ void setMatchLinks(const QString& matchLinks) {
_matchLinks.setFilter(matchLinks); _clientSetMatchLinks = true; }
void setTerminalId(const QString& terminalId) { _terminalId =
terminalId; _clientSetTerminalId = true; }
void setStartId(Id id) { _startId = id; }
void setFilterNamespaceDefinitions(const QMap<QString,QString>&
nsDefs) {_filterNamespaceDefinitions = nsDefs; }
@@ -268,9 +293,9 @@
bool _clientSetMaxDepth;
int _maxSize;
bool _clientSetMaxSize;
- QString _resultFilter;
+ MetadataFilter _resultFilter;
bool _clientSetResultFilter;
- QString _matchLinks;
+ MetadataFilter _matchLinks;
bool _clientSetMatchLinks;
QString _terminalId;
bool _clientSetTerminalId;
=======================================
--- /branches/lfu/subscription.cpp Thu Jun 20 11:23:04 2013
+++ /branches/lfu/subscription.cpp Wed Jun 26 16:09:00 2013
@@ -21,6 +21,7 @@

#include "subscription.h"
#include "mapsessions.h"
+#include <QRegExp>

SearchResult::ResultType
SearchResult::resultTypeForPublishType(Meta::PublishOperationType
publishType)
{
@@ -153,77 +154,98 @@
return false;
}

-QString Subscription::translateFilter(const QString& ifmapFilter)
-{
- //const char *fnName = "SearchGraph::translateFilter:";
+// (LFu) this code is now in MetadataFilter::setFilter()
+//QString Subscription::translateFilter(const QString& ifmapFilter,
SimplifiedFilter& simFilter, bool& canSimplifyMatching)
+//{
+// //const char *fnName = "SearchGraph::translateFilter:";

- /* non-predicate expressions joined by "or" need to be translated
- into a parenthesized expression separated by "|".
+// /* non-predicate expressions joined by "or" need to be translated
+// into a parenthesized expression separated by "|".

- Examples:
- meta:ip-mac or scada:node
- --> (meta:ip-mac | scada:node)
+// Examples:
+// meta:ip-mac or scada:node
+// --> (meta:ip-mac | scada:node)

- meta:role[@publisher-id = "myPubId" or name="myRole"] or meta:ip-mac
- --> (meta:role[@publisher-id = "myPubId" or name="myRole"] |
meta:ip-mac)
+// meta:role[@publisher-id = "myPubId" or name="myRole"] or
meta:ip-mac
+// --> (meta:role[@publisher-id = "myPubId" or name="myRole"] |
meta:ip-mac)

- standard XPath does not support predicate expressions that begin
with [; need to add *
- */
+// standard XPath does not support predicate expressions that begin
with [; need to add *
+// */

- // TODO: Do this with QRegExp
+// // (LFu) - determine if the filter looks like "ns-1:elem-1 or ... or
ns-n:elem-n"
+// // and provide simplified metadata matching in this case:
+// QRegExp rx("((\\w|-)+:(\\w|-)+)(\\s+(or|OR)\\s+((\\w|-)+:(\\w|
-)+))*");
+// if(rx.exactMatch(ifmapFilter))
+// {
+// canSimplifyMatching = true;
+// qDebug() << "~~regex matches filter: " << ifmapFilter;
+// int pos = 0;
+// QRegExp rx2("((\\w|-)+):((\\w|-)+)(\\s+(or|OR))?");
+// while ((pos = rx2.indexIn(ifmapFilter, pos)) != -1) {
+// simFilter.append(QPair<QString, QString>(rx2.cap(1),
rx2.cap(3)));
+// qDebug() << "~~\tns:" << rx2.cap(1) << " elem:" <<
rx2.cap(3);
+// pos += rx2.matchedLength();
+// }
+// }
+// else
+// qDebug() << "~~regex does not match filter: " << ifmapFilter;

- QString qtFilter = ifmapFilter;
- if (ifmapFilter.contains(" or ", Qt::CaseInsensitive)) {
- //qDebug() << fnName << "WARNING! filter translation is woefully
incomplete!";
- //qDebug() << fnName << "filter before translation:" <<
ifmapFilter;
- qtFilter.replace(" or "," | ");
- qtFilter.prepend("(");
- qtFilter.append(")");
- //qDebug() << fnName << "filter after translation:" << qtFilter;
- }

- return qtFilter;
-}
+// // TODO: Do this with QRegExp
+// QString qtFilter = ifmapFilter;
+// if (ifmapFilter.contains(" or ", Qt::CaseInsensitive)) {
+// //qDebug() << fnName << "WARNING! filter translation is woefully
incomplete!";
+// //qDebug() << fnName << "filter before translation:" <<
ifmapFilter;
+// qtFilter.replace(" or "," | ");
+// qtFilter.prepend("(");
+// qtFilter.append(")");
+// //qDebug() << fnName << "filter after translation:" << qtFilter;
+// }

-QString Subscription::intersectFilter(const QString& matchLinksFilter,
const QString& resultFilter)
-{
- /* This method creates an intersect filter for XPath
- as the logical AND combination of the match-links
- filter and the result-filter.
+// return qtFilter;
+//}

- The passed-in filters MUST first individually be translated
- using SearchGraph::translateFilter().
- */
- QString qtFilter = "(";
- qtFilter += matchLinksFilter;
- qtFilter += " intersect ";
- qtFilter += resultFilter;
- qtFilter += ")";
+// (LFu) unused:
+//QString Subscription::intersectFilter(const QString& matchLinksFilter,
const QString& resultFilter)
+//{
+// /* This method creates an intersect filter for XPath
+// as the logical AND combination of the match-links
+// filter and the result-filter.
+
+// The passed-in filters MUST first individually be translated
+// using SearchGraph::translateFilter().
+// */
+// QString qtFilter = "(";
+// qtFilter += matchLinksFilter;
+// qtFilter += " intersect ";
+// qtFilter += resultFilter;
+// qtFilter += ")";

- return qtFilter;
-}
+// return qtFilter;
+//}

-QStringList Subscription::filterPrefixes(const QString& filter)
-{
- // TODO: Improve RegExp to not include colons inside quotes
- // For example: vend:ike-policy[@gateway=1.2.3.4 and
meta:phase1/@identity=name:joe]
- // should not capture the `name' prefix. However, it's only a slight
performance hit
- // to capture these false prefixes, because they won't map to a
declared namespace
- // in the document, or if they do, that's ok too.
- // Here's a possibility for a RegExp that excludes colons inside
quotes, but not quite
- //QRegExp rx("([^\"{0}]\\b\\w+:)");
+// (LFu) unused:
+//QStringList Subscription::filterPrefixes(const QString& filter)
+//{
+// // TODO: Improve RegExp to not include colons inside quotes
+// // For example: vend:ike-policy[@gateway=1.2.3.4 and
meta:phase1/@identity=name:joe]
+// // should not capture the `name' prefix. However, it's only a
slight performance hit
+// // to capture these false prefixes, because they won't map to a
declared namespace
+// // in the document, or if they do, that's ok too.
+// // Here's a possibility for a RegExp that excludes colons inside
quotes, but not quite
+// //QRegExp rx("([^\"{0}]\\b\\w+:)");

- // Look for a word boundary followed by 1 or more word characters up
to a colon
- QRegExp rx("(\\b\\w+:)");
- QStringList prefixes;
+// // Look for a word boundary followed by 1 or more word characters up
to a colon
+// QRegExp rx("(\\b\\w+:)");
+// QStringList prefixes;

- int pos = 0;
- while ((pos = rx.indexIn(filter, pos)) != -1) {
- QString prefix = rx.cap(1);
- prefixes << prefix.left(prefix.length()-1);
- pos += rx.matchedLength();
- }
- //qDebug() << "prefixes:" << prefixes.join("|");
+// int pos = 0;
+// while ((pos = rx.indexIn(filter, pos)) != -1) {
+// QString prefix = rx.cap(1);
+// prefixes << prefix.left(prefix.length()-1);
+// pos += rx.matchedLength();
+// }
+// //qDebug() << "prefixes:" << prefixes.join("|");

- return prefixes;
-}
+// return prefixes;
+//}
=======================================
--- /branches/lfu/subscription.h Thu Jun 20 11:23:04 2013
+++ /branches/lfu/subscription.h Wed Jun 26 16:09:00 2013
@@ -55,6 +55,7 @@
MapRequest::RequestError _error;
};

+
class Subscription
{
public:
@@ -93,9 +94,14 @@

void clearSearchResults();

- static QString translateFilter(const QString& ifmapFilter);
- static QString intersectFilter(const QString& matchLinksFilter, const
QString& resultFilter);
- static QStringList filterPrefixes(const QString& filter);
+ // translates the filter to use with Qt xmlpattern matching
+ // (LFu) the method now determines if the filter is a simple
disjunction of qual. metadata element names
+ // and if so the method will set canSimplifyMatching to true and fills
simFilter with the list of
+ // (namespace prefix/element name) pairs that the filter contains. In
this case the method returns
+ // the empty string.
+// static QString translateFilter(const QString& ifmapFilter,
SimplifiedFilter& simFilter, bool& canSimplifyMatching);
+// static QString intersectFilter(const QString& matchLinksFilter,
const QString& resultFilter);
+// static QStringList filterPrefixes(const QString& filter);
};

#endif // SUBSCRIPTION_H
Reply all
Reply to author
Forward
0 new messages