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.alfresco.solr.SolrInformationServer.java

License:Open Source License

private void doUpdateDescendantDocs(NodeMetaData parentNodeMetaData, boolean overwrite,
        SolrQueryRequest request, UpdateRequestProcessor processor, LinkedHashSet<Long> stack)
        throws AuthenticationException, IOException, JSONException {

    // skipDescendantDocsForSpecificAspects is initialised on a synchronised method, so access must be also synchronised 
    synchronized (this) {
        if ((skipDescendantDocsForSpecificTypes
                && typesForSkippingDescendantDocs.contains(parentNodeMetaData.getType()))
                || (skipDescendantDocsForSpecificAspects
                        && shouldBeIgnoredByAnyAspect(parentNodeMetaData.getAspects()))) {
            return;
        }//from   www  .  j  a v a 2s  . c o m
    }

    Set<Long> childIds = new HashSet<>();

    if (parentNodeMetaData.getChildIds() != null) {
        childIds.addAll(parentNodeMetaData.getChildIds());
    }

    String query = FIELD_PARENT + ":\"" + parentNodeMetaData.getNodeRef() + "\"";
    ModifiableSolrParams params = new ModifiableSolrParams(request.getParams()).set(CommonParams.Q, query)
            .set(CommonParams.FL, FIELD_SOLR4_ID);

    if (skippingDocsQueryString != null && !skippingDocsQueryString.isEmpty()) {
        params.set(CommonParams.FQ, "NOT ( " + skippingDocsQueryString + " )");
    }

    SolrDocumentList docs = cloud.getSolrDocumentList(nativeRequestHandler, request, params);
    for (SolrDocument doc : docs) {
        String id = getFieldValueString(doc, FIELD_SOLR4_ID);
        TenantAclIdDbId ids = AlfrescoSolrDataModel.decodeNodeDocumentId(id);
        childIds.add(ids.dbId);
    }

    for (Long childId : childIds) {
        NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
        nmdp.setFromNodeId(childId);
        nmdp.setToNodeId(childId);
        nmdp.setIncludeAclId(false);
        nmdp.setIncludeAspects(false);
        nmdp.setIncludeChildAssociations(false);
        nmdp.setIncludeChildIds(true);
        nmdp.setIncludeNodeRef(false);
        nmdp.setIncludeOwner(false);
        nmdp.setIncludeParentAssociations(false);
        // We only care about the path and ancestors (which is included) for this case
        nmdp.setIncludePaths(true);
        nmdp.setIncludeProperties(false);
        nmdp.setIncludeType(false);
        nmdp.setIncludeTxnId(false);
        // Gets only one
        List<NodeMetaData> nodeMetaDatas = repositoryClient.getNodesMetaData(nmdp, 1);

        if (!nodeMetaDatas.isEmpty()) {
            NodeMetaData nodeMetaData = nodeMetaDatas.get(0);
            if (mayHaveChildren(nodeMetaData)) {
                updateDescendantDocs(nodeMetaData, overwrite, request, processor, stack);
            }

            try {
                lock(childId);

                LOGGER.debug("Cascade update child doc {}", childId);

                // Gets the document that we have from the content store and updates it
                String fixedTenantDomain = AlfrescoSolrDataModel.getTenantId(nodeMetaData.getTenantDomain());
                SolrInputDocument cachedDoc = solrContentStore
                        .retrieveDocFromSolrContentStore(fixedTenantDomain, nodeMetaData.getId());

                if (cachedDoc != null) {
                    updatePathRelatedFields(nodeMetaData, cachedDoc);
                    updateNamePathRelatedFields(nodeMetaData, cachedDoc);
                    updateAncestorRelatedFields(nodeMetaData, cachedDoc);

                    AddUpdateCommand addDocCmd = new AddUpdateCommand(request);
                    addDocCmd.overwrite = overwrite;
                    addDocCmd.solrDoc = cachedDoc;

                    processor.processAdd(addDocCmd);
                    solrContentStore.storeDocOnSolrContentStore(fixedTenantDomain, nodeMetaData.getId(),
                            cachedDoc);
                } else {
                    LOGGER.debug("No child doc found to update {}", childId);
                }
            } finally {
                unlock(childId);
            }
        }
    }
}

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

private long topNodeId(String sortDir) {
    try (SolrQueryRequest request = this.newSolrQueryRequest()) {
        ModifiableSolrParams params = new ModifiableSolrParams(request.getParams())
                .set(CommonParams.Q, FIELD_DOC_TYPE + ":" + DOC_TYPE_NODE).set(CommonParams.ROWS, 1)
                .set(CommonParams.SORT, FIELD_DBID + " " + sortDir).set(CommonParams.FL, FIELD_DBID);

        SolrDocumentList docs = cloud.getSolrDocumentList(nativeRequestHandler, request, params);
        return docs.stream().findFirst().map(doc -> getFieldValueLong(doc, FIELD_DBID)).orElse(0L);
    }/*from w w  w .  j av  a2 s . com*/
}

