Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

25
LINES

< > BotCompany Repo | #45 // Search engine v1

Lua code

1  
-- variable input: search term
2  
-- variable snippets: array with all snippets (as delivered by http://tinybrain.de:8080/tb-int/allsnippets.php)
3  
-- returns: array of matching snippets
4  
--   best matches first (well, smarter search engines would do that)
5  
--
6  
-- if we also get the snippet texts, we will match those too.
7  
-- but that is a lot of data...
8  
9  
found = {}
10  
foundLevelTwo = {}
11  
12  
input = input:lower()
13  
for _, s in ipairs(snippets.snippets) do
14  
  if s.name:lower():find(input, 1, true) or s.id == input or ("#"..s.id) == input then
15  
    table.insert(found, s)
16  
  elseif s.text and s.text:lower():find(input, 1, true) then
17  
    table.insert(foundLevelTwo, s)
18  
  end
19  
end
20  
21  
-- merge two lists
22  
for _, s in ipairs(foundLevelTwo) do table.insert(found, s) end
23  
24  
-- return
25  
return found

Author comment

TODO: changes case of snippet names according to input (wtf?)

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
704 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
-- variable input: search term
-- variable snippets: array with all snippets (as delivered by http://tinybrain.de:8080/tb-int/allsnippets.php)
-- returns: array of matching snippets
-- best matches first (well, smarter search engines would do that)
--
-- if we also get the snippet texts, we will match those too.
-- but that is a lot of data...

found = {}
foundLevelTwo = {}

input = input:lower()
for _, s in ipairs(snippets.snippets) do
if s.name:lower():find(input, 1, true) or s.id == input or ("#"..s.id) == input then
table.insert(found, s)
elseif s.text and s.text:lower():find(input, 1, true) then
table.insert(foundLevelTwo, s)
end
end

-- merge two lists
for _, s in ipairs(foundLevelTwo) do table.insert(found, s) end

-- return
return found
}}
2015-08-19 09:47:31  delete 
702 #1000604 (pitcher) 2015-08-18 00:07:22

add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 755 [visualize]

Snippet ID: #45
Snippet name: Search engine v1
Eternal ID of this version: #45/1
Text MD5: 861c71c57b3327a907506461831fb6f4
Author: stefan
Category: searching
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-17 18:52:42
Source code size: 794 bytes / 25 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1624 / 5250
Referenced in: [show references]