List of usage examples for org.apache.solr.common.params CommonParams FQ
String FQ
To view the source code for org.apache.solr.common.params CommonParams FQ.
Click Source Link
From source file:org.phenotips.vocabulary.internal.GeneNomenclature.java
License:Open Source License
private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort, String customFilter) {//from w ww . j a v a 2 s. com String escapedQuery = ClientUtils.escapeQueryChars(originalQuery.trim()); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(CommonParams.Q, escapedQuery); params.add(CommonParams.ROWS, rows.toString()); if (StringUtils.isNotBlank(sort)) { params.add(CommonParams.SORT, sort); } params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFilter, "status:Approved")); return params; }
From source file:org.phenotips.vocabulary.internal.solr.GeneNomenclature.java
License:Open Source License
private SolrQuery produceDynamicSolrParams(Map<String, String> staticOptions, String originalQuery, Integer rows, String sort, String customFilter) { String escapedQuery = ClientUtils.escapeQueryChars(originalQuery.trim()); SolrQuery params = new SolrQuery(escapedQuery); for (Map.Entry<String, String> option : staticOptions.entrySet()) { params.set(option.getKey(), option.getValue()); }//www . ja va 2s . c o m params.setRows(rows); if (StringUtils.isNotBlank(sort)) { params.add(CommonParams.SORT, sort); } params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFilter, "status:Approved")); return params; }
From source file:org.phenotips.vocabulary.internal.solr.HumanPhenotypeOntology.java
License:Open Source License
private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort, String customFq, boolean isId) { String query = originalQuery.trim(); ModifiableSolrParams params = new ModifiableSolrParams(); String escapedQuery = ClientUtils.escapeQueryChars(query); if (isId) {/*from w w w . j a va 2 s . c om*/ params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFq, new MessageFormat("id:{0} alt_id:{0}").format(new String[] { escapedQuery }))); } else { params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFq, "term_category:HP\\:0000118")); } params.add(CommonParams.Q, escapedQuery); params.add(SpellingParams.SPELLCHECK_Q, query); params.add(CommonParams.ROWS, rows.toString()); if (StringUtils.isNotBlank(sort)) { params.add(CommonParams.SORT, sort); } return params; }
From source file:org.phenotips.vocabulary.internal.solr.MendelianInheritanceInMan.java
License:Open Source License
private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort, String customFq) { String query = originalQuery.trim(); ModifiableSolrParams params = new ModifiableSolrParams(); String escapedQuery = ClientUtils.escapeQueryChars(query); params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFq, "-(nameSort:\\** nameSort:\\+* nameSort:\\^*)")); params.add(CommonParams.Q, escapedQuery); params.add(SpellingParams.SPELLCHECK_Q, query); String lastWord = StringUtils.substringAfterLast(escapedQuery, " "); if (StringUtils.isBlank(lastWord)) { lastWord = escapedQuery;// www .j a va2s .c o m } lastWord += "*"; params.add(DisMaxParams.BQ, String.format("nameSpell:%1$s^20 keywords:%1$s^2 text:%1$s^1 textSpell:%1$s^2", lastWord)); params.add(CommonParams.ROWS, rows.toString()); if (StringUtils.isNotBlank(sort)) { params.add(CommonParams.SORT, sort); } return params; }
From source file:org.sakaiproject.nakamura.api.search.solr.DomainObjectSearchQueryHandler.java
License:Apache License
/** * Set up standard query option values and then give subclasses a chance * to refine it.//from ww w . jav a 2 s. c om */ public void configureQuery(Map<String, String> parametersMap, Query query) { Map<String, Object> queryOptions = query.getOptions(); // Configure the standard Filter Queries. Set<String> filterQueries = new HashSet<String>(); filterQueries.add(getResourceTypeClause(parametersMap)); queryOptions.put(CommonParams.FQ, filterQueries); // Configure sorting. final String sort; String sortKey = parametersMap.get(DEFAULT_REQUEST_PARAMS.sortOn.toString()); String sortOrder = parametersMap.get(DEFAULT_REQUEST_PARAMS.sortOrder.toString()); if ((sortKey == null) || (sortOrder == null)) { sort = getDefaultSort(); } else { sort = sortKey + " " + sortOrder; } queryOptions.put(CommonParams.SORT, sort); // Configure default faceting. queryOptions.putAll(QUERY_OPTIONS_MAP); // And now let the domain-specific code have its say. refineQuery(parametersMap, query); }
From source file:org.sakaiproject.nakamura.search.solr.SolrResultSetFactory.java
License:Apache License
/** * Process a query string to search using Solr. * * @param request//from ww w.java 2 s.c o m * @param query * @param asAnon * @param rs * @return * @throws SolrSearchException */ @SuppressWarnings("rawtypes") public SolrSearchResultSet processQuery(SlingHttpServletRequest request, Query query, boolean asAnon) throws SolrSearchException { try { // Add reader restrictions to solr fq (filter query) parameter, // to prevent "reader restrictions" from affecting the solr score // of a document. Map<String, Object> originalQueryOptions = query.getOptions(); Map<String, Object> queryOptions = Maps.newHashMap(); Object filterQuery = null; if (originalQueryOptions != null) { // copy from originalQueryOptions in case its backed by a ImmutableMap, // which prevents saving of filter query changes. queryOptions.putAll(originalQueryOptions); if (queryOptions.get(CommonParams.FQ) != null) { filterQuery = queryOptions.get(CommonParams.FQ); } } Set<String> filterQueries = Sets.newHashSet(); // add any existing filter queries to the set if (filterQuery != null) { if (filterQuery instanceof Object[]) { CollectionUtils.addAll(filterQueries, (Object[]) filterQuery); } else if (filterQuery instanceof Iterable) { CollectionUtils.addAll(filterQueries, ((Iterable) filterQuery).iterator()); } else { filterQueries.add(String.valueOf(filterQuery)); } } // apply readers restrictions. if (asAnon) { filterQueries.add("readers:" + User.ANON_USER); } else { Session session = StorageClientUtils .adaptToSession(request.getResourceResolver().adaptTo(javax.jcr.Session.class)); if (!User.ADMIN_USER.equals(session.getUserId())) { AuthorizableManager am = session.getAuthorizableManager(); Authorizable user = am.findAuthorizable(session.getUserId()); Set<String> readers = Sets.newHashSet(); for (Iterator<Group> gi = user.memberOf(am); gi.hasNext();) { readers.add(SearchUtil.escapeString(gi.next().getId(), Query.SOLR)); } readers.add(SearchUtil.escapeString(session.getUserId(), Query.SOLR)); filterQueries.add("readers:(" + StringUtils.join(readers, " OR ") + ")"); } } List<String> deletedPaths = deletedPathsService.getDeletedPaths(); if (!deletedPaths.isEmpty()) { // these are escaped as they are collected filterQueries.add("-path:(" + StringUtils.join(deletedPaths, " OR ") + ")"); } // save filterQuery changes queryOptions.put(CommonParams.FQ, filterQueries); SolrQuery solrQuery = buildQuery(request, query.getQueryString(), queryOptions); SolrServer solrServer = solrSearchService.getServer(); if (LOGGER.isDebugEnabled()) { try { LOGGER.debug("Performing Query {} ", URLDecoder.decode(solrQuery.toString(), "UTF-8")); } catch (UnsupportedEncodingException e) { } } long tquery = System.currentTimeMillis(); QueryResponse response = solrServer.query(solrQuery); tquery = System.currentTimeMillis() - tquery; try { if (tquery > verySlowQueryThreshold) { SLOW_QUERY_LOGGER.error("Very slow solr query {} ms {} ", tquery, URLDecoder.decode(solrQuery.toString(), "UTF-8")); } else if (tquery > slowQueryThreshold) { SLOW_QUERY_LOGGER.warn("Slow solr query {} ms {} ", tquery, URLDecoder.decode(solrQuery.toString(), "UTF-8")); } } catch (UnsupportedEncodingException e) { } SolrSearchResultSetImpl rs = new SolrSearchResultSetImpl(response); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Got {} hits in {} ms", rs.getSize(), response.getElapsedTime()); } return rs; } catch (StorageClientException e) { throw new SolrSearchException(500, e.getMessage()); } catch (AccessDeniedException e) { throw new SolrSearchException(500, e.getMessage()); } catch (SolrServerException e) { throw new SolrSearchException(500, e.getMessage()); } }
From source file:org.tallison.solr.search.concordance.SolrConcordanceBase.java
License:Apache License
public static List<Query> parseFilters(Query q, SolrQueryRequest req) throws SyntaxError { List<Query> filters = null; filters = new ArrayList<Query>(); if (q != null) filters.add(q);/* w w w.j a v a 2 s .c o m*/ String[] fqs = req.getParams().getParams(CommonParams.FQ); if (fqs != null && fqs.length != 0) { for (String fq : fqs) { if (fq != null && fq.trim().length() != 0) { QParser fqp = QParser.getParser(fq, null, req); filters.add(fqp.getQuery()); } } } return filters; }