001: package com.sun.portal.search;
002:
003: import java.util.*;
004: import java.lang.*;
005:
006: /**
007: * QueryParser class produces the scope for
008: * advanced search queries
009: */
010: public class QueryParser {
011: StringBuffer scope = null;
012: String scopeString = "";
013:
014: public void QueryParser() {
015: }
016:
017: public void setQueryParams(String wordsOp, String wordsVal,
018: String nowordsVal, String authorOp, String authorVal,
019: String titleOp, String titleVal, String urlOp,
020: String urlVal, String expiresOp, String expiresVal,
021: String lmodifiedOp, String lmodifiedVal, String comments) {
022:
023: String r_op = "";
024: scope = new StringBuffer();
025:
026: if (!wordsVal.equals("")) {
027: r_op = getRightOperator(wordsVal);
028: scope.append("(" + r_op + ")");
029: scope.append(" <AND> ");
030: }
031: if (!nowordsVal.equals("")) {
032: r_op = getRightOperator(nowordsVal);
033: scope.append(" <NOT> (" + r_op + ")");
034: scope.append(" <AND> ");
035: }
036: if (!urlVal.equals("")) {
037: r_op = getRightOperator(urlVal);
038: parse("Url", urlOp, r_op);
039: }
040: if (!authorVal.equals("")) {
041: r_op = getRightOperator(authorVal);
042: parse("Author", authorOp, r_op);
043: }
044: if (!titleVal.equals("")) {
045: r_op = getRightOperator(titleVal);
046: parse("Title", titleOp, r_op);
047: }
048: if (!expiresVal.equals("")) {
049: r_op = getRightOperator(expiresVal);
050: parse("Expires", expiresOp, r_op);
051: }
052: if (!lmodifiedVal.equals("")) {
053: r_op = getRightOperator(lmodifiedVal);
054: parse("Last-Modified", lmodifiedOp, r_op);
055: }
056:
057: if (comments.equalsIgnoreCase("no")) {
058: // TODO: exclude comments gv-discussion-id =
059: }
060:
061: // Remove trailing <AND>
062: scopeString = scope.toString();
063: if (scopeString.endsWith(" <AND> ")) {
064: scopeString = scopeString.substring(0,
065: scopeString.length() - 7);
066: }
067: }
068:
069: public String getScope() {
070: return scopeString;
071: }
072:
073: public String getRightOperator(String r_op) {
074: String new_op = "";
075:
076: if (r_op.indexOf(",") > 0) {
077: new_op = r_op.replace(',', '+');
078: } else if (r_op.indexOf(" ") > 0) {
079: new_op = r_op.replace(' ', '+');
080: } else {
081: new_op = r_op;
082: }
083:
084: return new_op;
085: }
086:
087: public void parse(String l_op, String operand, String r_op) {
088:
089: if (operand.equals("does")) {
090: scope.append("(" + l_op + " <CONTAINS> " + r_op + ")");
091: } else if (operand.equals("doesnt")) {
092: scope.append(" <NOT> " + "(" + l_op + " <CONTAINS> " + r_op
093: + ")");
094: } else if (operand.equals("is")) {
095: scope.append("(" + l_op + " = " + r_op + ")");
096: } else if (operand.equals("isnt")) {
097: scope.append(" <NOT> " + "(" + l_op + " = " + r_op + ")");
098: } else if (operand.equals("before")) {
099: scope.append("(" + l_op + " < " + r_op + ")");
100: } else if (operand.equals("after")) {
101: scope.append("(" + l_op + " > " + r_op + ")");
102: } else if (operand.equals("all")) {
103: } else if (operand.equals("any")) {
104: } else if (operand.equals("exact")) {
105: }
106: scope.append(" <AND> ");
107:
108: }
109:
110: }
|