From source file:org.apache.blur.slur.BlurQueryHelper.java

License:Apache License

private static void maybeAddSelector(BlurQuery blurQuery, SolrParams p) {
    String fieldString = p.get(CommonParams.FL);
    Selector selector = new Selector();
    selector.setRecordOnly(true);/*from   ww w.  j  a  va 2s .c  o  m*/

    if (fieldString != null) {
        Map<String, Set<String>> famCols = Maps.newHashMap();
        String[] fields = fieldString.split(",");

        for (String field : fields) {
            String[] famCol = field.split("\\.");

            if (famCol.length != 2) {
                throw new IllegalArgumentException("Fields must be in a family.column format[" + field + "]");
            }
            if (!famCols.containsKey(famCol[0])) {
                famCols.put(famCol[0], new HashSet<String>());
            }
            Set<String> cols = famCols.get(famCol[0]);
            cols.add(famCol[1]);
        }
        selector.setColumnsToFetch(famCols);

    }
    blurQuery.setSelector(selector);
}

From source file:org.apache.gora.solr.query.SolrResult.java

License:Apache License

public SolrResult(DataStore<K, T> dataStore, Query<K, T> query, SolrServer server, int resultsSize)
        throws IOException {
    super(dataStore, query);
    store = (SolrStore<K, T>) dataStore;
    ModifiableSolrParams params = new ModifiableSolrParams();
    if (query instanceof PartitionQueryImpl) {
        query = ((PartitionQueryImpl<K, T>) query).getBaseQuery();
    }/*from  w w w .  ja v a2s  .  com*/
    String q = ((SolrQuery<K, T>) query).toSolrQuery();
    params.set(CommonParams.Q, q);
    fields = query.getFields();
    if (fields == null) {
        params.set(CommonParams.FL, "*");
    } else {
        HashSet<String> uniqFields = new HashSet<String>(Arrays.asList(fields));
        String keyFld = ((SolrStore<K, T>) dataStore).getMapping().getPrimaryKey();
        uniqFields.add(keyFld); // return also primary key
        StringBuilder sb = new StringBuilder();
        for (String f : uniqFields) {
            if (sb.length() > 0)
                sb.append(',');
            sb.append(f);
        }
        params.set(CommonParams.FL, sb.toString());
    }
    params.set(CommonParams.ROWS, resultsSize);
    try {
        QueryResponse rsp = server.query(params);
        list = rsp.getResults();
    } catch (SolrServerException e) {
        e.printStackTrace();
        throw new IOException(e);
    }
}

From source file:org.apache.gora.solr.store.SolrStore.java

License:Apache License

@Override
public T get(K key, String[] fields) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.QT, "/get");
    params.set(CommonParams.FL, toDelimitedString(fields, ","));
    params.set("id", key.toString());
    try {/*from  ww  w .j a  va 2 s  . com*/
        QueryResponse rsp = server.query(params);
        Object o = rsp.getResponse().get("doc");
        if (o == null) {
            return null;
        }
        return newInstance((SolrDocument) o, fields);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return null;
}

From source file:org.eclipse.orion.internal.server.search.Indexer.java

License:Open Source License

private boolean isModified(IFileStore file, IFileInfo fileInfo) {
    try {//from  w w  w . j a va 2  s.c o  m
        //if there is no match, then the file last modified doesn't match last index so assume it was modified
        StringBuffer qString = new StringBuffer(ProtocolConstants.KEY_ID);
        qString.append(':');
        qString.append(ClientUtils.escapeQueryChars(file.toURI().toString()));
        qString.append(" AND "); //$NON-NLS-1$
        qString.append(ProtocolConstants.KEY_LAST_MODIFIED);
        qString.append(':');
        qString.append(Long.toString(fileInfo.getLastModified()));
        SolrQuery query = new SolrQuery(qString.toString());
        query.setParam(CommonParams.FL, ProtocolConstants.KEY_ID);
        QueryResponse response = server.query(query);
        return response.getResults().getNumFound() == 0;
    } catch (SolrServerException e) {
        handleIndexingFailure(e);
        //attempt to re-index
        return true;
    }
}

From source file:org.eclipse.orion.internal.server.search.SearchServlet.java

License:Open Source License

private SolrQuery buildSolrQuery(HttpServletRequest req) {
    SolrQuery query = new SolrQuery();
    query.setParam(CommonParams.WT, "json");
    query.setParam(CommonParams.FL, "Id,Name,Length,Directory,LastModified,Location");
    query.setParam("hl", "true");
    String queryString = req.getParameter(CommonParams.Q);
    queryString += " AND " + ProtocolConstants.KEY_USER_NAME + ':' + req.getRemoteUser();
    query.setQuery(queryString);/*from  w  ww. ja v a2s  .c  o m*/
    return query;
}

