1 Reply Latest reply: Aug 14, 2006 10:43 AM by sdienhart RSS

    Why searching by Date attribute does not work?

    487823
      Hi!
      I'm using Oracle 9i (r2) Ultra Search.
      My instance indecies text from table data sourse, which contains date attribute (Date type). The mapping between table column and attribute is set. In the US table i see that date data is indexed.
      But when i use this:
      java.util.Date d = ... // needed date
      Query q = new Equals(d);

      and then call
      inst.getResult(q, ...

      the search returns no result, however i know that this date exactly present in my instance.

      The Hours, Minutes and seconds in the sourse table and in my query date are set to zero.
      What is the problem?
      Thanks
        • 1. Re: Why searching by Date attribute does not work?
          sdienhart
          Try using an attribute-based approach to searching by date. In our implementation, we use a date range filter.

          // Add from date
          GreaterThan greaterThan = new GreaterThan(creationDateAttribute, java.util.Date());

          // Add to date
          LessThan lessThan = new LessThan(creationDateAttribute, java.util.Date());

          Add the two date terms to a Query[] object and then create a new And query. Something like...

          // Add dates to list
          queryTermsList.add(greaterThan);
          queryTermsList.add(lessThan );

          // Create Query[] of all search filters to use
          Query[] query = (Query[]) queryTermsList.toArray(new Query[queryTermsList.size()]);

          // Create query
          And(query);

          Also, be sure you are setting the fetch attributes on the request before searching...

          // Set attributes
          Collection attributeCollection = sc.getQueryInstance().getMetaData().getAttributes();
          Attribute[] attributeArray = (Attribute[]) attributeCollection.toArray(new Attribute[attributeCollection.size()]);
          request.setAttributesFetched(attributeArray);

          Good luck,

          - Stephen