<%--
  Copyright 2003 Sun Microsystems, Inc. All rights reserved 
  Use is subject to license terms.
 --%>
<%-- @(#)advQuery.jsp --%>

<%@page import="com.sun.portal.search.providers.*, java.util.*, java.text.*" %>

<%@ taglib uri="/tld/search.tld" prefix="search" %>
<%@ taglib uri="/tld/jx.tld" prefix="jx" %>

<jsp:useBean id="formbean" scope="request" class="SearchRequestBean">
<jsp:setProperty name="formbean" property= "*"/>
</jsp:useBean>

<jx:declare id="locale" type="java.util.Locale"/>

<%
ArrayList l = new ArrayList();
HashMap h = new HashMap();

// Discussions Feature
h = new HashMap();
String rtvalue = request.getParameter("rating");
if (rtvalue != null) {
    int rt = Integer.parseInt(rtvalue);
    if (rt > -1) {
	h.put(SearchContext.OPERAND, "rd-rating");
	h.put(SearchContext.OPERATION, SearchContext.GREATER);
	h.put(SearchContext.VALUE, (rt-1)+"");
	l.add(h);
    }
}

if (!formbean.getWordsVal().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, ""); // should be a valid schema name
    h.put(SearchContext.OPERATION, formbean.getWordsOp());
    h.put(SearchContext.VALUE, formbean.getWordsVal());
    l.add(h);
}

if (!formbean.getNowords().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, "");
    h.put(SearchContext.OPERATION, SearchContext.NOT);
    h.put(SearchContext.VALUE, "<OR> "+formbean.getNowords());
    l.add(h);
}

if (!formbean.getAuthorVal().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, "author");
    h.put(SearchContext.OPERATION, formbean.getAuthorOp());
    h.put(SearchContext.VALUE, formbean.getAuthorVal());
    l.add(h);
}

if (!formbean.getTitleVal().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, "title");
    h.put(SearchContext.OPERATION, formbean.getTitleOp());
    h.put(SearchContext.VALUE, formbean.getTitleVal());
    l.add(h);
}

if (!formbean.getTitleVal().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, "url");
    h.put(SearchContext.OPERATION, formbean.getUrlOp());
    h.put(SearchContext.VALUE, formbean.getUrlVal());
    l.add(h);
}

if (!formbean.getUrlVal().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, "url");
    h.put(SearchContext.OPERATION, formbean.getUrlOp());
    h.put(SearchContext.VALUE, formbean.getUrlVal());
    l.add(h);
}

if (!formbean.getSince().equals("")) {
    h = new HashMap();
    h.put(SearchContext.OPERAND, "last-modified");
    h.put(SearchContext.OPERATION, SearchContext.GREATER);

    DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    Calendar c1 = new GregorianCalendar();
    String d1 = df.format(c1.getTime());

    if (formbean.getSince().equals("7")) {
	c1.add(Calendar.DATE, -7);
    }

    if (formbean.getSince().equals("30")) {
	c1.roll(Calendar.MONTH, false);
    }

    if (formbean.getSince().equals("180")) {
	c1.add(Calendar.MONTH, -6);
    }

    if (formbean.getSince().equals("365")) {
	c1.roll(Calendar.YEAR, false);
    }

    String d2 = df.format(c1.getTime());
    h.put(SearchContext.VALUE, d2);
    if (!formbean.getSince().equals("0")) {
	l.add(h);
    }
}
%>
<search:setCriteria criteria="<%=l%>"/>
