List of usage examples for org.apache.solr.client.solrj SolrQuery get
@Override
public String get(String param)
From source file:org.apache.jackrabbit.oak.plugins.index.solr.query.FilterQueryParserTest.java
License:Apache License
@Test public void testAllChildrenQueryParsing() throws Exception { String query = "select [jcr:path], [jcr:score], * from [nt:hierarchy] as a where isdescendantnode(a, '/')"; Filter filter = mock(Filter.class); OakSolrConfiguration configuration = new DefaultSolrConfiguration() { @Override//from w ww. j av a2s.c o m public boolean useForPathRestrictions() { return true; } }; when(filter.getQueryStatement()).thenReturn(query); Filter.PathRestriction pathRestriction = Filter.PathRestriction.ALL_CHILDREN; when(filter.getPathRestriction()).thenReturn(pathRestriction); when(filter.getPath()).thenReturn("/"); QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class); SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration); assertNotNull(solrQuery); String[] filterQueries = solrQuery.getFilterQueries(); assertTrue(Arrays.asList(filterQueries) .contains(configuration.getFieldForPathRestriction(pathRestriction) + ":\\/")); assertEquals("*:*", solrQuery.get("q")); }
From source file:org.apache.jackrabbit.oak.plugins.index.solr.query.FilterQueryParserTest.java
License:Apache License
@Test public void testCollapseJcrContentNodes() throws Exception { String query = "select [jcr:path], [jcr:score], * from [nt:hierarchy] as a where isdescendantnode(a, '/')"; Filter filter = mock(Filter.class); OakSolrConfiguration configuration = new DefaultSolrConfiguration() { @Override//from w w w. jav a 2 s . c om public boolean collapseJcrContentNodes() { return true; } }; when(filter.getQueryStatement()).thenReturn(query); QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class); SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration); assertNotNull(solrQuery); String[] filterQueries = solrQuery.getFilterQueries(); assertTrue(Arrays.asList(filterQueries).contains("{!collapse field=" + configuration.getCollapsedPathField() + " min=" + configuration.getPathDepthField() + " hint=top_fc nullPolicy=expand}")); assertEquals("*:*", solrQuery.get("q")); }
From source file:org.apache.metron.solr.matcher.SolrQueryMatcher.java
License:Apache License
@Override public boolean matches(Object o) { SolrQuery solrQuery = (SolrQuery) o; return Objects.equals(solrQuery.getStart(), expectedSolrQuery.getStart()) && Objects.equals(solrQuery.getRows(), expectedSolrQuery.getRows()) && Objects.equals(solrQuery.getQuery(), expectedSolrQuery.getQuery()) && Objects.equals(solrQuery.getSorts(), expectedSolrQuery.getSorts()) && Objects.equals(solrQuery.getFields(), expectedSolrQuery.getFields()) && Arrays.equals(solrQuery.getFacetFields(), expectedSolrQuery.getFacetFields()) && Objects.equals(solrQuery.get("collection"), expectedSolrQuery.get("collection")) && Objects.equals(solrQuery.get("stats"), expectedSolrQuery.get("stats")) && Objects.equals(solrQuery.get("stats.field"), expectedSolrQuery.get("stats.field")) && Objects.equals(solrQuery.get("facet"), expectedSolrQuery.get("facet")) && Objects.equals(solrQuery.get("facet.pivot"), expectedSolrQuery.get("facet.pivot")); }
From source file:org.geotools.data.solr.SolrDataStore.java
License:Open Source License
private void addViewparams(Query q, SolrQuery query) { String qViewParamers = null;/*w w w . j a v a 2 s. c o m*/ String fqViewParamers = null; Hints hints = q.getHints(); if (hints != null) { Map<String, String> parameters = (Map<String, String>) hints.get(Hints.VIRTUAL_TABLE_PARAMETERS); if (parameters != null) { for (String param : parameters.keySet()) { // Accepts only q and fq query parameters if (param.equalsIgnoreCase("q")) { qViewParamers = parameters.get(param); } if (param.equalsIgnoreCase("fq")) { fqViewParamers = parameters.get(param); } } } } if (qViewParamers != null && !qViewParamers.isEmpty()) { query.set("q", query.get("q").concat(" AND ").concat(qViewParamers)); } if (fqViewParamers != null && !fqViewParamers.isEmpty()) { query.addFilterQuery(fqViewParamers); } }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
/** * Used by chord diagram//from ww w. j a va2 s .c o m * @param topLevelMpTerms the mp terms are used with AND. If not null returns data for genes that have ALL phenotypes in the passed list. * @param idg Option to get data only for IDG. Set to false or null if you want all data. * @param idgClass one of [GPCRs, Ion Channels, Ion Channels] * @return */ public JSONObject getPleiotropyMatrix(List<String> topLevelMpTerms, Boolean idg, String idgClass) throws IOException, SolrServerException, JSONException { try { SolrQuery query = getPleiotropyQuery(topLevelMpTerms, idg, idgClass); QueryResponse queryResponse = genotypePhenotypeCore.query(query, SolrRequest.METHOD.POST); Set<String> facets = getFacets(queryResponse).get(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME).keySet(); Map<String, Set<String>> genesByTopLevelMp = new HashMap<>(); // <mp, <genes>> Integer[][] matrix = new Integer[facets.size()][facets.size()]; // initialize labels -> needed to keep track of order for the matrix cells List<String> matrixLabels = facets.stream().collect(Collectors.toList()); // Fill matrix with 0s for (int i = 0; i < matrixLabels.size(); i++) { for (int j = 0; j < matrixLabels.size(); j++) { matrix[i][j] = 0; } genesByTopLevelMp.put(matrixLabels.get(i), new HashSet<>()); } Map<String, List<String>> facetPivotResults = getFacetPivotResults(queryResponse, query.get("facet.pivot")); // <gene, <top_level_mps>> // Count genes associated to each pair of top-level mps. Gene count not g-p doc count, nor allele. for (String gene : facetPivotResults.keySet()) { List<String> mpTerms = facetPivotResults.get(gene); for (int i = 0; i < matrixLabels.size(); i++) { String mpI = matrixLabels.get(i); if (mpTerms.contains(mpI)) { Set<String> temp = genesByTopLevelMp.get(mpI); temp.add(gene); genesByTopLevelMp.put(mpI, temp); if (mpTerms.size() > 1) { // Other phenotypes too for (int j = 0; j < matrixLabels.size(); j++) { String mpJ = matrixLabels.get(j); if (mpTerms.contains(mpJ)) { if (!mpI.equalsIgnoreCase(mpJ)) { matrix[i][j]++; } } } } else { // Only one top level mp for this gene; count as self, will display as arch to self matrix[i][i]++; } } } } List<JSONObject> labelList = genesByTopLevelMp.entrySet().stream().map(entry -> { try { return new JSONObject().put("name", entry.getKey()).put("geneCount", entry.getValue().size()); } catch (JSONException e) { e.printStackTrace(); } return null; }).collect(Collectors.toList()); JSONObject result = new JSONObject(); result.put("matrix", new org.springframework.boot.configurationprocessor.json.JSONArray(matrix)); result.put("labels", labelList); result.put("geneCount", facetPivotResults.keySet().size()); return result; } catch (SolrServerException | SQLException | IOException | JSONException e) { e.printStackTrace(); } return new JSONObject(); }
From source file:org.opencommercesearch.AbstractSearchServer.java
License:Apache License
private SearchResponse doSearch(SolrQuery query, Site site, RepositoryItem catalog, Locale locale, boolean isSearch, boolean isRuleBasedPage, String categoryPath, boolean isOutletPage, String brandId, FilterQuery... filterQueries) throws SearchServerException { if (site == null) { throw new IllegalArgumentException("Missing site"); }/*from www . ja v a 2 s.c om*/ if (catalog == null) { throw new IllegalArgumentException("Missing catalog"); } long startTime = System.currentTimeMillis(); query.addFacetField("category"); query.set("facet.mincount", 1); RuleManager ruleManager = new RuleManager(getSearchRepository(), getRulesBuilder(), getRulesSolrServer(locale)); if ((query.getRows() != null && query.getRows() > 0) || (query.get("group") != null && query.getBool("group"))) { setGroupParams(query, locale); setFieldListParams(query, locale.getCountry(), catalog.getRepositoryId()); try { ruleManager.setRuleParams(query, isSearch, isRuleBasedPage, categoryPath, filterQueries, catalog, isOutletPage, brandId); if (ruleManager.getRules().containsKey(SearchRepositoryItemDescriptor.REDIRECT_RULE)) { Map<String, List<RepositoryItem>> rules = ruleManager.getRules(); List<RepositoryItem> redirects = rules.get(SearchRepositoryItemDescriptor.REDIRECT_RULE); if (redirects != null) { RepositoryItem redirect = redirects.get(0); return new SearchResponse(query, null, null, null, (String) redirect.getPropertyValue(RedirectRuleProperty.URL), null, true); } } } catch (RepositoryException ex) { if (isLoggingError()) { logError("Unable to load search rules: " + ex.getMessage()); } throw create(SEARCH_EXCEPTION, ex); } catch (SolrServerException ex) { if (isLoggingError()) { logError("Unable to load search rules: " + ex.getMessage()); } throw create(SEARCH_EXCEPTION, ex); } catch (SolrException ex) { if (isLoggingError()) { logError("Unable to load search rules: " + ex.getMessage()); } throw create(SEARCH_EXCEPTION, ex); } } else { ruleManager.setFilterQueries(filterQueries, catalog.getRepositoryId(), query); } try { QueryResponse queryResponse = getCatalogSolrServer(locale).query(query); String correctedTerm = null; boolean matchesAll = true; //if no results, check for spelling errors if (query.getRows() > 0 && isEmptySearch(queryResponse.getGroupResponse()) && StringUtils.isNotEmpty(query.getQuery())) { SpellCheckResponse spellCheckResponse = queryResponse.getSpellCheckResponse(); //try to do searching for the corrected term matching all terms (q.op=AND) QueryResponse tentativeResponse = handleSpellCheck(spellCheckResponse, getCatalogSolrServer(locale), query, "AND"); if (tentativeResponse != null) { //if we got results, set the corrected term variable and proceed to return the results queryResponse = tentativeResponse; correctedTerm = spellCheckResponse.getCollatedResult(); } else { //if we didn't got any response, try doing another search matching any term (q.op=OR) tentativeResponse = handleSpellCheck(spellCheckResponse, getCatalogSolrServer(locale), query, "OR"); if (tentativeResponse != null) { //if we got results for the match any term scenario. Set similar results to true //and set the corrected term. queryResponse = tentativeResponse; matchesAll = false; correctedTerm = query.getQuery(); } } } long searchTime = System.currentTimeMillis() - startTime; if (isLoggingDebug()) { logDebug("Search time is " + searchTime + ", search engine time is " + queryResponse.getQTime()); } SearchResponse searchResponse = new SearchResponse(query, queryResponse, ruleManager, filterQueries, null, correctedTerm, matchesAll); searchResponse.setRuleQueryTime(ruleManager.getLoadRulesTime()); return searchResponse; } catch (SolrServerException ex) { throw create(SEARCH_EXCEPTION, ex); } catch (SolrException ex) { throw create(SEARCH_EXCEPTION, ex); } }
From source file:org.phenotips.vocabulary.internal.solr.FrenchHPOTranslationTest.java
License:Open Source License
@Test public void queriesAreExtendedToIncludeFrenchFieldsWhenLocaleIsFr() { SolrQuery query = new SolrQuery("seizures"); query.set(DisMaxParams.QF, "name"); query.set(DisMaxParams.PF, "name"); this.component.extendQuery(query, this.vocabulary); Assert.assertEquals("name name_fr^60 synonym_fr^45 def_fr^12 ", query.get(DisMaxParams.PF)); Assert.assertEquals("name name_fr^30 synonym_fr^21 def_fr^6 ", query.get(DisMaxParams.QF)); }
From source file:org.phenotips.vocabulary.internal.solr.FrenchHPOTranslationTest.java
License:Open Source License
@Test public void queriesAreExtendedToIncludeFrenchFieldsWhenLocaleIsFrFR() { when(this.localizationContext.getCurrentLocale()).thenReturn(Locale.FRANCE); SolrQuery query = new SolrQuery("seizures"); query.set(DisMaxParams.QF, "name"); query.set(DisMaxParams.PF, "name"); this.component.extendQuery(query, this.vocabulary); Assert.assertEquals("name name_fr^60 synonym_fr^45 def_fr^12 ", query.get(DisMaxParams.PF)); Assert.assertEquals("name name_fr^30 synonym_fr^21 def_fr^6 ", query.get(DisMaxParams.QF)); }
From source file:org.phenotips.vocabulary.internal.solr.FrenchHPOTranslationTest.java
License:Open Source License
@Test public void queriesAreNotModifiedWhenLocaleIsDe() { when(this.localizationContext.getCurrentLocale()).thenReturn(Locale.GERMAN); SolrQuery query = new SolrQuery("seizures"); query.set(DisMaxParams.QF, "name"); query.set(DisMaxParams.PF, "name"); this.component.extendQuery(query, this.vocabulary); Assert.assertEquals("name", query.get(DisMaxParams.PF)); Assert.assertEquals("name", query.get(DisMaxParams.QF)); }
From source file:org.phenotips.vocabulary.internal.solr.FrenchHPOTranslationTest.java
License:Open Source License
@Test public void queriesAreNotModifiedWhenLocaleIsNull() { when(this.localizationContext.getCurrentLocale()).thenReturn(null); SolrQuery query = new SolrQuery("seizures"); query.set(DisMaxParams.QF, "name"); query.set(DisMaxParams.PF, "name"); this.component.extendQuery(query, this.vocabulary); Assert.assertEquals("name", query.get(DisMaxParams.PF)); Assert.assertEquals("name", query.get(DisMaxParams.QF)); }