Search in sources :

Example 6 with UrlParamBuilder

use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.

the class Link method appendQueryParameters.

private static String appendQueryParameters(Multimap<String, ?> queryParameters, String path) {
    if (!queryParameters.isEmpty()) {
        UrlParamBuilder paramBuilder = UrlParamBuilder.params();
        for (Map.Entry<String, ?> paramEntry : queryParameters.entries()) {
            paramBuilder.add(paramEntry.getKey(), paramEntry.getValue().toString());
        }
        path = path + "?" + UriUtil.formatMangledParams(paramBuilder.build());
    }
    return path;
}
Also used : UrlParamBuilder(org.ambraproject.wombat.util.UrlParamBuilder) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with UrlParamBuilder

use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.

the class SolrSearchApiTest method testSetQueryFilters_IncludeArticleTypes.

@Test
public void testSetQueryFilters_IncludeArticleTypes() throws IOException {
    UrlParamBuilder actual = UrlParamBuilder.params();
    ArticleSearchQuery.SolrExplicitDateRange edr = new ArticleSearchQuery.SolrExplicitDateRange("test", "2011-01-01", "2015-06-01");
    ArrayList<String> articleTypes = new ArrayList<>();
    articleTypes.add("Research Article");
    setQueryFilters(actual, ImmutableList.of("foo"), articleTypes, new ArrayList<String>(), edr);
    SetMultimap<String, String> actualMap = convertToMap(actual.build());
    assertPubDate(actualMap.get("fq"));
    assertJournals(actualMap.get("fq"), "foo");
    assertArticleTypes(actualMap.get("fq"));
}
Also used : UrlParamBuilder(org.ambraproject.wombat.util.UrlParamBuilder) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with UrlParamBuilder

use of org.ambraproject.wombat.util.UrlParamBuilder in project wombat by PLOS.

the class SolrQueryBuilder method buildParameters.

public static List<NameValuePair> buildParameters(ArticleSearchQuery asq) {
    UrlParamBuilder params = UrlParamBuilder.params();
    params.add("wt", "json");
    if (asq.isPartialSearch()) {
        params.add("qf", "doc_partial_body");
        params.add("fl", "*");
        params.add("fq", "doc_type:partial");
    } else {
        params.add("fq", "doc_type:full");
    }
    params.add("fq", "!article_type_facet:\"Issue Image\"");
    if (asq.getStart() > 0) {
        params.add("start", Integer.toString(asq.getStart()));
    }
    params.add("rows", Integer.toString(asq.getRows()));
    params.add("hl", "false");
    String queryString = asq.getQuery();
    params.add("q", queryString);
    if (asq.isSimple()) {
        // Use the dismax query parser, recommended for all user-entered queries.
        // See https://wiki.apache.org/solr/DisMax
        params.add("defType", "dismax");
    }
    if (asq.getFacetFields().size() > 0) {
        params.add("facet", "true");
        for (ArticleSearchQuery.Facet field : asq.getFacetFields()) {
            String query = field.getExcludeKey().map(excludeKey -> String.format("{!ex=%s}", excludeKey)).orElse("") + field.getField();
            params.add("facet.field", query);
        }
        params.add("facet.mincount", Integer.toString(asq.getFacetMinCount()));
        params.add("facet.limit", Integer.toString(asq.getFacetLimit()));
        params.add("facet.threads", Integer.toString(THREAD_PER_FACET));
        params.add("json.nl", "map");
    } else {
        params.add("facet", "false");
    }
    List<String> fields = asq.getFields().orElse(ArticleSearchQuery.ARTICLE_FIELDS);
    params.add("fl", Joiner.on(",").join(fields));
    asq.getCursor().ifPresent(cursor -> params.add("cursorMark", cursor));
    setQueryFilters(asq, params);
    if (asq.getStatsField().isPresent()) {
        params.add("stats", "true");
        params.add("stats.field", asq.getStatsField().get());
    }
    return params.build();
}
Also used : UrlParamBuilder(org.ambraproject.wombat.util.UrlParamBuilder)

Aggregations

UrlParamBuilder (org.ambraproject.wombat.util.UrlParamBuilder)8 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ArticleSearchQuery (org.ambraproject.wombat.service.remote.ArticleSearchQuery)1 SolrSearchApi (org.ambraproject.wombat.service.remote.SolrSearchApi)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1