Răsfoiți Sursa

fix search part

잉여개발기 (SPDV) 3 ani în urmă
părinte
comite
920efda0e3
7 a modificat fișierele cu 70 adăugiri și 35 ștergeri
  1. 3 0
      app.py
  2. 3 0
      lang/en-US.json
  3. 3 1
      lang/ko-KR.json
  4. 27 31
      route/main_search_deep.py
  5. 23 0
      route/tool/func.py
  6. 10 2
      route/view_read.py
  7. 1 1
      version.json

+ 3 - 0
app.py

@@ -616,6 +616,9 @@ app.route('/manager/<int:num>/<add_2>', methods = ['POST', 'GET'])(main_tool_red
 
 app.route('/search', methods=['POST'])(main_search)
 app.route('/search/<everything:name>')(main_search_deep)
+app.route('/search/<int:num>/<everything:name>')(main_search_deep)
+app.route('/search_data/<everything:name>', defaults = { 'search_type' : 'data' })(main_search_deep)
+app.route('/search_data/<int:num>/<everything:name>', defaults = { 'search_type' : 'data' })(main_search_deep)
 app.route('/goto', methods=['POST'])(main_search_goto)
 app.route('/goto/<everything:name>', methods=['POST'])(main_search_goto)
 

+ 3 - 0
lang/en-US.json

@@ -227,6 +227,9 @@
         "user_title" : "User title",
         "multiple_ban" : "Multiple ban",
     	"dont_move" : "Don't move",
+        "_comment_" : "Search",
+            "search_document_name" : "Search document name",
+            "search_document_data" : "Search document data",
         "_comment_2.1_" : "Filter",
             "_comment_2.1.1_" : "List",
                 "interwiki_list" : "Interwiki(s) list",

+ 3 - 1
lang/ko-KR.json

@@ -460,5 +460,7 @@
     "stiemap_exclude_domain": "도메인 제외",
     "stiemap_exclude_user_page": "사용자 문서 제외",
     "stiemap_exclude_file_page": "파일 문서 제외",
-    "stiemap_exclude_category_page": "분류 문서 제외"
+    "stiemap_exclude_category_page": "분류 문서 제외",
+    "search_document_name": "문서명 검색",
+    "search_document_data": "문서 내용 검색"
 }

+ 27 - 31
route/main_search_deep.py

@@ -1,24 +1,35 @@
 from .tool.func import *
 
-def main_search_deep(name = 'Test'):
+def main_search_deep(name = 'Test', search_type = 'title', num = 1):
     with get_db_connect() as conn:
         curs = conn.cursor()
 
         if name == '':
             return redirect()
 
-        num = int(number_check(flask.request.args.get('num', '1')))
         sql_num = (num * 50 - 50) if num * 50 > 0 else 0
 
-        div = '<ul class="inside_ul">'
+        div = ''
+        if search_type == 'title':
+            div += '<a href="/search_data/1/' + url_pas(name) + '">(' + load_lang('search_document_data') + ')</a>'
+        else:
+            div += '<a href="/search/1/' + url_pas(name) + '">(' + load_lang('search_document_name') + ')</a>'
+
+        name_new = ''
+        if re.search(r'^분류:', name):
+            name_new = re.sub(r"^분류:", 'category:', name)
+        elif re.search(r"^사용자:", name):
+            name_new = re.sub(r"^사용자:", 'user:', name)
+        elif re.search(r"^파일:", name):
+            name_new = re.sub(r"^파일:", 'file:', name)
 
-        div_plus = ''
-        test = ''
+        if name_new != '':
+            div += ' <a href="/search/1/' + url_pas(name_new) + '">(' + name_new + ')</a>'
 
         curs.execute(db_change("select title from data where title = ?"), [name])
         link_id = '' if curs.fetchall() else 'id="not_thing"'
 
-        div = '''
+        div += '''
             <ul class="inside_ul">
                 <li>
                     <a ''' + link_id + ' href="/w/' + url_pas(name) + '">' + html.escape(name) + '''</a>