From source file:org.janusgraph.diskstorage.solr.SolrIndex.java

License:Apache License

@Override
public Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever information, BaseTransaction tx)
        throws BackendException {
    final String collection = query.getStore();
    final String keyIdField = getKeyFieldId(collection);
    final SolrQuery solrQuery = new SolrQuery("*:*");
    solrQuery.set(CommonParams.FL, keyIdField);
    final String queryFilter = buildQueryFilter(query.getCondition(), information.get(collection));
    solrQuery.addFilterQuery(queryFilter);
    if (!query.getOrder().isEmpty()) {
        addOrderToQuery(solrQuery, query.getOrder());
    }/*w  ww. j av  a2s  .  c o m*/
    solrQuery.setStart(0);
    if (query.hasLimit()) {
        solrQuery.setRows(Math.min(query.getLimit(), batchSize));
    } else {
        solrQuery.setRows(batchSize);
    }
    return executeQuery(query.hasLimit() ? query.getLimit() : null, 0, collection, solrQuery,
            doc -> doc.getFieldValue(keyIdField).toString());
}

From source file:org.mitre.opensextant.extraction.PlacenameMatcher.java

License:Apache License

/**
 *///  www. j a  v a2 s .  c  o m
protected static void initialize() throws IOException {

    if (solr != null) {
        return;
    }

    // NOTE: This is set via opensextant.apps.Config or by some other means
    // But it is required to intialize.  "gazetteer" is the core name of interest.
    // Being explicit here about the core name allows integrator to field multiple cores 
    // in the same gazetteer.  
    // 
    String config_solr_home = System.getProperty("solr.solr.home");
    solr = new SolrProxy(config_solr_home, "gazetteer");

    ModifiableSolrParams _params = new ModifiableSolrParams();
    _params.set(CommonParams.QT, requestHandler);
    //request all fields in the Solr index
    // Do we need specific fields or *?  If faster use specific fields. TODO.
    //_params.set(CommonParams.FL, "*,score");
    // Note -- removed score for now, as we have not evaluated how score could be used in this sense.
    // Score depends on FST creation and other factors.
    // 
    // TODO: verify that all the right metadata is being retrieved here
    _params.set(CommonParams.FL,
            "id,name,cc,adm1,adm2,feat_class,feat_code,lat,lon,place_id,name_bias,id_bias,name_type");

    _params.set("tagsLimit", 100000);
    _params.set(CommonParams.ROWS, 100000);
    _params.set("subTags", false);
    _params.set("matchText", false);//we've got the input doc as a string instead

    /* Possible overlaps: ALL, NO_SUB, LONGEST_DOMINANT_RIGHT
     * See Solr Text Tagger documentation for details. 
     */
    _params.set("overlaps", "LONGEST_DOMINANT_RIGHT");
    //_params.set("overlaps", "NO_SUB");

    params = _params;
}

From source file:org.mitre.opensextant.extraction.SolrGazetteer.java

License:Apache License

/** 
 *//*from w w w .j  a v a2s  . c om*/
private void initialize() throws IOException {

    java.io.InputStream io = SolrGazetteer.class.getResourceAsStream("/country-names-2013.csv");
    java.io.Reader countryIO = new InputStreamReader(io);
    CsvMapReader countryMap = new CsvMapReader(countryIO, CsvPreference.EXCEL_PREFERENCE);
    String[] columns = countryMap.getHeader(true);
    Map<String, String> country_names = null;
    while ((country_names = countryMap.read(columns)) != null) {
        String n = country_names.get("country_name");
        String cc = country_names.get("ISO2_cc");
        String fips = country_names.get("FIPS_cc");
        iso2fips.put(cc, fips);
        fips2iso.put(fips, cc);

        if (n == null || cc == null) {
            continue;
        }

        // FIPS could be *, but as long as we use ISO2, we're fine. if ("*".equals(cc)){ cc = fips.toUpperCase(); }

        // Normalize:              "US"  =>  "united states of america"
        _default_country_names.put(cc.toUpperCase(), n.toLowerCase());
    }

    if (_default_country_names.isEmpty()) {
        throw new IOException("No data found in country name map");
    }

    String config_solr_home = System.getProperty("solr.solr.home");
    solr = new SolrProxy(config_solr_home, "gazetteer");

    params.set(CommonParams.Q, "*:*");
    params.set(CommonParams.FL,
            "id,name,cc,adm1,adm2,feat_class,feat_code,lat,lon,place_id,name_bias,id_bias,name_type");
    try {
        loadCountries();
    } catch (SolrServerException loadErr) {
        throw new IOException(loadErr);
    }
}