Example usage for org.apache.solr.common.params CommonParams FL

List of usage examples for org.apache.solr.common.params CommonParams FL

Introduction

In this page you can find the example usage for org.apache.solr.common.params CommonParams FL.

Prototype

String FL

To view the source code for org.apache.solr.common.params CommonParams FL.

Click Source Link

Document

query and init param for field list

Usage

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testEnhanceParamsDefaultValues() {
    ModifiableSolrParams input = new ModifiableSolrParams();
    SolrParams output = SolrQueryUtils.enhanceParams(input);
    Assert.assertNull(output.get(CommonParams.Q));
    Assert.assertEquals("* score", output.get(CommonParams.FL));
    Assert.assertEquals(true, output.getBool(SpellingParams.SPELLCHECK_COLLATE));
    Assert.assertEquals(0, (int) output.getInt(CommonParams.START));
    Assert.assertTrue(output.getInt(CommonParams.ROWS) > 100);
}

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testEnhanceParamsDoesntReplaceExistingValues() {
    ModifiableSolrParams input = new ModifiableSolrParams();
    input.set(CommonParams.Q, "field:value");
    input.set(CommonParams.FL, "id");
    input.set(CommonParams.START, 30);/*from   w w  w  .  j  a  v a2s  .  co m*/
    input.set(CommonParams.ROWS, 10);
    SolrParams output = SolrQueryUtils.enhanceParams(input);
    Assert.assertEquals("field:value", output.get(CommonParams.Q));
    Assert.assertEquals("id", output.get(CommonParams.FL));
    Assert.assertEquals(true, output.getBool(SpellingParams.SPELLCHECK_COLLATE));
    Assert.assertEquals(30, (int) output.getInt(CommonParams.START));
    Assert.assertEquals(10, (int) output.getInt(CommonParams.ROWS));
}

From source file:org.phenotips.vocabulary.internal.solr.SolrQueryUtils.java

License:Open Source License

/**
 * Adds extra parameters to a Solr query for better term searches, including custom options. More specifically, adds
 * parameters for requesting the score to be included in the results, for requesting a spellcheck result, and sets
 * the {@code start} and {@code rows} parameters when missing.
 *
 * @param originalParams the original Solr parameters to enhance
 * @param queryOptions extra options to include in the query; these override the default values, but don't override
 *            values already set in the query
 * @return the enhanced parameters//from  w  w  w.j  a  v a  2 s.c om
 */
public static SolrParams enhanceParams(SolrParams originalParams, Map<String, String> queryOptions) {
    if (originalParams == null) {
        return null;
    }
    ModifiableSolrParams newParams = new ModifiableSolrParams();
    newParams.set(CommonParams.START, "0");
    newParams.set(CommonParams.ROWS, "1000");
    newParams.set(CommonParams.FL, "* score");
    if (queryOptions != null) {
        for (Map.Entry<String, String> item : queryOptions.entrySet()) {
            newParams.set(item.getKey(), item.getValue());
        }
    }
    for (Map.Entry<String, Object> item : originalParams.toNamedList()) {
        if (item.getValue() != null && item.getValue() instanceof String[]) {
            newParams.set(item.getKey(), (String[]) item.getValue());
        } else {
            newParams.set(item.getKey(), String.valueOf(item.getValue()));
        }
    }
    if (newParams.get(SPELLCHECK) == null) {
        newParams.set(SPELLCHECK, Boolean.toString(true));
        newParams.set(SpellingParams.SPELLCHECK_COLLATE, Boolean.toString(true));
    }
    return newParams;
}

From source file:org.sakaiproject.nakamura.files.search.AbstractContentSearchQueryHandler.java

License:Apache License

/**
 * {@inheritDoc}//from   w w w  .j a  v a  2  s . c  o m
 * @see org.sakaiproject.nakamura.api.search.solr.DomainObjectSearchQueryHandler#refineQuery(java.util.Map, org.sakaiproject.nakamura.api.search.solr.Query)
 */