@@ -28,36 +39,21 @@ def main_search_deep(name = 'Test'):
             <ul class="inside_ul">
         '''
 
-        curs.execute(db_change('select data from other where name = "count_all_title"'))
-        if int(curs.fetchall()[0][0]) < 30000:
-            curs.execute(db_change("" + \
-                "select distinct title, case " + \
-                "when title like ? then 'title' else 'data' end from data " + \
-                "where (title like ? or data like ?) order by case " + \
-                "when title like ? then 1 else 2 end limit ?, 50"),
-                ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', sql_num]
+        if search_type == 'title':
+            curs.execute(db_change("select title from data where title like ? order by title limit ?, 50"),
+                ['%' + name + '%', sql_num]
             )
-            all_list = curs.fetchall()
-            if all_list:
-                test = all_list[0][1]
-
-                for data in all_list:
-                    if data[1] != test:
-                        div_plus += '</ul><hr class="main_hr"><ul class="inside_ul">'
-
-                        test = data[1]
-
-                    div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + html.escape(data[0]) + '</a> (' + data[1] + ')</li>'
         else:
-            curs.execute(db_change("select title from data where title like ? order by title limit ?, 50"),
+            curs.execute(db_change("select title from data where data like ? order by title limit ?, 50"),
                 ['%' + name + '%', sql_num]
             )
-            all_list = curs.fetchall()
-            for data in all_list:
-                div_plus += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a> (title)</li>'
 
-        div += div_plus + '</ul>'
-        div += next_fix('/search/' + url_pas(name) + '?num=', num, all_list)
+        all_list = curs.fetchall()
+        for data in all_list:
+            div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a></li>'
+
+        div += '</ul>'
+        div += get_next_page_bottom('/search/{}/' + url_pas(name), num, all_list)
 
         return easy_minify(flask.render_template(skin_check(),
             imp = [name, wiki_set(), wiki_custom(), wiki_css(['(' + load_lang('search') + ')', 0])],

+ 23 - 0
route/tool/func.py

@@ -708,6 +708,29 @@ def http_warning():
         <span style="display: none;" id="opennamu_http_warning_text_lang">''' + load_lang('http_warning') + '''</span>
     '''
 
+def get_next_page_bottom(link, num, page, end = 50):
+    list_data = ''
+
+    if num == 1:
+        if len(page) == end:
+            list_data += '' + \
+                '<hr class="main_hr">' + \
+                '<a href="' + link.format(str(num + 1)) + '">(' + load_lang('next') + ')</a>' + \
+            ''
+    elif len(page) != end:
+        list_data += '' + \
+            '<hr class="main_hr">' + \
+            '<a href="' + link.format(str(num - 1)) + '">(' + load_lang('previous') + ')</a>' + \
+        ''
+    else:
+        list_data += '' + \
+            '<hr class="main_hr">' + \
+            '<a href="' + link.format(str(num - 1)) + '">(' + load_lang('previous') + ')</a> ' + \
+            '<a href="' + link.format(str(num + 1)) + '">(' + load_lang('next') + ')</a>' + \
+        ''
+
+    return list_data
+
 def next_fix(link, num, page, end = 50):
     list_data = ''
 

+ 10 - 2
route/view_read.py

@@ -15,7 +15,7 @@ def view_read(name = 'Test', doc_rev = 0, doc_from = '', do_type = ''):
             
         uppage = re.sub(r"/([^/]+)$", '', name)
         uppage = 0 if uppage == name else uppage
-        num = str(doc_rev)        
+        num = str(doc_rev)
 
         curs.execute(db_change("select sub from rd where title = ? and not stop = 'O' order by date desc"), [name])
         topic = 1 if curs.fetchall() else 0
@@ -24,6 +24,8 @@ def view_read(name = 'Test', doc_rev = 0, doc_from = '', do_type = ''):
         down = 1 if curs.fetchall() else 0
 
         if re.search(r'^category:', name):
+            name_view = name
+
             category_doc = ''
             category_sub = ''
 
@@ -41,6 +43,8 @@ def view_read(name = 'Test', doc_rev = 0, doc_from = '', do_type = ''):
             if category_sub != '':
                 category_doc += '<h2 id="cate_under">' + load_lang('under_category') + '</h2><ul class="inside_ul">' + category_sub + '</ul>'
         elif re.search(r"^user:([^/]*)", name):
+            name_view = name
+
             match = re.search(r"^user:([^/]*)", name)
             
             user_name = html.escape(match.group(1))
@@ -72,6 +76,8 @@ def view_read(name = 'Test', doc_rev = 0, doc_from = '', do_type = ''):
             if name == 'user:' + user_name:
                 menu += [['w/' + url_pas(name) + '/' + url_pas(get_time().split()[0]), load_lang('today_doc')]]
         elif re.search(r"^file:", name):
+            name_view = name
+
             mime_type = re.search(r'([^.]+)$', name)
             if mime_type:
                 mime_type = mime_type.group(1).lower()
@@ -98,6 +104,8 @@ def view_read(name = 'Test', doc_rev = 0, doc_from = '', do_type = ''):
                 menu += [['delete_file/' + url_pas(name), load_lang('file_delete')]]
             else:
                 file_data = ''
+        else:
+            name_view = name
 
         if num != '0':
             curs.execute(db_change("select title from history where title = ? and id = ? and hide = 'O'"), [name, num])
@@ -216,7 +224,7 @@ def view_read(name = 'Test', doc_rev = 0, doc_from = '', do_type = ''):
             watch_list = 0
 
         return easy_minify(flask.render_template(skin_check(),
-            imp = [name, wiki_set(), wiki_custom(), wiki_css([sub, r_date, watch_list])],
+            imp = [name_view, wiki_set(), wiki_custom(), wiki_css([sub, r_date, watch_list])],
             data = div,
             menu = menu
         )), response_data

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.5 (stable2) (beta3) (dev42)",
+        "r_ver" : "v3.4.5 (stable2) (beta3) (dev43)",
         "c_ver" : "3500113",
         "s_ver" : "3500110"
     }