OSDN Git Service

search better
authoryamat0jp <yamat0jp@yahoo.co.jp>
Tue, 22 Nov 2016 12:25:04 +0000 (21:25 +0900)
committeryamat0jp <yamat0jp@yahoo.co.jp>
Tue, 22 Nov 2016 12:25:04 +0000 (21:25 +0900)
__pycache__/index.cpython-35.pyc
index.py
static/db/db.json

index b61db88..ed4ad64 100644 (file)
Binary files a/__pycache__/index.cpython-35.pyc and b/__pycache__/index.cpython-35.pyc differ
index 867e878..db18789 100755 (executable)
--- a/index.py
+++ b/index.py
@@ -276,27 +276,37 @@ class SearchHandler(tornado.web.RequestHandler):
         self.render('modules/search.htm',records=[],word1=word,db=dbname)
         
     def search(self,name):
-        table = self.application.db.table(name)
-        mem = TinyDB(storage=MemoryStorage)
-        for word in self.word.split():
-            for x in table.search(where('comment').search(word)):
-                if self.radiobox == 'comment':
-                    result = ''
-                    for text in x['raw'].splitlines(True):                  
+        table = self.application.db.table(name)    
+        element = self.word.split()
+        if len(element) == 0:
+            element = ['']
+        while len(element) < 3:
+            element.append(element[0])
+        if self.radiobox == 'comment':
+            query = (Query()[self.radiobox].search(element[0])) | (Query()[self.radiobox].search(element[1])) | (Query()[self.radiobox].search(element[2]))
+        else:
+            query = (Query()[self.radiobox] == element[0]) | (Query()[self.radiobox] == element[1]) | (Query()[self.radiobox] == element[2])
+        if self.radiobox == 'comment':
+            rec = []
+            mem = TinyDB(storage=MemoryStorage)            
+            for x in table.search(query):
+                result = ''
+                for text in x['raw'].splitlines(True):                  
+                    for word in self.word.split():                        
                         if text.find(word) > -1:
-                            result = result+'<p style=background-color:yellow>'+text+'</p>'                            
-                        else:
-                            result = result+'<p>'+text+'</p>'
-                    if mem.get(where('number') == x['number']) == None:
-                        i = mem.insert(x)
-                        mem.update({'comment':result},eids=[i])   
-                else:
-                    rec = table.search(where('name').search(word))
-                    return sorted(rec,key=lambda x: x['number'])     
-        rec = sorted(mem.all(),key=lambda x: x['number'])
-        mem.close()
-        return rec
-                                            
+                            result = result+'<p style=background-color:yellow>'+text+'<br></p>'  
+                            break                          
+                    else:
+                        result = result+'<p>'+text+'<br></p>'
+                i = mem.insert(x)
+                mem.update({'comment':result},eids=[i])   
+                rec = sorted(mem.all(),key=lambda x: x['number'])
+            mem.close()
+            return rec        
+        else:
+            rec = table.search(query)
+            return sorted(rec,key=lambda x: x['number'])   
+                                        
 class FooterModule(tornado.web.UIModule):
     def render(self,number,url,link):
         return self.render_string('modules/footer.htm',index=number,url=url,link=link)
