You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by se...@apache.org on 2023/03/20 11:48:52 UTC

svn commit: r1908565 - in /comdev/helpwanted.apache.org/site: listitems.lua tasks.lua

Author: sebb
Date: Mon Mar 20 11:48:52 2023
New Revision: 1908565

URL: http://svn.apache.org/viewvc?rev=1908565&view=rev
Log:
Update to use queryscroll generator

Modified:
    comdev/helpwanted.apache.org/site/listitems.lua
    comdev/helpwanted.apache.org/site/tasks.lua

Modified: comdev/helpwanted.apache.org/site/listitems.lua
URL: http://svn.apache.org/viewvc/comdev/helpwanted.apache.org/site/listitems.lua?rev=1908565&r1=1908564&r2=1908565&view=diff
==============================================================================
--- comdev/helpwanted.apache.org/site/listitems.lua (original)
+++ comdev/helpwanted.apache.org/site/listitems.lua Mon Mar 20 11:48:52 2023
@@ -35,22 +35,21 @@ function handle(r)
 --            if docs and #docs == 1 then
 --                doc = docs[1]
 --            end
-            local json
---          Find all the ids
-            json = elastic.raw {
-                _source = false,
-                size = 250
-            }
-            if json and json.hits and json.hits.hits then
+            local matches = {}
+            local query = {_source = false, size = 250}
+            for json in elastic.scrollquery(query, 'item') do
+                print(#json.hits.hits)
                 for k, v in pairs(json.hits.hits) do
---                  Find the first matching id
---                  Should check for multiple matches, but the original code does not either ...
-                    if string.sub(v._id,1,8) == get.id then
-                        doc = elastic.get('item', v._id)
-                        break
+                    local long = v._id
+                    local short = long:sub(1,8)
+                    if short == get.id then
+                        table.insert(matches, long)
                     end
                 end
             end
+            if #matches == 1 then
+                doc = elastic.get('item', matches[1])
+            end
         else 
             doc = elastic.get('item', get.id)
         end

Modified: comdev/helpwanted.apache.org/site/tasks.lua
URL: http://svn.apache.org/viewvc/comdev/helpwanted.apache.org/site/tasks.lua?rev=1908565&r1=1908564&r2=1908565&view=diff
==============================================================================
--- comdev/helpwanted.apache.org/site/tasks.lua (original)
+++ comdev/helpwanted.apache.org/site/tasks.lua Mon Mar 20 11:48:52 2023
@@ -20,6 +20,17 @@ local JSON = require 'cjson'
 local elastic = require 'lib/elastic'
 local cache = {}
 
+-- find matching short codes
+local function process_results(json, ctx)
+  for k, v in pairs(json.hits.hits) do
+      local long = v._id
+      local short = long:sub(1,8)
+      if short == ctx.id then
+          table.insert(ctx.matches, long)
+      end
+  end
+end
+
 function handle(r)
     r.content_type = "application/json"
     local now = r:clock()
@@ -34,22 +45,21 @@ function handle(r)
 --            if docs and #docs == 1 then
 --                doc = docs[1]
 --            end
-            local json
---          Find all the ids
-            json = elastic.raw {
-                _source = false,
-                size = 250
-            }
-            if json and json.hits and json.hits.hits then
+            local matches = {}
+            local query = {_source = false, size = 250}
+            for json in elastic.scrollquery(query, 'item') do
+                print(#json.hits.hits)
                 for k, v in pairs(json.hits.hits) do
---                  Find the first matching id
---                  Should check for multiple matches, but the original code does not either ...
-                    if string.sub(v._id,1,8) == get.id then
-                        doc = elastic.get('item', v._id)
-                        break
+                    local long = v._id
+                    local short = long:sub(1,8)
+                    if short == get.id then
+                        table.insert(matches, long)
                     end
                 end
             end
+            if #matches == 1 then
+                doc = elastic.get('item', matches[1])
+            end
         else 
             doc = elastic.get('item', get.id)
         end