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


Java SolrQuery.setFields方法代碼示例

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


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

示例1: 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

示例2: getQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getQuery() {
    SolrQuery solrQuery = new SolrQuery();
    MCRConfiguration config = MCRConfiguration.instance();
    // query
    String idQuery = getResult().stream()
        .map(getIdentifier())
        .map(MCRSolrUtils::escapeSearchValue)
        .collect(Collectors.joining(" OR ", "id:(", ")"));
    solrQuery.setQuery(idQuery);
    solrQuery.setFilterQueries(query);
    solrQuery.setFields("id");
    solrQuery.setRows(getResult().size());
    // request handler
    solrQuery.setRequestHandler(config.getString(getConfigPrefix() + "Search.RequestHandler", "/select"));
    return solrQuery;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:17,代碼來源:MCROAIQuerySetResolver.java

示例3: getSolrDocument

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public SolrDocument getSolrDocument(String docId) {
    if (docId == null) {
        throw new NullPointerException("Cannot get SOLR document for null docId");
    }
    SolrDocument result = null;
    SolrQuery query = new SolrQuery();
    query.setQuery("id:" + ClientUtils.escapeQueryChars(docId));
    query.setFields("*");
    SolrDocumentList docs = fireQuery(query).getResults();
    if (docs.getNumFound() > 1) {
        logger.error("Error: found multiple documents for id (will return first one): " + docId + " \nDocuments found: " + docs);
        result = docs.get(0);
    } else if (docs.getNumFound() == 1) {
        result = docs.get(0);
    }
    return result;
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:18,代碼來源:SolrDaoImpl.java

示例4: getAllBooks

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public List<BookEntry> getAllBooks(List<WatchList> watchList) throws SolrServerException {
    if (watchList.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    String searchString = "id:(";
    for (WatchList watchListItem : watchList) {
        searchString = searchString + "\"" +watchListItem.getBookId() +"\",";
    }
    searchString = searchString.substring(0, searchString.length()-1) + ")";
    
    SolrQuery query = new SolrQuery();
    query.setRows(20);
    query.setStart(0);
    query.setQuery(searchString);
    query.setSort(SolrQuery.SortClause.asc("author"));
    query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
    
    return bookService.searchBooks(query).getBeans(BookEntry.class);
    
}
 
開發者ID:felixhusse,項目名稱:bookery,代碼行數:21,代碼來源:WatchListService.java

示例5: getSolrQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public SolrQuery getSolrQuery(List<WatchList> watchList) {
    if (watchList.isEmpty()) {
        return null;
    }
    String searchString = "id:(";
    for (WatchList watchListItem : watchList) {
        searchString = searchString + "\"" +watchListItem.getBookId() +"\",";
    }
    searchString = searchString.substring(0, searchString.length()-1) + ")";
    
    SolrQuery query = new SolrQuery();
    query.setRows(20);
    query.setStart(0);
    query.setQuery(searchString);
    query.setSort(SolrQuery.SortClause.asc("author"));
    query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
    return query;
}
 
開發者ID:felixhusse,項目名稱:bookery,代碼行數:19,代碼來源:WatchListService.java

示例6: searchSolrIndex

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public QueryResponse searchSolrIndex(String queryString, String fields, int rows, int startOffset) throws SolrServerException  {
    SolrServer solr = null;
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery(queryString);
    query.setRows(rows);
    query.setStart(startOffset);
    
    query.setFields(fields);
    QueryResponse rsp = solr.query(query);
    return rsp;
}
 
開發者ID:felixhusse,項目名稱:bookery,代碼行數:17,代碼來源:SolrHandler.java

示例7: exec

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void exec(PatientSearch search, FrameTask task) throws FrameException {
	// create + exec SOLR query
	SolrQuery query = search.initQuery();
	query.setParam("q.op", "OR");

	query.setQuery("+all:\"" + ClientUtils.escapeQueryChars(search.getQueryStr()) + '"');
	
	// search for the specific domains we don't have frames for
	String domains = "obs procedure "; // encounter stuff
	domains += "mh "; // other patient stuff
	domains += "roadtrip auxiliary "; // CPE specific stuff
	domains += "pov skin diagnosis ptf exam treatment"; // encounter flags
	query.addFilterQuery("+domain: (" + domains + ")");
	query.addFilterQuery("-removed:true"); 
	
	query.addSort(SearchService.DATETIME, ORDER.desc);
	query.setFields(SearchService.UID, SearchService.DATETIME,
			SearchService.SUMMARY, SearchService.URL_FIELD,
			SearchService.DOMAIN, SearchService.KIND,
			SearchService.FACILITY);
	task.addAction(new SolrSearchAction(query, execSolrQuery(query, task)));
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:24,代碼來源:GoldSearchFrame.java

示例8: execute

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public SearchResult<? extends Result> execute(ComponentConfiguration conf, Template intent, Conversation conversation, MultiValueMap<String, String> queryParams) throws IOException {
    // read default page-size from builder-configuration
    int pageSize = conf.getConfiguration(CONFIG_KEY_PAGE_SIZE, 3);
    // if present, a queryParam 'rows' takes precedence.
    pageSize = toInt(queryParams.getFirst("rows"), pageSize);
    long offset = toInt(queryParams.getFirst("start"), 0);


    final QueryRequest solrRequest = buildSolrRequest(conf, intent, conversation, offset, pageSize, queryParams);
    if (solrRequest == null) {
        return new SearchResult<ConversationResult>(pageSize);
    }

    try (SolrClient solrClient = solrServer.getSolrClient(conversationCore)) {
        final NamedList<Object> response = solrClient.request(solrRequest);
        final QueryResponse solrResponse = new QueryResponse(response, solrClient);
        final SolrDocumentList solrResults = solrResponse.getResults();

        final List<ConversationResult> results = new ArrayList<>();
        for (SolrDocument solrDocument : solrResults) {
            //get the answers /TODO hacky, should me refactored (at least ordered by rating)
            SolrQuery query = new SolrQuery("*:*");
            query.add("fq",String.format("conversation_id:\"%s\"",solrDocument.get("conversation_id")));
            query.add("fq", "message_idx:[1 TO *]");
            query.setFields("*","score");
            query.setSort("time", SolrQuery.ORDER.asc);
            //query.setRows(3);

            QueryResponse answers = solrClient.query(query);

            results.add(toHassoResult(conf, solrDocument, answers.getResults(), intent.getType()));
        }
        return new SearchResult<>(solrResults.getNumFound(), solrResults.getStart(), pageSize, results);
    } catch (SolrServerException e) {
        throw new IOException(e);
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:39,代碼來源:ConversationQueryBuilder.java

示例9: getBaseQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getBaseQuery(String restrictionField) {
    String configPrefix = this.identify.getConfigPrefix();
    SolrQuery query = new SolrQuery();
    // query
    String restriction = getConfig().getString(configPrefix + "Search.Restriction", null);
    if (restriction != null) {
        query.set(restrictionField, restriction);
    }
    String[] requiredFields = Stream.concat(Stream.of("id", getModifiedField()), getRequiredFieldNames().stream())
        .toArray(String[]::new);
    query.setFields(requiredFields);
    // request handler
    query.setRequestHandler(getConfig().getString(configPrefix + "Search.RequestHandler", "/select"));
    return query;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:16,代碼來源:MCROAISolrSearcher.java

示例10: SolrDocumentQueryFactoryImpl

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
     *
     * @param documentFields fields that should be included in document queries
     */
    public SolrDocumentQueryFactoryImpl(Collection<String> documentFields) {
        defaultQueryTemplate = new SolrQuery();
        defaultQueryTemplate.setFields(documentFields.toArray(new String[]{}));
//        //TODO: qf (all fields with weights - make configurable (later)
//        defaultQueryTemplate.setParam(DisMaxParams.QF, "name^20 description^10");
    }
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:11,代碼來源:SolrDocumentQueryFactoryImpl.java

示例11: testGetFacets

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Test of getFacets method, of class SearchResultsDaoImpl.
 *
 * @throws java.lang.Exception
 */
@Test
public void testGetFacets() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setRows(10);
    query.setStart(0);
    query.setFields(FIELD_NAME, FIELD_ID, FIELD_DESCRIPTION);
    query.setQuery(null);

    query.setFacet(true);
    query.setFacetMinCount(1);
    query.addFacetField(FIELD_COLLECTION, FIELD_COUNTRY);

    List<FacetField> facetFields = instance.getFacets(query);
    assertNotNull(facetFields);
    assertEquals(2, facetFields.size());

    // 1 collection
    assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf(
            Matchers.<FacetField>hasProperty("name", equalTo(FIELD_COLLECTION)),
            Matchers.<FacetField>hasProperty("valueCount", equalTo(1)))));

    // 2 countries
    assertThat(facetFields, Matchers.<FacetField>hasItem(Matchers.allOf(
            Matchers.<FacetField>hasProperty("name", equalTo(FIELD_COUNTRY)),
            Matchers.<FacetField>hasProperty("valueCount", equalTo(2)))));
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:32,代碼來源:SearchResultsDaoImplTest.java

示例12: enter

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    SolrQuery.SortClause sortClause = SolrQuery.SortClause.asc("author");
    
    String searchString = SolrSearchUtil.generateSearchString(appHeader.getSearchText());
    
    String[] params = event.getParameters().split("/");
    if (params.length > 0) {
        String sortParameter = params[0];
        switch(sortParameter) {
            case "author":
                sortClause = SolrQuery.SortClause.asc("author");
                break;
            case "likes":
                sortClause = SolrQuery.SortClause.desc("likes");
                break;
            case "downloads":
                sortClause = SolrQuery.SortClause.desc("downloadcount");
                break;
        }
        
        if (params.length > 1) {
            String viewer = SecurityUtils.getSubject().getPrincipal().toString();
            searchString = SolrSearchUtil.addNewBooksSearchString(viewer, searchString);
        }
    }
    SolrQuery query = new SolrQuery();
    query.setRows(20);
    query.setStart(0);
    query.setQuery(searchString);
    query.setSort(sortClause);
    query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
    searchLayout.searchBooks(query,true);
}
 
開發者ID:felixhusse,項目名稱:bookery,代碼行數:35,代碼來源:SearchView.java

示例13: getSplits

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public org.apache.hadoop.mapred.InputSplit[] getSplits(org.apache.hadoop.mapred.JobConf conf, int numSplits) throws IOException {
  log.info("SolrInputFormat -> getSplits");
  String collectionName = conf.get(COLLECTION_NAME);
  SolrServer solr = SolrOperations.getSolrServer(conf);

  final SolrQuery solrQuery = new SolrQuery(conf.get(SOLR_QUERY));
  solrQuery.setFields(ID_FIELD);
  solrQuery.setRows(50);
  solrQuery.set("collection", collectionName);
  solrQuery.setStart(0);

  QueryResponse response;
  try {
    response = solr.query(solrQuery);
  } catch (final SolrServerException e) {
    throw new IOException(e);
  }

  int numResults = (int)response.getResults().getNumFound();
  int numDocsPerSplit = (numResults / numSplits); 
  int currentDoc = 0;

  List<InputSplit> splits = new ArrayList<InputSplit>();
  for (int i = 0; i < numSplits - 1; i++) {
    splits.add(new SolrInputSplit(currentDoc, numDocsPerSplit));
    currentDoc += numDocsPerSplit;
  }
  splits.add(new SolrInputSplit(currentDoc, numResults - currentDoc));

  return splits.toArray(new SolrInputSplit[splits.size()]);
}
 
開發者ID:mrt,項目名稱:bigsolr,代碼行數:33,代碼來源:SolrInputFormat.java

示例14: createRecordReader

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public RecordReader<NullWritable, SolrRecord> createRecordReader(InputSplit split,
    TaskAttemptContext context) throws IOException, InterruptedException {
  
  log.info("SolrInputFormat -> createRecordReader");

  Configuration conf = context.getConfiguration();
  org.apache.hadoop.mapred.Reporter reporter = null;  // Need to implement with heartbeat
  
  String collectionName = conf.get(COLLECTION_NAME);
  String fields = conf.get(FIELDS);
  SolrServer solr = SolrOperations.getSolrServer(conf);

  SolrInputSplit solrSplit = (SolrInputSplit) split;
  final int numDocs = (int) solrSplit.getLength();
    
  final SolrQuery solrQuery = new SolrQuery(conf.get(SOLR_QUERY));

  solrQuery.setFields(fields);
  solrQuery.set("collection", collectionName);
  solrQuery.setStart(solrSplit.getDocBegin());
  solrQuery.setRows(numDocs);

  QueryResponse response;
  try {
    response = solr.query(solrQuery);
  } catch (final SolrServerException e) {
    throw new IOException(e);
  }

  final SolrDocumentList solrDocs = response.getResults();
  return new SolrRecordReader(solrDocs, numDocs);
}
 
開發者ID:mrt,項目名稱:bigsolr,代碼行數:34,代碼來源:SolrInputFormat.java

示例15: getEpubBook

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public List<BookEntry> getEpubBook(String bookID) throws SolrServerException {
    SolrServer solr = null;
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery("id:"+bookID);
    query.setRows(1);
    query.setFields("id,epub");
    QueryResponse rsp = solr.query(query);
    return rsp.getBeans(BookEntry.class);
}
 
開發者ID:felixhusse,項目名稱:bookery,代碼行數:15,代碼來源:SolrHandler.java


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