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


Java SolrQuery.addField方法代碼示例

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


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

示例1: configureQueryForDocuments

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private void configureQueryForDocuments(SolrQuery query) {
    query.addFilterQuery("domain:document");
    query.addSort("reference_date_time", ORDER.desc);

    query.addField(Document.SOLR_LOCAL_TITLE_FIELD);
    query.addField(Document.SOLR_DOC_DEF_UID_FIELD);
    query.addField(Document.SOLR_DOCUMENT_STATUS_FIELD);
    query.addField(Document.SOLR_AUTHOR_UID_FIELD);
    query.addField(Document.SOLR_SIGNER_UID_FIELD);
    query.addField(Document.SOLR_COSIGNER_UID_FIELD);
    query.addField((Document.SOLR_ATTENDING_UID_FIELD));
    query.addField(Document.SOLR_IS_INTERDISCIPLINARY_FIELD);
    query.addField(Document.SOLR_INTERDISCIPLINARY_TYPE_FIELD);

    query.addField(SearchService.PHRASE);

    query.set(GroupParams.GROUP, true);
    query.set(GroupParams.GROUP_FIELD, Document.SOLR_LOCAL_TITLE_FIELD);
    query.setHighlight(true);
    query.addHighlightField("body").addHighlightField("subject");
    query.setHighlightFragsize(45);
    query.setHighlightSnippets(5);
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:24,代碼來源:GoldSearchFrame.java

示例2: list

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
protected void list(final PatientSearch search, FrameTask task) throws FrameException {
	if (!search.searchType("problem")) return;
	SolrQuery query = search.initQuery();
	query.setQuery("domain:problem");
	query.addFilterQuery("-removed:true");
    query.addField("smile,comment,icd_code,icd_name,icd_group,problem_status,acuity_name,onset,entered");
    query.addFilterQuery("domain:problem");
    query.addSort("problem_status", ORDER.asc);
	query.addSort(SearchService.DATETIME, ORDER.desc);
	query.set(GroupParams.GROUP, true);
	query.set(GroupParams.GROUP_FIELD, "icd_group");
	query.set(GroupParams.GROUP_LIMIT, 11);
	
	QueryResponse results = execSolrQuery(query, task);
	task.addAction(new SolrProblemSearchAction(search, query, results, this.view));
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:18,代碼來源:GoldSearchFrame.java

示例3: prepareQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery prepareQuery(PatientSearch search, boolean highlight) {
	SolrQuery query = search.initQuery();
	query.addFilterQuery("domain:med");
	query.addSort("overall_stop", ORDER.desc);
	query.addField("qualified_name");
	query.addField("va_type");
	query.addField("last_filled");
	query.addField("last_give");
	query.addField(CLASS_FIELD);
	query.set(GroupParams.GROUP, true);
	query.set(GroupParams.GROUP_FIELD, "kind");
	query.add(GroupParams.GROUP_FIELD, "qualified_name");
	
	if (highlight) {
		query.setHighlight(true);
	    query.addHighlightField("administration_comment");
	    query.addHighlightField("prn_reason");
	    query.setHighlightFragsize(72);
	    query.setHighlightSnippets(5);
	}
	
	return query;
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:24,代碼來源:MedsSearchFrame.java

示例4: getEarliestRecordDatestamp

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public String getEarliestRecordDatestamp() throws SolrServerException {
    try {
        String searchStr = SolrConstants.ISWORK + ":true" + getAllSuffixes();

        SolrQuery solrQuery = new SolrQuery(searchStr);
        solrQuery.setRows(1);
        solrQuery.addField(SolrConstants.DATECREATED);
        solrQuery.addSort(SolrConstants.DATECREATED, ORDER.asc);
        QueryResponse resp = server.query(solrQuery);

        if (resp.getResults().size() > 0) {
            SolrDocument doc = resp.getResults().get(0);
            if (doc.getFieldValue(SolrConstants.DATECREATED) != null) {
                Date d = new Date((Long) doc.getFieldValue(SolrConstants.DATECREATED));
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// ;YYYY-MM-DDThh:mm:ssZ
                SimpleDateFormat hours = new SimpleDateFormat("HH:mm:ss");
                format.setTimeZone(TimeZone.getTimeZone("GMT"));
                hours.setTimeZone(TimeZone.getTimeZone("GMT"));
                String yearMonthDay = format.format(d);
                String hourMinuteSeconde = hours.format(d);

                return yearMonthDay + "T" + hourMinuteSeconde + "Z";
            }
        }
    } catch (NullPointerException e) {
        logger.error(e.getMessage(), e);
    }
    return "";
}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:30,代碼來源:SolrSearchIndex.java

示例5: search

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * 
 * @param query
 * @param fields
 * @param rows
 * @return
 * @throws SolrServerException
 */
public SolrDocumentList search(String query, List<String> fields, int rows) throws SolrServerException {
    SolrQuery solrQuery = new SolrQuery(query);
    solrQuery.setRows(MAX_HITS);
    if (fields != null) {
        for (String field : fields) {
            solrQuery.addField(field);
        }
    }
    QueryResponse resp = server.query(solrQuery);

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

示例6: search

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Pure Solr search method.
 * 
 * @param query {@link String}
 * @param first {@link Integer}
 * @param rows {@link Integer}
 * @param sortFields
 * @param fieldList If not null, only the fields in the list will be returned.
 * @param params Additional query parameters.
 * @return {@link QueryResponse}
 * @throws SolrServerException
 * @throws PresentationException
 * @should return correct results
 * @should return correct number of rows
 * @should sort results correctly
 */
public QueryResponse search(String query, int first, int rows, List<String> sortFields, List<String> fieldList, Map<String, String> params)
        throws SolrServerException {
    SolrQuery solrQuery = new SolrQuery(query);
    solrQuery.setStart(first);
    solrQuery.setRows(rows - first);

    if (sortFields != null && !sortFields.isEmpty()) {
        for (String sortField : sortFields) {
            solrQuery.addSort(sortField, ORDER.asc);
            // logger.trace("Added sorting field: {}", sortField);
        }
    }
    if (fieldList != null && !fieldList.isEmpty()) {
        for (String field : fieldList) {
            // logger.trace("adding result field: " + field);
            if (StringUtils.isNotEmpty(field)) {
                solrQuery.addField(field);
            }
        }
    }
    if (params != null && !params.isEmpty())

    {
        for (String key : params.keySet()) {
            solrQuery.set(key, params.get(key));
            // logger.trace("&{}={}", key, params.get(key));
        }
    }

    // logger.trace("Solr query: {}", solrQuery.toString());
    // logger.debug("range: {} - {}", first, rows);
    // logger.debug("facetFields: " + facetFields);
    // logger.debug("fieldList: " + fieldList);
    QueryResponse resp = server.query(solrQuery);
    // logger.debug("found: " + resp.getResults().getNumFound());
    // logger.debug("fetched: {}", resp.getResults().size());

    return resp;

}
 
開發者ID:intranda,項目名稱:goobi-viewer-connector,代碼行數:57,代碼來源:SolrSearchIndex.java

示例7: querySolrIndex

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Returns all patterns from the index and their features for reverb and the
 * wordnet distance and the overall boa-boaScore.
 * 
 * @param propertyUri the property URI
 * @return a list of patterns
 */
private static Set<Pattern> querySolrIndex(String propertyUri) {

    Map<Integer, Pattern> patterns = new HashMap<>();

    try {

        SolrQuery query = new SolrQuery("uri:\"" + propertyUri + "\"");
        query.addField("REVERB");
        query.addField("WORDNET_DISTANCE");
        query.addField("SUPPORT_NUMBER_OF_PAIRS_LEARNED_FROM");
        query.addField("pos");
        query.addField("boa-score");
        query.addField("nlr-var");
        query.addField("nlr-no-var");
        query.setRows(10000);
        QueryResponse response = server.query(query);
        SolrDocumentList docList = response.getResults();

        // return the first list of types
        for (SolrDocument d : docList) {

            Pattern pattern = new Pattern();
            pattern.naturalLanguageRepresentation = (String) d.get("nlr-var");
            pattern.naturalLanguageRepresentationWithoutVariables = (String) d.get("nlr-no-var");
            pattern.features.put("REVERB", Double.valueOf((String) d.get("REVERB")));
            pattern.features.put("WORDNET_DISTANCE", Double.valueOf((String) d.get("WORDNET_DISTANCE")));
            pattern.features.put("SUPPORT_NUMBER_OF_PAIRS_LEARNED_FROM", Double.valueOf((String) d.get("SUPPORT_NUMBER_OF_PAIRS_LEARNED_FROM")));
            pattern.posTags = (String) d.get("pos");
            pattern.boaScore = Double.valueOf((String) d.get("boa-score"));
            pattern.naturalLanguageScore = calculateNaturalLanguageScore(pattern);

            // since ?D? and ?R? are removed so two patterns might look the
            // same
            if (isSuitable(pattern)) {

                // merge the pattern
                if (patterns.containsKey(pattern.hashCode())) {

                    Pattern p = patterns.get(pattern.hashCode());
                    p.features.put("REVERB", pattern.features.get("REVERB") + p.features.get("REVERB"));
                    p.features.put("WORDNET_DISTANCE", pattern.features.get("WORDNET_DISTANCE") + p.features.get("WORDNET_DISTANCE"));
                    p.features.put("SUPPORT_NUMBER_OF_PAIRS_LEARNED_FROM", pattern.features.get("SUPPORT_NUMBER_OF_PAIRS_LEARNED_FROM") + p.features.get("SUPPORT_NUMBER_OF_PAIRS_LEARNED_FROM"));
                    p.boaScore += pattern.boaScore;
                    p.naturalLanguageScore += pattern.naturalLanguageScore;
                    patterns.put(pattern.hashCode(), p);
                }
                else {

                    patterns.put(pattern.hashCode(), pattern);
                }
            }
        }
    }
    catch (SolrServerException e) {

        System.out.println("Could not execute query: " + e);
        e.printStackTrace();
    }
    return new HashSet<>(patterns.values());
}
 
開發者ID:dice-group,項目名稱:RDF2PT,代碼行數:68,代碼來源:BoaPatternSelector.java

示例8: doQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected SolrDocumentList doQuery(int start) {
  this.queryString = context.getResolvedEntityAttribute(QUERY);
  if (this.queryString == null) {
    throw new DataImportHandlerException(
        DataImportHandlerException.SEVERE,
        "SolrEntityProcessor: parameter 'query' is required"
    );
  }

  String rowsP = context.getResolvedEntityAttribute(CommonParams.ROWS);
  if (rowsP != null) {
    rows = Integer.parseInt(rowsP);
  }

  String fqAsString = context.getResolvedEntityAttribute(CommonParams.FQ);
  if (fqAsString != null) {
    this.filterQueries = fqAsString.split(",");
  }

  String fieldsAsString = context.getResolvedEntityAttribute(CommonParams.FL);
  if (fieldsAsString != null) {
    this.fields = fieldsAsString.split(",");
  }
  this.requestHandler = context.getResolvedEntityAttribute(CommonParams.QT);
  String timeoutAsString = context.getResolvedEntityAttribute(TIMEOUT);
  if (timeoutAsString != null) {
    this.timeout = Integer.parseInt(timeoutAsString);
  }

  SolrQuery solrQuery = new SolrQuery(queryString);
  solrQuery.setRows(rows);
  solrQuery.setStart(start);
  if (fields != null) {
    for (String field : fields) {
      solrQuery.addField(field);
    }
  }
  solrQuery.setRequestHandler(requestHandler);
  solrQuery.setFilterQueries(filterQueries);
  solrQuery.setTimeAllowed(timeout * 1000);
  
  QueryResponse response = null;
  try {
    response = solrServer.query(solrQuery);
  } catch (SolrServerException e) {
    if (ABORT.equals(onError)) {
      wrapAndThrow(SEVERE, e);
    } else if (SKIP.equals(onError)) {
      wrapAndThrow(DataImportHandlerException.SKIP_ROW, e);
    }
  }
  
  return response == null ? null : response.getResults();
}
 
開發者ID:europeana,項目名稱:search,代碼行數:55,代碼來源:SolrEntityProcessor.java

示例9: testGetFieldsPhaseError

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testGetFieldsPhaseError() throws SolrServerException {
  BadResponseWriter.failOnGetFields = true;
  BadResponseWriter.failOnGetTopIds = false;
  SolrQuery query = new SolrQuery();
  query.setQuery("subject:batman OR subject:superman");
  query.addField("id");
  query.addField("subject");
  query.set("distrib", "true");
  query.set("shards", shard1 + "," + shard2);
  query.set(ShardParams.SHARDS_INFO, "true");
  query.set("debug", "true");
  query.set("stats", "true");
  query.set("stats.field", "id");
  query.set("mlt", "true");
  query.set("mlt.fl", "title");
  query.set("mlt.count", "1");
  query.set("mlt.mintf", "0");
  query.set("mlt.mindf", "0");
  query.setHighlight(true);
  query.addFacetField("id");
  query.setFacet(true);
  
  ignoreException("Dummy exception in BadResponseWriter");
  try {
    collection1.query(query);
    fail("Should get an exception");
  } catch (Exception e) {
    //expected
  }
  query.set(ShardParams.SHARDS_TOLERANT, "true");
  QueryResponse response = collection1.query(query);
  assertTrue(response.getResponseHeader().getBooleanArg("partialResults"));
  NamedList<Object> shardsInfo = ((NamedList<Object>)response.getResponse().get("shards.info"));
  boolean foundError = false;
  for (int i = 0; i < shardsInfo.size(); i++) {
    if (shardsInfo.getName(i).contains("collection2")) {
      assertNotNull(((NamedList<Object>)shardsInfo.getVal(i)).get("error"));
      foundError = true;
      break;
    }
  }
  assertTrue(foundError);
  assertEquals(1, response.getResults().get(0).getFieldValue("id"));
  assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
  unIgnoreException("Dummy exception in BadResponseWriter");
}
 
開發者ID:europeana,項目名稱:search,代碼行數:48,代碼來源:TestTolerantSearch.java

示例10: testGetTopIdsPhaseError

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testGetTopIdsPhaseError() throws SolrServerException {
  BadResponseWriter.failOnGetTopIds = true;
  BadResponseWriter.failOnGetFields = false;
  SolrQuery query = new SolrQuery();
  query.setQuery("subject:batman OR subject:superman");
  query.addField("id");
  query.addField("subject");
  query.set("distrib", "true");
  query.set("shards", shard1 + "," + shard2);
  query.set(ShardParams.SHARDS_INFO, "true");
  query.set("debug", "true");
  query.set("stats", "true");
  query.set("stats.field", "id");
  query.set("mlt", "true");
  query.set("mlt.fl", "title");
  query.set("mlt.count", "1");
  query.set("mlt.mintf", "0");
  query.set("mlt.mindf", "0");
  query.setHighlight(true);
  query.addFacetField("id");
  query.setFacet(true);
  
  ignoreException("Dummy exception in BadResponseWriter");
  try {
    collection1.query(query);
    fail("Should get an exception");
  } catch (Exception e) {
    //expected
  }
  query.set(ShardParams.SHARDS_TOLERANT, "true");
  QueryResponse response = collection1.query(query);
  assertTrue(response.getResponseHeader().getBooleanArg("partialResults"));
  NamedList<Object> shardsInfo = ((NamedList<Object>)response.getResponse().get("shards.info"));
  boolean foundError = false;
  for (int i = 0; i < shardsInfo.size(); i++) {
    if (shardsInfo.getName(i).contains("collection2")) {
      assertNotNull(((NamedList<Object>)shardsInfo.getVal(i)).get("error"));
      foundError = true;
      break;
    }
  }
  assertTrue(foundError);
  
  assertEquals(1, response.getResults().get(0).getFieldValue("id"));
  assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
  unIgnoreException("Dummy exception in BadResponseWriter");
}
 
開發者ID:europeana,項目名稱:search,代碼行數:49,代碼來源:TestTolerantSearch.java

示例11: suggestDrugCategory

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Use the term index to see if the query appears to be a drug name, if so, determine the drug class
 * and suggest that as potentially broader search option.
 */
private void suggestDrugCategory(PatientSearch search, FrameTask task) throws FrameException {
	String queryStr = search.getQueryStr();
	
	// query the index values for a match against drug class
	ModifiableSolrParams classQry = new ModifiableSolrParams();
	classQry.set("qt", "/terms");
	classQry.add("terms.fl", "med_ingredient_code_name","med_ingredient_name");
	classQry.set("terms.sort", "count");
	classQry.set("terms.regex", ClientUtils.escapeQueryChars(queryStr) + ".*");
	classQry.set("terms.regex.flag", "case_insensitive");
	
	QueryResponse ret = execSolrQuery(classQry, task);
	
	// get suggestions from med ingredient code name or name
	NamedList<String> match = (NamedList<String>) ret.getResponse().findRecursive("terms", "med_ingredient_code_name");
	if (match == null || match.size() <= 0) {
		match = (NamedList<String>) ret.getResponse().findRecursive("terms", "med_ingredient_name");
	}
	
	// offer them up as drug class suggestions
	if (match != null && match.size() > 0) {
		// match found, get associated drug classes
		String term = match.getName(0);
		SolrQuery qry = new SolrQuery("med_ingredient_code_name: " + term);
		qry.addField("med_ingredient_code_name,med_drug_class_name");
		qry.addFilterQuery("domain:med");
		qry.setRows(1);
		
		ret = execSolrQuery(qry, task);
		if (!ret.getResults().isEmpty()) {
			SolrDocument doc = ret.getResults().get(0);
			List<String> list = (List<String>) doc.getFieldValue("med_drug_class_name");
			for (String drugClass : list) {
				SuggestItem item = new SuggestItem(drugClass, drugClass, "Therapeutic Drug Class");
	        	item.setProp("typeFilter", "med");
	        	item.setCategory("All Medications");
	        	task.addAction(item);
			}
		}
	}
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:46,代碼來源:MedsSearchFrame.java


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