/*
 * Copyright 2014-2015 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.frontend.find.search;

import com.hp.autonomy.frontend.find.ApiKeyService;
import com.hp.autonomy.iod.client.api.search.*;
import com.hp.autonomy.iod.client.error.IodErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DocumentsServiceImpl implements DocumentsService {

    @Autowired
    private ApiKeyService apiKeyService;

    @Autowired
    private QueryTextIndexService queryTextIndexService;

    @Override
    public Documents queryTextIndex(final String text, final int maxResults, final Summary summary, final List<String> indexes, final String fieldText) throws IodErrorException {

        final Map<String, Object> params = new QueryRequestBuilder()
                .setAbsoluteMaxResults(maxResults)
                .setSummary(summary)
                .setIndexes(indexes)
                .setFieldText(fieldText)
                .build();

        return queryTextIndexService.queryTextIndexWithText(apiKeyService.getApiKey(), text, params);
    }
}

@@ -281,16 +281,74 @@
 ervice;%0A
+import com.hp.autonomy.frontend.find.QueryProfileService;%0A
 import c
@@ -387,16 +387,16 @@
 arch.*;%0A
-
 import c
@@ -730,24 +730,93 @@
 eyService;%0A%0A
+    @Autowired%0A    private QueryProfileService queryProfileService;%0A%0A
     @Autowir
@@ -1264,16 +1264,16 @@
 ndexes)%0A
-
         
@@ -1305,16 +1305,88 @@
 ldText)%0A
+                .setQueryProfile(queryProfileService.getQueryProfile())%0A
         

Use query profile when querying for results documents