function convertQPquery(query){ var qtext = query; var exp; qtext = cleanQuery(qtext); // 연산자 앞 뒤로 공백을 추가 qtext = qtext.replace(/[&]/g, " & "); qtext = qtext.replace(/[|]/g, " | "); qtext = qtext.replace(/[!]/g, " ! "); exp = /[\s]/g; var arr_qtext = qtext.split(exp); qtext = ""; for( var i = 0 ; i < arr_qtext.length ; i++ ){ if( arr_qtext[i] == "!" ){ qtext += ""; } else if( arr_qtext[i] == "&" ){ qtext += ""; } else if( arr_qtext[i] == "|" ){ qtext += ""; } else if( arr_qtext[i] != "" ){ qtext = qtext + "`" + arr_qtext[i] + "`"; } } return qtext; } function convertQPBigramQuery(query){ var qtext = query; var exp; qtext = cleanQuery(qtext); // 연산자 앞 뒤로 공백을 추가 qtext = qtext.replace(/[&]/g, " & "); qtext = qtext.replace(/[|]/g, " | "); qtext = qtext.replace(/[!]/g, " ! "); exp = /[\s]/g; var arr_qtext = qtext.split(exp); qtext = ""; for( var i = 0 ; i < arr_qtext.length ; i++ ){ if( arr_qtext[i] == "!" ){ qtext += ""; } else if( arr_qtext[i] == "&" ){ qtext += ""; } else if( arr_qtext[i] == "|" ){ qtext += ""; } else if( arr_qtext[i] != "" ){ qtext = qtext + "`" + arr_qtext[i] + "`"; } } return qtext; } function cleanUpQuery(query) { var qtext = query; var exp; // 특수문자를 기준으로 split 하여 분리한 다음 // 분리된 단어가 and or not 인지 판별하여 기호로 치환하여 나중에 한꺼번에 처리한다 // exp = /[.!|!/\-+\'\"~`?*&^%$#@,=;:\\\]\[}{)(\s><_]/g ; exp = /[.!|!/\-\'\"~`?&^%$#@,=;:\\\]\[}{)(\s><_]/g ; var arr_qtext = qtext.split(exp); qtext = ""; for (var i = 0; i < arr_qtext.length; i++) { arr_qtext[i] = arr_qtext[i].replace(/(^or$|^and$|^not$)/i, " "); // 다시 하나의 string으로 연결한다. qtext += arr_qtext[i] + " "; } // 다시 중복 스페이스를 압축 exp = /[\s]+/g; qtext = qtext.replace(exp, " "); // 마지막 스페이스 제거 exp = /[\s]+$/g; qtext = qtext.replace(exp, ""); return qtext; } function cleanQuery(query) { var qtext = query; var exp; // 특수문자를 기준으로 split 하여 분리한 다음 // 분리된 단어가 and or not 인지 판별하여 기호로 치환하여 나중에 한꺼번에 처리한다 exp = /[.!/\-+\'\"~`?*^%$#@,=;:\\\]\[}{)(\s><_]/g ; var arr_qtext = qtext.split(exp); qtext = ""; for (var i = 0; i < arr_qtext.length; i++) { arr_qtext[i] = arr_qtext[i].replace(/^or$/i, "|"); arr_qtext[i] = arr_qtext[i].replace(/^and$/i, "&"); arr_qtext[i] = arr_qtext[i].replace(/^not$/i, "!"); // 다시 하나의 string으로 연결한다. qtext += arr_qtext[i] + " "; } // 뒤에 따라나오는 !(not) |(or) &(and) 연산자 제거 exp = /[!&|\s]+$/g; qtext = qtext.replace(exp, ""); // 앞에 나오는 & | 연산자 제거 exp = /^[&|][&!|\s]+/g; qtext = qtext.replace(exp, ""); exp = /^[!][!&|]+[!&|\s]*/g; qtext = qtext.replace(exp, ""); exp = /^[&|\s]+/g; qtext = qtext.replace(exp, ""); // ! (not) 연산자 앞 뒤 공백 압축 exp = /[\s]*[!][\s]*/g ; qtext = qtext.replace(exp, "!"); // & (and) 연산자 앞 뒤 공백 압축 exp = /[\s]*[&][\s]*/g ; qtext = qtext.replace(exp, "&"); // | (or) 연산자 앞 뒤 공백 압축 exp = /[\s]*[|][\s]*/g ; qtext = qtext.replace(exp, "|"); // 잘못된 중복 연산자 and 로 치환 ( |! ( )은 유효) exp = /([&!][&!|]+|[|][&|]+|[|][!][!|&]+|[\s]+)/g; qtext = qtext.replace(exp, "&"); return qtext; } function cleanQueryBeauty(query) { var qtext = query; var exp; qtext = cleanQuery(qtext); // 예쁘게 보이기 하기 위해서 연산자 주위로 공백 추가 exp = /[!]/g; qtext = qtext.replace(exp, " ! "); exp = /[&]/g; qtext = qtext.replace(exp, " & "); exp = /[|]/g; qtext = qtext.replace(exp, " | "); exp = /^[\s]+/g; qtext = qtext.replace(exp, ""); return qtext; } /* ! : 연산자 ' ' : 연산자 | : 연산자 중복이 되거나 잘못된 연산자의 연속은 and로 치환 */ function convertQuery(query) { var qtext = query; var exp; // 특수문자를 기준으로 split 하여 분리한 다음 // 분리된 단어가 and or not 인지 판별하여 기호로 치환하여 나중에 한꺼번에 처리한다 exp = /[.!/\-+\'\"~`?*^%$#@,=;:\\\]\[}{)(\s><_]/g ; var arr_qtext = qtext.split(exp); qtext = ""; for (var i = 0; i < arr_qtext.length; i++) { arr_qtext[i] = arr_qtext[i].replace(/^or$/i, "|"); arr_qtext[i] = arr_qtext[i].replace(/^and$/i, "&"); arr_qtext[i] = arr_qtext[i].replace(/^not$/i, "!"); // 다시 하나의 string으로 연결한다. qtext += arr_qtext[i] + " "; } // 뒤에 따라나오는 !(not) |(or) &(and) 연산자 제거 exp = /[!&|\s]+$/g; qtext = qtext.replace(exp, ""); // 앞에 나오는 & | 연산자 제거 exp = /^[&|][&!|\s]+/g; qtext = qtext.replace(exp, ""); exp = /^[!][!&|]+[!&|\s]*/g; qtext = qtext.replace(exp, ""); exp = /^[&|\s]+/g; qtext = qtext.replace(exp, ""); // ! (not) 연산자 앞 뒤 공백 압축 exp = /[\s]*[!][\s]*/g ; qtext = qtext.replace(exp, "!"); // & (and) 연산자 앞 뒤 공백 압축 exp = /[\s]*[&][\s]*/g ; qtext = qtext.replace(exp, "&"); // | (or) 연산자 앞 뒤 공백 압축 exp = /[\s]*[|][\s]*/g ; qtext = qtext.replace(exp, "|"); // 잘못된 중복 연산자 and 로 치환 ( |! ( )은 유효) exp = /([&!][&!|]+|[|][&|]+|[|][!][!|&]+|[\s]+)/g; qtext = qtext.replace(exp, "&"); // AND exp = /[&]/g; qtext = qtext.replace(exp, ""); // OR exp = /[|]/g; qtext = qtext.replace(exp, ""); // NOT exp = /[!]/g; qtext = qtext.replace(exp, ""); return qtext; } function setQueryText() { var ktext = document.frmSearch.keyword.value; var qtext = ktext; qtext = convertQuery(ktext); alert("[qtext:" + qtext + "]"); //query_view.innerText = "["+qtext+"]"; qtext = cleanUpQuery(ktext); alert("[cleanup_view:" + qtext + "]"); //cleanup_view.innerText = "["+qtext+"]"; qtext = cleanQuery(ktext); alert("[clean_view:" + qtext + "]"); //clean_view.innerText = "["+qtext+"]"; qtext = cleanQueryBeauty(ktext); alert("[cleanbeauty_view:" + qtext + "]"); //cleanbeauty_view.innerText = "["+qtext+"]"; qtext = convertQPquery(ktext); alert("[qp_view:" + qtext + "]"); //qp_view.innerText = "["+qtext+"]"; qtext = convertQPBigramQuery(ktext); alert("[qpbigram_view:" + qtext + "]"); //qpbigram_view.innerText = "["+qtext+"]"; return false; } function goTotalSearch(){ frm = document.searchFrm; frm.query.value = cleanUpQuery(frm.query.value); if(frm.query.value == "" || frm.query.value == null || frm.query.value.length < 2 ){ alert("검색어가 없거나 특수기호 입니다.\n검색어를 입력해 주시기 바랍니다."); frm.query.value = ""; frm.query.focus(); return false; } else{ frm.action = "/search/search.jsp"; frm.submit(); } }