@Override
public void refineQuery(Map<String, String> parametersMap, Query query) {
    query.getOptions().put(CommonParams.FL, "path");

    /*
     * If there is a query string 'q' specified, then we will also need to search on
     * widget data contents. Because of this, to avoid duplicate content (e.g, multiple
     * widgets of a pooled content item match on the content), we need to group by the
     * widget content "returnpath". See also the #getResourceTypeClause(Map) method to
     * see how the widget data resourceType is dynamically included in the query.
     */
    if (hasGeneralQuery(parametersMap)) {
        query.getOptions().put(GroupParams.GROUP, Boolean.TRUE);
        query.getOptions().put(GroupParams.GROUP_FIELD, "returnpath");

        // record the number "groups" matched to give accurate total of elements
        // returned. Here, one GROUP is one actual result, instead of all the
        // identical elements aggregated in those groups.
        query.getOptions().put(GroupParams.GROUP_TOTAL_COUNT, Boolean.TRUE);
    }
}

From source file:org.sakaiproject.nakamura.user.search.PeopleGroupsAutocompleteQueryHandler.java

License:Apache License

@Override
public void refineQuery(Map<String, String> parametersMap, Query query) {
    query.getOptions().put(CommonParams.FL, "path,type");
}

From source file:org.sakaiproject.nakamura.user.search.UsersSearchQueryHandler.java

License:Apache License

@Override
public void refineQuery(Map<String, String> parametersMap, Query query) {
    Map<String, Object> queryOptions = query.getOptions();
    queryOptions.put(CommonParams.FL, "path");

    // If both Authorizable and Profile records will be searched, collapse them
    // into a single result for a single person.
    if (isFullProfile(parametersMap)) {
        queryOptions.putAll(FULLPROFILE_QUERY_OPTIONS_MAP);
    }//  w  ww  .  ja  v  a  2  s  . c o m
}

From source file:org.tallison.solr.search.concordance.KeywordCooccurRankHandler.java

License:Apache License

