From 8af26de05185817225c131e0f4791f9dd19c2189 Mon Sep 17 00:00:00 2001 From: kim-ec <kim-ec@agentec.jp> Date: Tue, 27 Oct 2020 18:16:43 +0900 Subject: [PATCH] #39714 andやor検索(未入力検索修正) --- abvw/js/contentsearch.js | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------- abvw/js/header.js | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------ 2 files changed, 167 insertions(+), 166 deletions(-) diff --git a/abvw/js/contentsearch.js b/abvw/js/contentsearch.js index 87bb57e..09b872b 100644 --- a/abvw/js/contentsearch.js +++ b/abvw/js/contentsearch.js @@ -1041,101 +1041,102 @@ CONTENTSEARCH.searchEventButtonFunction = function() { alert('200字以下のテキストを入力してください'); return; } + if ($('#txtSearch').val() != '') { + try{ + //seperate string + var myRegexp = /[^\s"]+|"([^"]*)"/gi; + var myArray = []; + var myQuery; + var myRegExpArr = []; + var count = 0; + + do { + var match = myRegexp.exec($('#txtSearchWs').val()); + if (match != null) + { + myArray.push(match[1] ? match[1] : match[0]); + } + } while (match != null); - try{ - //seperate string - var myRegexp = /[^\s"]+|"([^"]*)"/gi; - var myArray = []; - var myQuery; - var myRegExpArr = []; - var count = 0; - - do { - var match = myRegexp.exec($('#txtSearchWs').val()); - if (match != null) - { - myArray.push(match[1] ? match[1] : match[0]); - } - } while (match != null); - - if(myArray[0].charAt(0) == "("){ - if(myArray[0] == "("){ - myRegExpArr[1] = new RegExp(myArray[1]); - myQuery = '( true'; + if(myArray[0].charAt(0) == "("){ + if(myArray[0] == "("){ + myRegExpArr[1] = new RegExp(myArray[1]); + myQuery = '( true'; + }else{ + myRegExpArr[0] = new RegExp(myArray[0].slice(1)); + myQuery = '( true' + count++; + } }else{ - myRegExpArr[0] = new RegExp(myArray[0].slice(1)); - myQuery = '( true' + myRegExpArr[0] = new RegExp(myArray[0]); + myQuery = 'true'; count++; } - }else{ - myRegExpArr[0] = new RegExp(myArray[0]); - myQuery = 'true'; - count++; - } - for (var i = 1; i < myArray.length; i++){ - if(myArray[i] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i]); - }else if(myArray[i].charAt(0) == "(" || myArray[i] == "("){ - if(myArray[i] == "("){ - if(myArray[i - 1] == "OR"){ - myQuery += ' || ('; + for (var i = 1; i < myArray.length; i++){ + if(myArray[i] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i]); + }else if(myArray[i].charAt(0) == "(" || myArray[i] == "("){ + if(myArray[i] == "("){ + if(myArray[i - 1] == "OR"){ + myQuery += ' || ('; + }else{ + myQuery += ' && ('; + } }else{ - myQuery += ' && ('; + if(myArray[i - 1] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i].slice(1)); + myQuery += ' || ( true'; + count++; + }else{ + myRegExpArr[i] = new RegExp(myArray[i].slice(1)); + myQuery += ' && ( true'; + count++; + } } - }else{ - if(myArray[i - 1] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i].slice(1)); - myQuery += ' || ( true'; - count++; + }else if(myArray[i].charAt(myArray[i].length - 1) == ")" || myArray[i] == ")"){ + if(myArray[i] == ")"){ + myQuery += ' )'; }else{ - myRegExpArr[i] = new RegExp(myArray[i].slice(1)); - myQuery += ' && ( true'; - count++; + if(myArray[i - 1] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); + myQuery += ' || true )'; + count++; + }else{ + myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); + myQuery += ' && true )'; + count++; + } } - } - }else if(myArray[i].charAt(myArray[i].length - 1) == ")" || myArray[i] == ")"){ - if(myArray[i] == ")"){ - myQuery += ' )'; }else{ if(myArray[i - 1] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); - myQuery += ' || true )'; - count++; - }else{ - myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); - myQuery += ' && true )'; - count++; - } - } - }else{ - if(myArray[i - 1] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i]); - myQuery += ' || true'; - count++; - }else{ - if(myArray[i - 1] == "("){ myRegExpArr[i] = new RegExp(myArray[i]); - myQuery += ' true'; - count++; + myQuery += ' || true'; + count++; }else{ - myRegExpArr[i] = new RegExp(myArray[i]); - myQuery += ' && true'; - count++; + if(myArray[i - 1] == "("){ + myRegExpArr[i] = new RegExp(myArray[i]); + myQuery += ' true'; + count++; + }else{ + myRegExpArr[i] = new RegExp(myArray[i]); + myQuery += ' && true'; + count++; + } } } } - } - if (eval(myQuery)) { - //is not correct query - } + if (eval(myQuery)) { + //is not correct query + } - }catch(error){ - alert('正しくない検索です'); - return; + }catch(error){ + alert('正しくない検索です'); + return; + } } - + if(count > 5){ alert('語句数は最大5つです'); return; diff --git a/abvw/js/header.js b/abvw/js/header.js index 3ba041c..cb5b90e 100644 --- a/abvw/js/header.js +++ b/abvw/js/header.js @@ -269,101 +269,101 @@ HEADER.searchHeaderButtonFunction = function(){ alert('200字以下のテキストを入力してください'); return; } - - try{ - //seperate string - var myRegexp = /[^\s"]+|"([^"]*)"/gi; - var myArray = []; - var myQuery; - var myRegExpArr = []; - var count = 0; - - do { - var match = myRegexp.exec($('#searchbox-key').val()); - if (match != null) - { - myArray.push(match[1] ? match[1] : match[0]); - } - } while (match != null); - - if(myArray[0].charAt(0) == "("){ - if(myArray[0] == "("){ - myRegExpArr[1] = new RegExp(myArray[1]); - myQuery = '( true'; - }else{ - myRegExpArr[0] = new RegExp(myArray[0].slice(1)); - myQuery = '( true' + if ($('#txtSearch').val() != '') { + try{ + //seperate string + var myRegexp = /[^\s"]+|"([^"]*)"/gi; + var myArray = []; + var myQuery; + var myRegExpArr = []; + var count = 0; + + do { + var match = myRegexp.exec($('#searchbox-key').val()); + if (match != null) + { + myArray.push(match[1] ? match[1] : match[0]); + } + } while (match != null); + + if(myArray[0].charAt(0) == "("){ + if(myArray[0] == "("){ + myRegExpArr[1] = new RegExp(myArray[1]); + myQuery = '( true'; + }else{ + myRegExpArr[0] = new RegExp(myArray[0].slice(1)); + myQuery = '( true' + count++; + } + }else{ + myRegExpArr[0] = new RegExp(myArray[0]); + myQuery = 'true'; count++; - } - }else{ - myRegExpArr[0] = new RegExp(myArray[0]); - myQuery = 'true'; - count++; - } + } - for (var i = 1; i < myArray.length; i++){ - if(myArray[i] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i]); - }else if(myArray[i].charAt(0) == "(" || myArray[i] == "("){ - if(myArray[i] == "("){ - if(myArray[i - 1] == "OR"){ - myQuery += ' || ('; - }else{ - myQuery += ' && ('; - } - }else{ - if(myArray[i - 1] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i].slice(1)); - myQuery += ' || ( true'; - count++; - }else{ - myRegExpArr[i] = new RegExp(myArray[i].slice(1)); - myQuery += ' && ( true'; - count++; - } - } - }else if(myArray[i].charAt(myArray[i].length - 1) == ")" || myArray[i] == ")"){ - if(myArray[i] == ")"){ - myQuery += ' )'; - }else{ - if(myArray[i - 1] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); - myQuery += ' || true )'; - count++; - }else{ - myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); - myQuery += ' && true )'; - count++; - } - } - }else{ - if(myArray[i - 1] == "OR"){ - myRegExpArr[i] = new RegExp(myArray[i]); - myQuery += ' || true'; - count++; - }else{ - if(myArray[i - 1] == "("){ - myRegExpArr[i] = new RegExp(myArray[i]); - myQuery += ' true'; - count++; - }else{ - myRegExpArr[i] = new RegExp(myArray[i]); - myQuery += ' && true'; - count++; - } - } - } - } + for (var i = 1; i < myArray.length; i++){ + if(myArray[i] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i]); + }else if(myArray[i].charAt(0) == "(" || myArray[i] == "("){ + if(myArray[i] == "("){ + if(myArray[i - 1] == "OR"){ + myQuery += ' || ('; + }else{ + myQuery += ' && ('; + } + }else{ + if(myArray[i - 1] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i].slice(1)); + myQuery += ' || ( true'; + count++; + }else{ + myRegExpArr[i] = new RegExp(myArray[i].slice(1)); + myQuery += ' && ( true'; + count++; + } + } + }else if(myArray[i].charAt(myArray[i].length - 1) == ")" || myArray[i] == ")"){ + if(myArray[i] == ")"){ + myQuery += ' )'; + }else{ + if(myArray[i - 1] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); + myQuery += ' || true )'; + count++; + }else{ + myRegExpArr[i] = new RegExp(myArray[i].slice(0, -1)); + myQuery += ' && true )'; + count++; + } + } + }else{ + if(myArray[i - 1] == "OR"){ + myRegExpArr[i] = new RegExp(myArray[i]); + myQuery += ' || true'; + count++; + }else{ + if(myArray[i - 1] == "("){ + myRegExpArr[i] = new RegExp(myArray[i]); + myQuery += ' true'; + count++; + }else{ + myRegExpArr[i] = new RegExp(myArray[i]); + myQuery += ' && true'; + count++; + } + } + } + } - if (eval(myQuery)) { - //is not correct query - } + if (eval(myQuery)) { + //is not correct query + } - }catch(error){ - alert('正しくない検索です'); - return; + }catch(error){ + alert('正しくない検索です'); + return; + } } - if(count > 5){ alert('語句数は最大5つです'); return; -- libgit2 0.26.0