List of usage examples for org.apache.solr.client.solrj SolrQuery getQuery
public String getQuery()
From source file:org.xume.solrcriteria.SolrjCriteriaTest.java
License:Apache License
@Test public void testQueryMultipleTerms() { SolrQuery query = criteria().query(new StubTerm("lorem")).query(new StubTerm("ipsum")).buildQuery(); assertThat(query.getQuery(), equalTo("(lorem ipsum)")); }
From source file:org.zenoss.zep.index.impl.solr.SolrEventIndexBackend.java
License:Open Source License
private EventSummaryResult execute(final SolrQuery query, boolean justUuids) throws ZepException { EventSummaryResult.Builder result = EventSummaryResult.newBuilder(); logger.debug("Searching SOLR for events matching: {}", query.getQuery()); final long now = logger.isDebugEnabled() ? System.currentTimeMillis() : 0; final QueryResponse response; try {// ww w .j ava 2s.co m response = queryServer.query(query); final int numFound = (int) response.getResults().getNumFound(); result.setTotal(numFound); if (query.getRows() != null) { final int limit = query.getRows(); final int offset = (query.getStart() == null) ? 0 : query.getStart(); result.setLimit(limit); if (numFound > offset + limit) result.setNextOffset(offset + limit); } logger.debug("Found {} results in SOLR", numFound); if (justUuids) { for (SolrDocument doc : response.getResults()) result.addEvents(SolrEventIndexMapper.toEventSummary(doc)); } else { Map<String, EventSummary> sortedResults = Maps.newLinkedHashMap(); Set<EventSummary> toLookup = Sets.newHashSet(); for (SolrDocument doc : response.getResults()) { EventSummary event = SolrEventIndexMapper.toEventSummary(doc); if (event.hasFirstSeenTime()) { sortedResults.put(event.getUuid(), event); } else { // We only store keys in the index for archived events. This must be one of those. // Set a place-holder now. We'll find it in the database shortly. sortedResults.put(event.getUuid(), null); toLookup.add(event); } } if (!toLookup.isEmpty()) { final long beforeLookup = System.currentTimeMillis(); logger.debug("Looking up {} events by UUID", toLookup.size()); List<EventSummary> events = archiveDao.findByKey(toLookup); if (events.size() != toLookup.size()) { int missing = toLookup.size() - events.size(); logger.info( "Event archive index out of sync - {} of {} event UUIDs are in Solr index, but not in database.", missing, toLookup.size()); } for (EventSummary event : events) sortedResults.put(event.getUuid(), event); // a re-insertion -- solr sort is preserved. logger.debug("Query spent {} milliseconds to lookup {} events by UUID.", System.currentTimeMillis() - beforeLookup, toLookup.size()); } else { logger.debug("Query did not have to lookup any events by UUID"); } for (EventSummary event : sortedResults.values()) if (event != null) result.addEvents(event); } } catch (SolrServerException e) { throw new ZepException(e); } finally { if (logger.isDebugEnabled()) logger.debug("Query {} finished in {} milliseconds", query, System.currentTimeMillis() - now); } return result.build(); }
From source file:podd.search.impl.IndexSearcherImpl.java
License:Open Source License
@Override public SearchResponse search(SearchCriteria criteria) { SolrQuery solrQuery = createQuery(criteria); // Only perform a search if there is a valid query if (StringUtils.hasText(solrQuery.getQuery())) { try {/* w w w. ja v a2s .c om*/ QueryResponse queryResponse = solrServer.query(solrQuery); return new SearchResponseImpl(queryResponse, criteria.getPageSize(), solrQuery.getHighlightFragsize()); } catch (SolrServerException e) { LOGGER.error("Found exception", e); } } return null; }
From source file:se.uu.ub.cora.solrsearch.SolrRecordSearchTest.java
License:Open Source License
@Test public void testSearchOneParameterNoRecordType() { DataGroup searchData = createSearchIncludeDataWithSearchTermIdAndValue("titleSearchTerm", "A title"); SpiderSearchResult searchResult = solrSearch.searchUsingListOfRecordTypesToSearchInAndSearchData(emptyList, searchData);// ww w . j av a 2 s. c o m assertNotNull(searchResult.listOfDataGroups); DataGroup firstResult = searchResult.listOfDataGroups.get(0); assertEquals(firstResult.getNameInData(), "book"); SolrQuery solrQueryCreated = (SolrQuery) solrClientSpy.params; assertEquals(solrQueryCreated.getQuery(), "title_s:(A title)"); assertEquals(searchStorage.searchTermIds.get(0), "titleSearchTerm"); assertEquals(searchStorage.collectIndexTermIds.get(0), "titleIndexTerm"); }
From source file:se.uu.ub.cora.solrsearch.SolrRecordSearchTest.java
License:Open Source License
private String extractCreatedParameterSuffix(SolrQuery solrQueryCreated) { String query = solrQueryCreated.getQuery(); return query.substring(query.indexOf("_"), query.indexOf(":")); }
From source file:se.uu.ub.cora.solrsearch.SolrRecordSearchTest.java
License:Open Source License
@Test public void testSearchLInkedDataOneParameterOneRecordType() { DataGroup searchData = createSearchIncludeDataWithSearchTermIdAndValue("linkedTextSearchTerm", "textToSearchFor"); List<String> recordTypeList = new ArrayList<>(); recordTypeList.add("someRecordType"); solrSearch.searchUsingListOfRecordTypesToSearchInAndSearchData(recordTypeList, searchData); SolrQuery solrQueryCreated = (SolrQuery) solrClientSpy.params; String[] createdFilterQueries = solrQueryCreated.getFilterQueries(); assertEquals(createdFilterQueries[0], "type:someRecordType"); assertEquals(solrQueryCreated.getQuery(), "{!join from=ids to=textId_s}swedish_t:textToSearchFor AND type:coraText"); }
From source file:uk.ac.ebi.atlas.solr.query.PropertyValueQueryBuilderTest.java
License:Apache License
@Test public void testBuildAutocompleteSuggestionQuery() throws Exception { // given//from ww w. ja v a 2 s .c om SolrQuery solrQuery = subject.withSpecies("species").withBioentityTypes(Sets.newHashSet("ensgene")) .withPropertyNames(new String[] { "prototype1", "prototype2" }) .buildPropertyValueAutocompleteQuery("geneX"); // then assertThat(solrQuery.getQuery(), is(SolrQueryService.PROPERTY_EDGENGRAM_FIELD + ":\"geneX\" AND " + SolrQueryBuilder.SPECIES_FIELD + ":\"species\" AND (" + SolrQueryService.BIOENTITY_TYPE_FIELD + ":\"ensgene\") AND (" + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype1\" OR " + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype2\")")); }
From source file:uk.ac.ebi.atlas.solr.query.PropertyValueQueryBuilderTest.java
License:Apache License
@Test public void testBuildBioentityQuery() throws Exception { // given// ww w .j a va 2s . c om SolrQuery solrQuery = subject.withPropertyNames(new String[] { "prototype1", "prototype2" }) .buildBioentityQuery("ENSMUS000000"); // then assertThat(solrQuery.getQuery(), is(SolrQueryService.BIOENTITY_IDENTIFIER_FIELD + ":\"ENSMUS000000\" AND (" + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype1\" OR " + SolrQueryService.PROPERTY_NAME_FIELD + ":\"prototype2\")")); }
From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.params.UrlSolrParamsTest.java
License:Apache License
@Test public void params1() throws Exception { String params = "q=*:*&sort=rigid asc&rows=30&fq=+dataset:(\"Cancer\")&fq=+go_expanded_id:(\"GO:0048511\")&start=0"; UrlSolrParams solrParams = new UrlSolrParams(params); SolrQuery solrQuery = new SolrQuery(); solrQuery.add(solrParams);//w ww.j a va 2s . c o m Assert.assertEquals("*:*", solrQuery.getQuery()); Assert.assertEquals("rigid asc", solrQuery.getSortField()); Assert.assertEquals(Integer.valueOf(30), solrQuery.getRows()); Assert.assertEquals(Integer.valueOf(0), solrQuery.getStart()); Assert.assertTrue(Arrays.asList(solrQuery.getFilterQueries()).contains("+go_expanded_id:(\"GO:0048511\")")); Assert.assertTrue(Arrays.asList(solrQuery.getFilterQueries()).contains("+dataset:(\"Cancer\")")); }