public static NamedList doLocalSearch(Query filter, SolrQueryRequest req) throws Exception {
    SolrParams params = req.getParams();
    String field = getField(params);

    String fl = params.get(CommonParams.FL);
    DocMetadataExtractor metadataExtractor = (fl != null && fl.length() > 0)
            ? new SimpleDocMetadataExtractor(fl.split(","))
            : new SimpleDocMetadataExtractor();

    CooccurConfig config = configureParams(field, params);

    IndexSchema schema = req.getSchema();
    SchemaField sf = schema.getField(field);
    Analyzer analyzer = sf.getType().getIndexAnalyzer();
    Filter queryFilter = getFilterQuery(req);
    String q = params.get(CommonParams.Q);
    Query query = QParser.getParser(q, null, req).parse();
    String solrUniqueKeyField = req.getSchema().getUniqueKeyField().getName();

    SolrIndexSearcher solr = req.getSearcher();
    IndexReader reader = solr.getIndexReader();
    boolean allowDuplicates = false;
    boolean allowFieldSeparators = false;

    Grammer grammer = new WGrammer(config.getMinNGram(), config.getMaxNGram(), allowFieldSeparators);
    IDFCalc idfCalc = new IDFCalc(reader);

    CooccurVisitor visitor = new CooccurVisitor(field, config.getTokensBefore(), config.getTokensAfter(),
            grammer, idfCalc, config.getMaxWindows(), allowDuplicates);

    visitor.setMinTermFreq(config.getMinTermFreq());

    try {//from w  w  w. ja v  a 2  s.  com
        ConcordanceArrayWindowSearcher searcher = new ConcordanceArrayWindowSearcher();
        System.out.println("UNIQUE KEY FIELD: " + solrUniqueKeyField);
        DocIdBuilder docIdBuilder = new FieldBasedDocIdBuilder(solrUniqueKeyField);
        System.out.println("QUERY: " + query.toString());
        searcher.search(reader, field, query, queryFilter, analyzer, visitor, docIdBuilder);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TargetTokenNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<TermIDF> overallResults = visitor.getResults();
    NamedList results = toNamedList(overallResults);
    //needed for cloud computations, merging cores

    results.add("collectionSize", reader.numDocs());
    results.add("numDocsVisited", visitor.getNumDocsVisited());
    results.add("numWindowsVisited", visitor.getNumWindowsVisited());
    results.add("numResults", overallResults.size());
    results.add("minTF", visitor.getMinTermFreq());

    return results;
}

From source file:org.tallison.solr.search.concordance.KeywordCooccurRankHandler.java

License:Apache License

public static String getField(SolrParams params) {
    String fieldName = params.get(CommonParams.FIELD);
    if (fieldName == null || fieldName.equalsIgnoreCase("null")) {

        if (fieldName == null || fieldName.equalsIgnoreCase("null"))
            fieldName = params.get(CommonParams.DF);

        if (fieldName == null || fieldName.equalsIgnoreCase("null")) {
            //check field list if not in field
            fieldName = params.get(CommonParams.FL);

            //TODO: change when/if request allows for multiple terms
            if (fieldName != null)
                fieldName = fieldName.split(",")[0].trim();
        }/*from  w  ww.  j av a 2 s .co  m*/
    }
    return fieldName;
}

From source file:org.tallison.solr.search.concordance.KWICRequestHandler.java

License:Apache License

public static NamedList doLocalSearch(Query filter, SolrQueryRequest req) throws Exception {
    SolrParams params = req.getParams();
    String field = getField(params, req.getSchema().getDefaultSearchFieldName());

    String q = params.get(CommonParams.Q);

    String fl = params.get(CommonParams.FL);
    String solrUniqueKeyField = req.getSchema().getUniqueKeyField().getName();
    DocMetadataExtractor metadataExtractor = (fl != null && fl.length() > 0)
            ? new SimpleDocMetadataExtractor(fl.split(","))
            : new SimpleDocMetadataExtractor();

    Filter queryFilter = getFilterQuery(req);

    //TODO remove and only use index
    String anType = params.get("anType", "query").toLowerCase();

    IndexSchema schema = req.getSchema();
    Analyzer analyzer = null;//from w  w w  .  j  av a  2s  .  co m
    SchemaField sf = schema.getField(field);
    if (sf != null && sf.getType() != null) {
        if (anType.equals("query")) {
            analyzer = sf.getType().getQueryAnalyzer();
        } else {
            analyzer = sf.getType().getIndexAnalyzer();
        }
    } else {
        throw new RuntimeException("No analyzer found for field " + field);
    }

    Query query = QParser.getParser(q, null, req).parse();

    IndexReader reader = req.getSearcher().getIndexReader();
    ConcordanceConfig config = buildConcordanceConfig(field, solrUniqueKeyField, params);

    WindowBuilder windowBuilder = new WindowBuilder(config.getTokensBefore(), config.getTokensAfter(), 100,
            new DefaultSortKeyBuilder(config.getSortOrder()), metadataExtractor,
            new FieldBasedDocIdBuilder(solrUniqueKeyField));

    ConcordanceSearcher searcher = new ConcordanceSearcher(windowBuilder);

    AbstractConcordanceWindowCollector collector = new ConcordanceWindowCollector(config.getMaxWindows());

    searcher.search(reader, field, query, queryFilter, analyzer, collector);

    NamedList results = convertToList(solrUniqueKeyField, collector);

    return results;
}

From source file:org.tallison.solr.search.concordance.SolrConcordanceBase.java

License:Apache License

public static String getField(SolrParams params, String fallBackField) {
    //TODO: figure out what the standard way of doing this
    String fieldName = params.get(CommonParams.FIELD);
    if (fieldName == null || fieldName.equalsIgnoreCase("null")) {

        if (fieldName == null || fieldName.equalsIgnoreCase("null")) {
            fieldName = params.get(CommonParams.DF);
        }/*from w  w  w . j a  v  a 2 s.  com*/

        if (fieldName == null || fieldName.equalsIgnoreCase("null")) {
            //check field list if not in field
            fieldName = params.get(CommonParams.FL);

            //TODO: change when/if request allows for multiple terms
            if (fieldName != null) {
                fieldName = fieldName.split(",")[0].trim();
            }
        }
    }

    return (fieldName != null) ? fieldName : fallBackField;
}