コード例 #1
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.smila.search.api.SearchService#search(java.lang.String,
   *     org.eclipse.smila.datamodel.record.Record)
   */
  public SearchResult search(final String workflowName, final Record query)
      throws ProcessingException {
    try {
      final long starttime = System.nanoTime();
      ensureQueryId(workflowName, query);
      final SearchResultImpl result = new SearchResultImpl(workflowName, query);
      final Blackboard blackboard = _blackboardFactory.createTransientBlackboard();
      blackboard.setRecord(query);
      SearchMessage message = new SearchMessage(query.getId(), null);
      message = _processor.process(workflowName, blackboard, message);

      if (message.hasQuery()) {
        result.setQuery(blackboard.getRecord(message.getQuery()));
      }
      if (message.hasRecords()) {
        final Id[] ids = message.getRecords();
        final Record[] records = new Record[ids.length];
        for (int i = 0; i < ids.length; i++) {
          records[i] = blackboard.getRecord(ids[i]);
        }
        result.setRecords(records);
      }
      final long endtime = System.nanoTime();
      setRuntime(blackboard, message.getQuery(), (endtime - starttime));
      blackboard.invalidate();
      return result;
    } catch (final BlackboardAccessException ex) {
      throw new ProcessingException("Blackboard error: ", ex);
    }
  }
コード例 #2
0
 /**
  * ensure that the given record has a "result" annotation.
  *
  * @param blackboard blackboard
  * @param record id of record
  * @return the "result" annotation on the record
  * @throws BlackboardAccessException error accessing blackboard.
  */
 private Annotation ensureResultAnnotation(final Blackboard blackboard, final Id record)
     throws BlackboardAccessException {
   Annotation annotation = blackboard.getAnnotation(record, null, SearchAnnotations.RESULT);
   if (annotation == null) {
     annotation = blackboard.createAnnotation(record);
     blackboard.setAnnotation(record, null, SearchAnnotations.RESULT, annotation);
   }
   return annotation;
 }