index 6f199c2..667e8af 100644 (file)
@@ -1 +1 @@
-{"bbs3": {}, "bbs1": {}, "_default": {"1": {"kinds": "conf", "title": "pybbs", "out_words": ["\u6b7b\u306d", "\u963f\u5446", "\u30a2\u30db", "\u99ac\u9e7f", "\u30d0\u30ab"], "mentenance": false, "title2": "<h1 style=color:gray;text-align:center>pybbs</h1>", "count": 30, "bad_words": ["<style", "<link", "<script", "<img"], "password": "admin"}}, "bbs": {"1": {"title": "\u3053\u306eBBS\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u3002\u3002\uff20\uff20\uff1b", "comment": "<p>\u3053\u306e\u63b2\u793a\u677f\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u4f55\u304c\u3059\u3054\u3044\u306e\u304b\u5229\u7528\u8005\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u3001\u7ba1\u7406\u8005\u306f\u7ba1\u7406\u304c\u3057\u3084\u3059\u3044\u3067\u3059\u3002\u7c21\u5358\u306b\u904b\u7528\u3067\u304d\u307e\u3059\u3002heroku\u3067git\u3059\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30af\u30ea\u30a2\u3057\u3066\u3059\u3050\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002\u6c17\u306b\u3057\u306a\u3044\u4eba\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002\r\n<br></p><p>\u3000tornado\u3092\u4f7f\u7528\u3057\u3066\u66f8\u304b\u308c\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u5927\u5909\u7c21\u7d20\u3067\u3059\u3002\u306a\u304a\u304b\u3064\u30d6\u30ed\u30b0\u30b7\u30b9\u30c6\u30e0\u306b\u30a2\u30c3\u30d7\u304c\u30b0\u30ec\u30fc\u30c9\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\r\n<br></p><p>\u3000\u63b2\u793a\u677f\u306e\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u62e1\u5f35\u3067\u3059\u304c\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u8ffd\u52a0\u306f\u7ba1\u7406\u8005\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8ffd\u52a0\u3057\u305f\u3044URL\u3092\u6253\u3061\u8fbc\u3080\u3060\u3051\u3002\u305d\u3046\u3059\u308c\u3070\u81ea\u52d5\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u308c\u307e\u3059\u3002\r\n<br></p><p>\u3000\u3055\u3042\u4f7f\u3044\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u304b\u3002<br></p>", "raw": "\u3053\u306e\u63b2\u793a\u677f\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u4f55\u304c\u3059\u3054\u3044\u306e\u304b\u5229\u7528\u8005\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u3001\u7ba1\u7406\u8005\u306f\u7ba1\u7406\u304c\u3057\u3084\u3059\u3044\u3067\u3059\u3002\u7c21\u5358\u306b\u904b\u7528\u3067\u304d\u307e\u3059\u3002heroku\u3067git\u3059\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30af\u30ea\u30a2\u3057\u3066\u3059\u3050\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002\u6c17\u306b\u3057\u306a\u3044\u4eba\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002\r\n\u3000tornado\u3092\u4f7f\u7528\u3057\u3066\u66f8\u304b\u308c\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u5927\u5909\u7c21\u7d20\u3067\u3059\u3002\u306a\u304a\u304b\u3064\u30d6\u30ed\u30b0\u30b7\u30b9\u30c6\u30e0\u306b\u30a2\u30c3\u30d7\u304c\u30b0\u30ec\u30fc\u30c9\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\r\n\u3000\u63b2\u793a\u677f\u306e\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u62e1\u5f35\u3067\u3059\u304c\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u8ffd\u52a0\u306f\u7ba1\u7406\u8005\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8ffd\u52a0\u3057\u305f\u3044URL\u3092\u6253\u3061\u8fbc\u3080\u3060\u3051\u3002\u305d\u3046\u3059\u308c\u3070\u81ea\u52d5\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u308c\u307e\u3059\u3002\r\n\u3000\u3055\u3042\u4f7f\u3044\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u304b\u3002", "date": "2016/11/22 19:43", "name": "\u7ba1\u7406\u8005", "number": 1, "password": "admin"}}, "bbs2": {}}
\ No newline at end of file
+{"bbs1": {"1": {"date": "2016/11/22 20:45", "number": 1, "raw": "test\r\n\r\ntext", "password": "admin", "title": "bbs1", "comment": "<p>test\r\n<br></p><p>\r\n<br></p><p>text<br></p>", "name": "\u7ba1\u7406\u8005"}, "2": {"date": "2016/11/22 20:46", "number": 2, "raw": "first", "password": "admin", "title": "bbs1", "comment": "<p>first<br></p>", "name": "me"}, "3": {"date": "2016/11/22 21:22", "number": 3, "raw": "tt", "password": "admin", "title": "bbs1", "comment": "<p>tt<br></p>", "name": "me"}}, "bbs": {"1": {"date": "2016/11/22 19:43", "number": 1, "raw": "\u3053\u306e\u63b2\u793a\u677f\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u4f55\u304c\u3059\u3054\u3044\u306e\u304b\u5229\u7528\u8005\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u3001\u7ba1\u7406\u8005\u306f\u7ba1\u7406\u304c\u3057\u3084\u3059\u3044\u3067\u3059\u3002\u7c21\u5358\u306b\u904b\u7528\u3067\u304d\u307e\u3059\u3002heroku\u3067git\u3059\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30af\u30ea\u30a2\u3057\u3066\u3059\u3050\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002\u6c17\u306b\u3057\u306a\u3044\u4eba\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002\r\n\u3000tornado\u3092\u4f7f\u7528\u3057\u3066\u66f8\u304b\u308c\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u5927\u5909\u7c21\u7d20\u3067\u3059\u3002\u306a\u304a\u304b\u3064\u30d6\u30ed\u30b0\u30b7\u30b9\u30c6\u30e0\u306b\u30a2\u30c3\u30d7\u304c\u30b0\u30ec\u30fc\u30c9\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\r\n\u3000\u63b2\u793a\u677f\u306e\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u62e1\u5f35\u3067\u3059\u304c\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u8ffd\u52a0\u306f\u7ba1\u7406\u8005\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8ffd\u52a0\u3057\u305f\u3044URL\u3092\u6253\u3061\u8fbc\u3080\u3060\u3051\u3002\u305d\u3046\u3059\u308c\u3070\u81ea\u52d5\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u308c\u307e\u3059\u3002\r\n\u3000\u3055\u3042\u4f7f\u3044\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u304b\u3002", "password": "admin", "title": "\u3053\u306eBBS\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u3002\u3002\uff20\uff20\uff1b", "comment": "<p>\u3053\u306e\u63b2\u793a\u677f\u306f\u3059\u3054\u3044\u3067\u3059\u3002\u4f55\u304c\u3059\u3054\u3044\u306e\u304b\u5229\u7528\u8005\u306b\u306f\u308f\u304b\u3089\u306a\u3044\u3067\u3057\u3087\u3046\u3051\u308c\u3069\u3001\u7ba1\u7406\u8005\u306f\u7ba1\u7406\u304c\u3057\u3084\u3059\u3044\u3067\u3059\u3002\u7c21\u5358\u306b\u904b\u7528\u3067\u304d\u307e\u3059\u3002heroku\u3067git\u3059\u308c\u3070\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u30af\u30ea\u30a2\u3057\u3066\u3059\u3050\u4f7f\u3048\u308b\u72b6\u614b\u306b\u306a\u308a\u307e\u3059\u3002\u6c17\u306b\u3057\u306a\u3044\u4eba\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002\r\n<br></p><p>\u3000tornado\u3092\u4f7f\u7528\u3057\u3066\u66f8\u304b\u308c\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304c\u5927\u5909\u7c21\u7d20\u3067\u3059\u3002\u306a\u304a\u304b\u3064\u30d6\u30ed\u30b0\u30b7\u30b9\u30c6\u30e0\u306b\u30a2\u30c3\u30d7\u304c\u30b0\u30ec\u30fc\u30c9\u3055\u305b\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002\r\n<br></p><p>\u3000\u63b2\u793a\u677f\u306e\u7ba1\u7406\u306b\u5fc5\u8981\u306a\u62e1\u5f35\u3067\u3059\u304c\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u8ffd\u52a0\u306f\u7ba1\u7406\u8005\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u8ffd\u52a0\u3057\u305f\u3044URL\u3092\u6253\u3061\u8fbc\u3080\u3060\u3051\u3002\u305d\u3046\u3059\u308c\u3070\u81ea\u52d5\u3067\u4f5c\u6210\u3055\u308c\u305f\u65b0\u3057\u3044\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u304f\u308c\u307e\u3059\u3002\r\n<br></p><p>\u3000\u3055\u3042\u4f7f\u3044\u305f\u304f\u306a\u308a\u307e\u3057\u305f\u304b\u3002<br></p>", "name": "\u7ba1\u7406\u8005"}}, "bbs3": {}, "bbs2": {}, "_default": {"1": {"bad_words": ["<style", "<link", "<script", "<img"], "count": 30, "mentenance": false, "password": "admin", "title": "pybbs", "kinds": "conf", "title2": "<h1 style=color:gray;text-align:center>pybbs</h1>", "out_words": ["\u6b7b\u306d", "\u963f\u5446", "\u30a2\u30db", "\u99ac\u9e7f", "\u30d0\u30ab"]}}}
\ No newline at end of file