fixed the search methods

This commit is contained in:
fgerlits 2005-01-20 14:11:37 +00:00
parent ab1ed0a009
commit 2a8113a892
10 changed files with 54 additions and 68 deletions

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.2 $ Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/Attic/SearchCriteria.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/Attic/SearchCriteria.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -62,9 +62,9 @@ class TestStorageClient; // forward declaration of friend class
* *
* Its fields are: * Its fields are:
* <ul> * <ul>
* <li>type - mandatory, values in (audioClip | playlist | all)</li> * <li>type - values in (audioClip | playlist | all); the default is
* <li>operator - values in (and | or); * <i>audioClip</i></li>
* optional, default is <i>and</i></li> * <li>operator - values in (and | or); the default is <i>and</i></li>
* <li>condition1 : { key : string, comparison: string, value : string } * <li>condition1 : { key : string, comparison: string, value : string }
* - a search condition, where <i>key</i> is one of the * - a search condition, where <i>key</i> is one of the
* fields in the metadata, and <i>comparison</i> is * fields in the metadata, and <i>comparison</i> is
@ -72,16 +72,17 @@ class TestStorageClient; // forward declaration of friend class
* | "<" | "<=" | ">" | ">=")</li> * | "<" | "<=" | ">" | ">=")</li>
* <li>...</li> * <li>...</li>
* <li>conditionN</li> * <li>conditionN</li>
* <li>limit : int - the maximum number of results to be returned; optional, * <li>limit : int - the maximum number of results to be returned;
* the default is 0, which means there is no limit</li> * the default is 0, which means unlimited</li>
* <li>offset : int - start at the <i>offset</i>+1-th result; optional, * <li>offset : int - ignore the first <i>offset</i> matches;
* the default is 0.</li> * the default is 0.</li>
* </ul> * </ul>
* *
* Usage: construct a SearchCriteria object either directly using the * Usage: construct a SearchCriteria object either directly using the
* constructor with 4 string arguments, or in several steps using the setter * constructor with 4 string arguments, or in several steps using
* methods; then pass this object to Storage::search() to search the local * addCondition() and the setter methods;
* storage. * then pass this object to StorageClientInterface::search()
* to search the local storage.
* *
* The <i>key</i> and <i>value</i> fields are case-sensitive, all the other * The <i>key</i> and <i>value</i> fields are case-sensitive, all the other
* strings (type, operator names) are case-insensitive. * strings (type, operator names) are case-insensitive.

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/include/LiveSupport/Storage/StorageClientInterface.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -67,7 +67,7 @@ using namespace Core;
* An interface for storage clients. * An interface for storage clients.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class StorageClientInterface class StorageClientInterface
{ {
@ -372,7 +372,9 @@ class StorageClientInterface
* *
* @param sessionId the session ID from the authentication client * @param sessionId the session ID from the authentication client
* @param searchCriteria an object containing the search criteria * @param searchCriteria an object containing the search criteria
* @return the number of items found. * @return the number of items found; this may not be equal to the
* number of items returned: see SearchCriteria::setLimit()
* and SearchCriteria::setOffset()
* @exception XmlRpcException if there is a problem with the XML-RPC * @exception XmlRpcException if there is a problem with the XML-RPC
* call. * call.
*/ */

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/Attic/SearchCriteria.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/Attic/SearchCriteria.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -95,7 +95,9 @@ SearchCriteria :: operator XmlRpc::XmlRpcValue() const
XmlRpc::XmlRpcValue returnValue; XmlRpc::XmlRpcValue returnValue;
returnValue["filetype"] = type; returnValue["filetype"] = type;
returnValue["operator"] = logicalOperator; if (searchConditions.size() > 1) {
returnValue["operator"] = logicalOperator;
}
XmlRpc::XmlRpcValue conditionList; XmlRpc::XmlRpcValue conditionList;
conditionList.setSize(searchConditions.size()); conditionList.setSize(searchConditions.size());
@ -110,8 +112,13 @@ SearchCriteria :: operator XmlRpc::XmlRpcValue() const
} }
returnValue["conditions"] = conditionList; returnValue["conditions"] = conditionList;
returnValue["limit"] = limit; if (limit) {
returnValue["offset"] = offset; returnValue["limit"] = limit;
}
if (offset) {
returnValue["offset"] = offset;
}
return returnValue; return returnValue;
} }

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/Attic/SearchCriteriaTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/Attic/SearchCriteriaTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -85,24 +85,15 @@ SearchCriteriaTest :: firstTest(void)
} }
CPPUNIT_ASSERT(xmlRpcValue.hasMember("filetype")); CPPUNIT_ASSERT(xmlRpcValue.hasMember("filetype"));
CPPUNIT_ASSERT(xmlRpcValue["filetype"] == "audioclip"); CPPUNIT_ASSERT(xmlRpcValue["filetype"] == "audioclip");
CPPUNIT_ASSERT(xmlRpcValue.hasMember("operator"));
CPPUNIT_ASSERT(xmlRpcValue["operator"] == "and");
CPPUNIT_ASSERT(xmlRpcValue.hasMember("conditions")); CPPUNIT_ASSERT(xmlRpcValue.hasMember("conditions"));
CPPUNIT_ASSERT(xmlRpcValue["conditions"].getType() CPPUNIT_ASSERT(xmlRpcValue["conditions"].getType()
== XmlRpc::XmlRpcValue::TypeArray); == XmlRpc::XmlRpcValue::TypeArray);
CPPUNIT_ASSERT(xmlRpcValue["conditions"].size() == 0); CPPUNIT_ASSERT(xmlRpcValue["conditions"].size() == 0);
CPPUNIT_ASSERT(xmlRpcValue.hasMember("limit"));
CPPUNIT_ASSERT(xmlRpcValue["limit"].getType()
== XmlRpc::XmlRpcValue::TypeInt);
CPPUNIT_ASSERT(int(xmlRpcValue["limit"]) == 0);
CPPUNIT_ASSERT(xmlRpcValue.hasMember("offset"));
CPPUNIT_ASSERT(xmlRpcValue["offset"].getType()
== XmlRpc::XmlRpcValue::TypeInt);
CPPUNIT_ASSERT(int(xmlRpcValue["offset"]) == 0);
try { try {
SearchCriteria secondCriteria("playlist", "Or"); SearchCriteria secondCriteria("playlist", "Or");
secondCriteria.setLimit(50); secondCriteria.setLimit(50);
secondCriteria.setOffset(100);
secondCriteria.addCondition("dc:title", "PREFIX", "My "); secondCriteria.addCondition("dc:title", "PREFIX", "My ");
secondCriteria.addCondition("DcTerms:Extent", "<", "180"); secondCriteria.addCondition("DcTerms:Extent", "<", "180");
xmlRpcValue = secondCriteria; xmlRpcValue = secondCriteria;
@ -141,7 +132,7 @@ SearchCriteriaTest :: firstTest(void)
CPPUNIT_ASSERT(xmlRpcValue.hasMember("offset")); CPPUNIT_ASSERT(xmlRpcValue.hasMember("offset"));
CPPUNIT_ASSERT(xmlRpcValue["offset"].getType() CPPUNIT_ASSERT(xmlRpcValue["offset"].getType()
== XmlRpc::XmlRpcValue::TypeInt); == XmlRpc::XmlRpcValue::TypeInt);
CPPUNIT_ASSERT(int(xmlRpcValue["offset"]) == 0); CPPUNIT_ASSERT(int(xmlRpcValue["offset"]) == 100);
try { try {
SearchCriteria thirdCriteria("all", "dc:creator", "partial", "X"); SearchCriteria thirdCriteria("all", "dc:creator", "partial", "X");
@ -163,14 +154,5 @@ SearchCriteriaTest :: firstTest(void)
CPPUNIT_ASSERT(condition0["op"] == "partial"); CPPUNIT_ASSERT(condition0["op"] == "partial");
CPPUNIT_ASSERT(condition0.hasMember("val")); CPPUNIT_ASSERT(condition0.hasMember("val"));
CPPUNIT_ASSERT(condition0["val"] == "X"); CPPUNIT_ASSERT(condition0["val"] == "X");
CPPUNIT_ASSERT(xmlRpcValue.hasMember("limit"));
CPPUNIT_ASSERT(xmlRpcValue["limit"].getType()
== XmlRpc::XmlRpcValue::TypeInt);
CPPUNIT_ASSERT(int(xmlRpcValue["limit"]) == 0);
CPPUNIT_ASSERT(xmlRpcValue.hasMember("offset"));
CPPUNIT_ASSERT(xmlRpcValue["offset"].getType()
== XmlRpc::XmlRpcValue::TypeInt);
CPPUNIT_ASSERT(int(xmlRpcValue["offset"]) == 0);
} }

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.32 $ Version : $Revision: 1.33 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -743,13 +743,10 @@ TestStorageClient :: search(Ptr<SessionId>::Ref sessionId,
AudioClipMapType::const_iterator it = audioClipMap.begin(); AudioClipMapType::const_iterator it = audioClipMap.begin();
while (it != audioClipMap.end()) { while (it != audioClipMap.end()) {
if (matchesCriteria(it->second, searchCriteria)) { if (matchesCriteria(it->second, searchCriteria)) {
if (counter >= first) { if (counter >= first && (!last || counter < last)) {
audioClipIds->push_back(it->second->getId()); audioClipIds->push_back(it->second->getId());
} }
++counter; ++counter;
if (last && counter >= last) {
return (counter - first);
}
} }
++it; ++it;
} }
@ -759,19 +756,16 @@ TestStorageClient :: search(Ptr<SessionId>::Ref sessionId,
PlaylistMapType::const_iterator it = playlistMap.begin(); PlaylistMapType::const_iterator it = playlistMap.begin();
while (it != playlistMap.end()) { while (it != playlistMap.end()) {
if (matchesCriteria(it->second, searchCriteria)) { if (matchesCriteria(it->second, searchCriteria)) {
if (counter >= first) { if (counter >= first && (!last || counter < last)) {
playlistIds->push_back(it->second->getId()); playlistIds->push_back(it->second->getId());
} }
++counter; ++counter;
if (last && counter >= last) {
return (counter - first);
}
} }
++it; ++it;
} }
} }
return (counter - first); return counter;
} }

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.26 $ Version : $Revision: 1.27 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -86,7 +86,7 @@ using namespace LiveSupport::Core;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.26 $ * @version $Revision: 1.27 $
*/ */
class TestStorageClient : class TestStorageClient :
virtual public Configurable, virtual public Configurable,
@ -503,7 +503,9 @@ class TestStorageClient :
* *
* @param sessionId the session ID from the authentication client * @param sessionId the session ID from the authentication client
* @param searchCriteria an object containing the search criteria * @param searchCriteria an object containing the search criteria
* @return the number of items found. * @return the number of items found; this may not be equal to the
* number of items returned: see SearchCriteria::setLimit()
* and SearchCriteria::setOffset()
* @exception XmlRpcException if there is a problem with the XML-RPC * @exception XmlRpcException if there is a problem with the XML-RPC
* call. * call.
*/ */

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.23 $ Version : $Revision: 1.24 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -431,7 +431,7 @@ TestStorageClientTest :: searchTest(void)
criteria->setLimit(2); criteria->setLimit(2);
criteria->setOffset(1); criteria->setOffset(1);
int numberFound = tsc->search(dummySessionId, criteria); int numberFound = tsc->search(dummySessionId, criteria);
CPPUNIT_ASSERT(numberFound == 2); CPPUNIT_ASSERT(numberFound == 4);
CPPUNIT_ASSERT(tsc->getAudioClipIds()->size() == 1); CPPUNIT_ASSERT(tsc->getAudioClipIds()->size() == 1);
CPPUNIT_ASSERT(tsc->getAudioClipIds()->at(0)->getId() == 0x10003); CPPUNIT_ASSERT(tsc->getAudioClipIds()->at(0)->getId() == 0x10003);
CPPUNIT_ASSERT(tsc->getPlaylistIds()->size() == 1); CPPUNIT_ASSERT(tsc->getPlaylistIds()->size() == 1);

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.30 $ Version : $Revision: 1.31 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -1947,7 +1947,6 @@ WebStorageClient :: search(Ptr<SessionId>::Ref sessionId,
= sessionId->getId(); = sessionId->getId();
parameters[searchCriteriaParamName] parameters[searchCriteriaParamName]
= *searchCriteria; = *searchCriteria;
// std::cerr << "\nparams: " << parameters.toXml() << "\n";
result.clear(); result.clear();
if (!xmlRpcClient.execute(searchMethodName.c_str(), if (!xmlRpcClient.execute(searchMethodName.c_str(),
@ -1960,7 +1959,6 @@ WebStorageClient :: search(Ptr<SessionId>::Ref sessionId,
} }
xmlRpcClient.close(); xmlRpcClient.close();
// std::cerr << "result: " << result.toXml() << "\n";
if (xmlRpcClient.isFault()) { if (xmlRpcClient.isFault()) {
std::stringstream eMsg; std::stringstream eMsg;
eMsg << "XML-RPC method '" eMsg << "XML-RPC method '"

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.21 $ Version : $Revision: 1.22 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -96,7 +96,7 @@ using namespace LiveSupport::Core;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.21 $ * @version $Revision: 1.22 $
*/ */
class WebStorageClient : class WebStorageClient :
virtual public Configurable, virtual public Configurable,
@ -533,7 +533,9 @@ class WebStorageClient :
* *
* @param sessionId the session ID from the authentication client * @param sessionId the session ID from the authentication client
* @param searchCriteria an object containing the search criteria * @param searchCriteria an object containing the search criteria
* @return the number of items found. * @return the number of items found; this may not be equal to the
* number of items returned: see SearchCriteria::setLimit()
* and SearchCriteria::setOffset()
* @exception XmlRpcException if there is a problem with the XML-RPC * @exception XmlRpcException if there is a problem with the XML-RPC
* call. * call.
*/ */

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.31 $ Version : $Revision: 1.32 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -591,7 +591,6 @@ void
WebStorageClientTest :: searchTest(void) WebStorageClientTest :: searchTest(void)
throw (CPPUNIT_NS::Exception) throw (CPPUNIT_NS::Exception)
{ {
/*
try { try {
wsc->reset(); wsc->reset();
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
@ -615,23 +614,23 @@ WebStorageClientTest :: searchTest(void)
try { try {
Ptr<SearchCriteria>::Ref criteria(new SearchCriteria( Ptr<SearchCriteria>::Ref criteria(new SearchCriteria(
"audioClip", "audioClip",
"dc:title", "prefix", "File")); "dc:title", "prefix", "File "));
int results = wsc->search(sessionId, criteria); int numberFound = wsc->search(sessionId, criteria);
CPPUNIT_ASSERT(results == 2); CPPUNIT_ASSERT(numberFound == 2);
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what()); CPPUNIT_FAIL(e.what());
} }
CPPUNIT_ASSERT(wsc->getAudioClipIds()->size() == 2); CPPUNIT_ASSERT(wsc->getAudioClipIds()->size() == 2);
CPPUNIT_ASSERT(*wsc->getAudioClipIds()->at(0) == *audioClip0); CPPUNIT_ASSERT(*wsc->getAudioClipIds()->at(0) == *audioClip0);
CPPUNIT_ASSERT(*wsc->getAudioClipIds()->at(1) == *audioClip1); CPPUNIT_ASSERT(*wsc->getAudioClipIds()->at(1) == *audioClip2);
try { try {
Ptr<SearchCriteria>::Ref criteria(new SearchCriteria( Ptr<SearchCriteria>::Ref criteria(new SearchCriteria(
"playlist", "or")); "playlist", "or"));
criteria->addCondition("dcterms:extent", ">=", "0"); criteria->addCondition("dcterms:extent", ">=", "0");
criteria->setLimit(10); criteria->setLimit(10);
int results = wsc->search(sessionId, criteria); int numberFound = wsc->search(sessionId, criteria);
CPPUNIT_ASSERT(results == 1); CPPUNIT_ASSERT(numberFound == 1);
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what()); CPPUNIT_FAIL(e.what());
} }
@ -643,6 +642,5 @@ WebStorageClientTest :: searchTest(void)
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
CPPUNIT_FAIL(e.what()); CPPUNIT_FAIL(e.what());
} }
*/
} }