diff OrthancServer/OrthancFindRequestHandler.cpp @ 1753:faf2ecab3472 db-changes

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 27 Oct 2015 20:31:34 +0100
parents c3d8ec63a179
children 39c37a994b2f
line wrap: on
line diff
--- a/OrthancServer/OrthancFindRequestHandler.cpp	Tue Oct 27 17:45:05 2015 +0100
+++ b/OrthancServer/OrthancFindRequestHandler.cpp	Tue Oct 27 20:31:34 2015 +0100
@@ -338,7 +338,6 @@
 
 #if USE_LOOKUP_RESOURCE != 1
     ResourceFinder finder(context_);
-#endif
 
     switch (level)
     {
@@ -355,26 +354,44 @@
       default:
         throw OrthancException(ErrorCode_InternalError);
     }
+#else
+    size_t maxResults = (level == ResourceType_Instance) ? maxInstances_ : maxResults_;
 
-    std::list<std::string> tmp;
+#endif
 
 #if USE_LOOKUP_RESOURCE == 1
-    bool finished = context_.Apply(tmp, finder);
+    std::vector<std::string> resources, instances;
+    context_.GetIndex().FindCandidates(resources, instances, finder);
 
-    for (std::list<std::string>::const_iterator
-        it = tmp.begin(); it != tmp.end(); ++it)
+    assert(resources.size() == instances.size());
+    bool finished = true;
+
+    for (size_t i = 0; i < instances.size(); i++)
     {
-      // TODO
-      Json::Value resource;
-      context_.ReadJson(resource, *it);
-      AddAnswer(answers, resource, query);
+      Json::Value dicom;
+      context_.ReadJson(dicom, instances[i]);
+      
+      if (finder.IsMatch(dicom))
+      {
+        if (maxResults != 0 &&
+            answers.GetSize() >= maxResults)
+        {
+          finished = false;
+          break;
+        }
+        else
+        {
+          AddAnswer(answers, dicom, query);
+        }
+      }
     }
 
 #else
+    std::list<std::string> tmp;
     bool finished = finder.Apply(tmp, findQuery);
 #endif
 
-    LOG(INFO) << "Number of matching resources: " << tmp.size();
+    LOG(INFO) << "Number of matching resources: " << answers.GetSize();
 
     return finished;
   }