當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrQuery類代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery類的具體用法?Java SolrQuery怎麽用?Java SolrQuery使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SolrQuery類屬於org.apache.solr.client.solrj包,在下文中一共展示了SolrQuery類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addDefaultParams

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
private void addDefaultParams(SolrQuery solrQuery, SolrEndpointConfiguration config) {
    if(MapUtils.isNotEmpty(config.getDefaults())){
        config.getDefaults().entrySet().stream()
        .filter(e -> StringUtils.isNoneBlank(e.getKey()) && e.getValue() != null)
        .forEach(e -> {
            String param = e.getKey();
            Collection<?> values;
            if(e.getValue() instanceof Collection){
                values = (Collection<?>)e.getValue();
            } else if(e.getValue().getClass().isArray()) {
                 values = Arrays.asList((Object[])e.getValue());
            } else {
                values = Collections.singleton(e.getValue());
            }
            Collection<String> strValues = StreamSupport.stream(values.spliterator(), false)
                    .map(Objects::toString) //convert values to strings
                    .filter(StringUtils::isNoneBlank) //filter blank values
                    .collect(Collectors.toList());
            if(!strValues.isEmpty()){
                solrQuery.add(param, strValues.toArray(new String[strValues.size()]));
            }
        });
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:25,代碼來源:SolrSearchQueryBuilder.java

示例2: main

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
		String zkHost = "localhost:2181";
		String defaultCollection = "collection1";
		CloudSolrServer solr = new CloudSolrServer(zkHost);
		solr.setDefaultCollection(defaultCollection);
        
/*		ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("q", "cat:electronics");
    	params.set("defType", "edismax");
    	params.set("start", "0");*/
		
		SolrQuery params = new SolrQuery();
		params.setQuery("*:*");
		params.setSort("score ",ORDER.desc);
		params.setStart(Integer.getInteger("0"));
		params.setRows(Integer.getInteger("100"));
		
    

		QueryResponse response = solr.query(params);
		SolrDocumentList results = response.getResults();
		for (int i = 0; i < results.size(); ++i) {
			System.out.println(results.get(i));
		}
	}
 
開發者ID:dimensoft,項目名稱:improved-journey,代碼行數:26,代碼來源:SolrCloudSolrJSearcher.java

示例3: getResultCount

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * Returns how many solr documents match the given query.
 * @param query a solr `q` query.
 * @return solr document count.
 * @deprecated use {@link #search(SolrQuery)}{@code .getNumFound()}.
 */
@Deprecated
@PreAuthorize("hasRole('ROLE_SEARCH')")
public int getResultCount(String query)
{
   try
   {
      query = solrDao.updateQuery(query);
      return (int) solrDao.search(new SolrQuery(query)).getResults().getNumFound();
   }
   catch (SolrServerException | IOException ex)
   {
      LOGGER.error(ex);
      throw new DHusSearchException("An exception occured while searching", ex);
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:22,代碼來源:SearchService.java

示例4: processHighlightOptions

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * Append highlighting parameters to {@link org.apache.solr.client.solrj.SolrQuery}
 *
 * @param solrQuery
 * @param query
 */
protected void processHighlightOptions(SolrQuery solrQuery, HighlightQuery query) {
	if (query.hasHighlightOptions()) {
		HighlightOptions highlightOptions = query.getHighlightOptions();
		solrQuery.setHighlight(true);
		if (!highlightOptions.hasFields()) {
			solrQuery.addHighlightField(HighlightOptions.ALL_FIELDS.getName());
		} else {
			for (Field field : highlightOptions.getFields()) {
				solrQuery.addHighlightField(field.getName());
			}
			for (FieldWithHighlightParameters fieldWithHighlightParameters : highlightOptions
					.getFieldsWithHighlightParameters()) {
				addPerFieldHighlightParameters(solrQuery, fieldWithHighlightParameters);
			}
		}
		for (HighlightParameter option : highlightOptions.getHighlightParameters()) {
			addOptionToSolrQuery(solrQuery, option);
		}
		if (highlightOptions.hasQuery()) {
			solrQuery.add(HighlightParams.Q, getQueryString(highlightOptions.getQuery()));
		}
	}
}
 
開發者ID:yiduwangkai,項目名稱:dubbox-solr,代碼行數:30,代碼來源:DefaultQueryParser.java

示例5: main

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
		HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
//		  ModifiableSolrParams params = new ModifiableSolrParams(); 
//        params.setQuery("name:Samsung ");
//        params.setStart(0);
//        params.setRows(100);
		SolrQuery params = new SolrQuery();
		params.setQuery("*:*");
		params.setSort("score ",ORDER.desc);
		params.setStart(Integer.getInteger("0"));
		params.setRows(Integer.getInteger("100"));

		QueryResponse response = solr.query(params);
		SolrDocumentList results = response.getResults();
		for (int i = 0; i < results.size(); ++i) {
			System.out.println(results.get(i));
		}
	}
 
開發者ID:dimensoft,項目名稱:improved-journey,代碼行數:19,代碼來源:SolrJSearcher.java

示例6: search

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * searches and returns a list of {@link SolrDocument}
 * 
 * @param from startdate
 * @param until enddate
 * @param set which collection
 * @param metadataPrefix
 * @param firstRow
 * @param numRows
 * @param urnOnly
 * @param querySuffix
 * @return list of hits as {@link SolrDocument}
 * @throws IOException
 * @throws SolrServerException
 */
public SolrDocumentList search(String from, String until, String set, String metadataPrefix, int firstRow, int numRows, boolean urnOnly,
        String querySuffix) throws IOException, SolrServerException {
    StringBuilder sbQuery = new StringBuilder(buildQueryString(from, until, set, metadataPrefix, urnOnly, querySuffix));
    if (urnOnly) {
        sbQuery.append(" AND (").append(SolrConstants.URN).append(":* OR ").append(SolrConstants.IMAGEURN_OAI).append(":*)");
    }
    sbQuery.append(getAllSuffixes());
    logger.debug("OAI query: {}", sbQuery.toString());
    SolrQuery solrQuery = new SolrQuery(sbQuery.toString());
    solrQuery.setStart(firstRow);
    solrQuery.setRows(numRows);
    solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
    QueryResponse resp = server.query(solrQuery);
    logger.debug("Total hits: {}, fetched records {} - {}", resp.getResults().getNumFound(), firstRow, firstRow + resp.getResults().size() - 1);

    return resp.getResults();
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:33,代碼來源:SolrSearchIndex.java

示例7: query

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * 
 * @param identifier
 * @param metadataPrefix
 * @param rows
 * @return
 * @throws SolrServerException
 */
private SolrDocumentList query(final String identifier, String metadataPrefix, int rows) throws SolrServerException {
    String useIdentifier = ClientUtils.escapeQueryChars(identifier);

    StringBuilder sb = new StringBuilder();
    sb.append('(').append(SolrConstants.PI).append(':').append(useIdentifier).append(" OR ").append(SolrConstants.URN).append(':').append(
            useIdentifier).append(" OR ").append(SolrConstants.IMAGEURN).append(':').append(useIdentifier).append(')');
    sb.append(getAllSuffixes());
    logger.debug(sb.toString());
    SolrQuery solrQuery = new SolrQuery(sb.toString());
    solrQuery.setRows(rows);
    QueryResponse resp = server.query(solrQuery);

    //        if (resp.getResults().isEmpty() && Metadata.epicur.name().equals(metadataPrefix)) {
    //            solrQuery = new SolrQuery(new StringBuilder(SolrConstants.IMAGEURN_OAI).append(":").append(identifier).toString());
    //            solrQuery.setRows(rows);
    //            resp = server.query(solrQuery);
    //        }

    return resp.getResults();
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:29,代碼來源:SolrSearchIndex.java

示例8: getSets

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * Creates a list with all available values for the given field (minus any blacklisted values).
 * 
 * @return
 * @throws SolrServerException
 * @should return all values
 */
public List<String> getSets(String field) throws SolrServerException {
    List<String> ret = new ArrayList<>();

    SolrQuery query = new SolrQuery();
    query.setQuery(field + ":* " + DataManager.getInstance().getConfiguration().getCollectionBlacklistFilterSuffix());
    query.setStart(0);
    query.setRows(0);
    query.addFacetField(field);
    logger.trace("Set query: {}", query.getQuery());
    QueryResponse resp = server.query(query);

    FacetField facetField = resp.getFacetField(field);
    if (facetField != null) {
        for (Count count : facetField.getValues()) {
            if (count.getCount() == 0) {
                continue;
            }
            ret.add(count.getName());
        }
    }

    Collections.sort(ret);
    logger.trace("{} terms found for {}", ret.size(), field);
    return ret;
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:33,代碼來源:SolrSearchIndex.java

示例9: getTotalHitNumber

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * 
 * @param params
 * @param urnOnly
 * @param querySuffix
 * @return size of search
 * @throws IOException
 * @throws SolrServerException
 */
public long getTotalHitNumber(Map<String, String> params, boolean urnOnly, String querySuffix) throws IOException, SolrServerException {
    StringBuilder sbQuery = new StringBuilder(buildQueryString(params.get("from"), params.get("until"), params.get("set"), params.get(
            "metadataPrefix"), urnOnly, querySuffix));
    if (urnOnly) {
        sbQuery.append(" AND (").append(SolrConstants.URN).append(":* OR ").append(SolrConstants.IMAGEURN_OAI).append(":*)");
    }
    sbQuery.append(getAllSuffixes());
    logger.debug("OAI query: {}", sbQuery.toString());
    SolrQuery solrQuery = new SolrQuery(sbQuery.toString());
    solrQuery.setStart(0);
    solrQuery.setRows(0);
    solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
    QueryResponse resp = server.query(solrQuery);

    long num = resp.getResults().getNumFound();
    logger.debug("Total hits: {}", num);
    return num;
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:28,代碼來源:SolrSearchIndex.java

示例10: search

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * Search.
 * <p>
 * Set `start` and `rows` values in the SolrQuery parameter to paginate the results.<br>
 * <strong>If no `rows` have been set, solr will only return 10 documents, no more.</strong>
 * <p>
 * To get the total number of document matching the given query, use {@code res.getNumFound()}.
 *
 * @param query a SolrQuery with at least a 'q' parameter set.
 * @return A list of solr document matching the given query.
 */
@PreAuthorize("hasRole('ROLE_SEARCH')")
public SolrDocumentList search(SolrQuery query)
{
   Objects.requireNonNull(query);

   query.setQuery(solrDao.updateQuery(query.getQuery()));
   try
   {
      return solrDao.search(query).getResults();
   }
   catch (SolrServerException | IOException ex)
   {
      LOGGER.error(ex);
      throw new DHusSearchException("An exception occured while searching", ex);
   }
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:28,代碼來源:SearchService.java

示例11: testRuntimeLib

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
    SearchServer server = testSearchServer.getSearchServer();

    SolrClient client = (SolrClient) server.getBackend();

    SolrInputDocument document = new SolrInputDocument();
    document.setField("_id_", "1");
    document.setField("_type_", "doc");
    document.setField("dynamic_multi_facet_string_f1", "test");
    document.setField("dynamic_multi_facet_string_f2", "hello");

    client.add(document);
    client.commit();

    SolrQuery query = new SolrQuery("t");
    query.setRequestHandler("/suggester");
    query.set("suggestion.df", "facets");
    query.set("suggestion.field", "dynamic_multi_facet_string_f1");

    QueryResponse response = client.query(query);

    assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:25,代碼來源:TestServerTest.java

示例12: getVersionAndInstallIfNecessary

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
public Long getVersionAndInstallIfNecessary(String dependency) {

        try {
            SolrQuery query = new SolrQuery("blobName:"+Utils.toBlobName(dependency));
            query.setSort("version", SolrQuery.ORDER.desc);
            QueryResponse response = client.query(".system",query);

            if(response.getResults().getNumFound() > 0) { //should could look for updates here as well?

                return Long.valueOf(response.getResults().get(0).get("version").toString());
            } else {
                Path configDirectory = Files.createTempDirectory(dependency);

                Path jarFile = Utils.downloadToTempDir(configDirectory, repositories, dependency);

                return uploadRuntimeLib(dependency, jarFile);
            }

        } catch (SolrServerException | IOException e) {
            logger.warn("Cannot load runtime dependeny " + dependency + ". This may cause runtime issues.");
            return -1L;
        }
    }
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:24,代碼來源:CollectionManagementService.java

示例13: execute

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
@Override
public SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory) {
    SolrQuery query = buildSolrQuery(search, assets, childFactory);

    try {
        log.debug(">>> query({})", query.toString());
        QueryResponse response = solrClient.query(query);
        if(response!=null){
            return SolrUtils.Result.buildSuggestionResult(response, assets, childFactory, search.getSearchContext());
        }else {
            log.error("Null result from SolrClient");
            throw new SolrServerException("Null result from SolrClient");
        }

    } catch (SolrServerException | IOException e) {
        log.error("Cannot execute suggestion query");
        throw new SearchServerException("Cannot execute suggestion query", e);
    }
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:20,代碼來源:SolrSearchServer.java

示例14: toHash

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
private int toHash(Object object) {
	// FIXME ugly af..
	if (object instanceof Artifact) {
		return ((Artifact) object).hashCode();
	} else if (object instanceof URI) {
		return ((URI) object).hashCode();
	} else if (object instanceof SolrQuery) {
		return ((SolrQuery) object).toString().hashCode();
	} else if (object instanceof Page) {
		Page<?, ?> page = ((Page<?, ?>) object);
		Optional<?> keyOptional = page.getKey();
		if (keyOptional.isPresent()) {
			return this.toHash(keyOptional.get());
		}
		return page.getElements().stream().map(element -> this.toHash(element))
				.collect(Collectors.reducing((a, b) -> a + b)).orElse(page.hashCode());
	}
	throw new IllegalArgumentException(
			String.format("Must be of ARtifact, URI, SolrQuery or Page, but was '%s'", object.toString()));
}
 
開發者ID:maenu,項目名稱:kowalski,代碼行數:21,代碼來源:MessageConverter.java

示例15: findCurrentDataRepository

import org.apache.solr.client.solrj.SolrQuery; //導入依賴的package包/類
/**
 * 
 * @param pi
 * @return The name of the data repository currently used for the record with the given PI; "?" if the record is indexed, but not in a repository;
 *         null if the record is not in the index
 * @throws SolrServerException
 * @should find correct data repository for record
 */
public String findCurrentDataRepository(String pi) throws SolrServerException {
    SolrQuery solrQuery = new SolrQuery(SolrConstants.PI + ":" + pi);
    solrQuery.setRows(1);
    solrQuery.setFields(SolrConstants.DATAREPOSITORY);
    QueryResponse resp = server.query(solrQuery);

    if (!resp.getResults().isEmpty()) {
        if (resp.getResults().get(0).getFieldValue(SolrConstants.DATAREPOSITORY) != null) {
            return (String) resp.getResults().get(0).getFieldValue(SolrConstants.DATAREPOSITORY);
        }
        return "?";
    }

    return null;
}
 
開發者ID:intranda,項目名稱:goobi-viewer-indexer,代碼行數:24,代碼來源:SolrHelper.java


注:本文中的org.apache.solr.client.solrj.SolrQuery類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。