本文整理匯總了Java中org.apache.solr.common.SolrDocumentList.add方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrDocumentList.add方法的具體用法?Java SolrDocumentList.add怎麽用?Java SolrDocumentList.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.common.SolrDocumentList
的用法示例。
在下文中一共展示了SolrDocumentList.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildRealTimeGetResult
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public static GetResult buildRealTimeGetResult(QueryResponse response, RealTimeGet query, DocumentFactory factory) {
final String DOC = "doc";
long nResults = 0;
List<Document> docResults = new ArrayList<>();
final SolrDocumentList results = response.getResults();
if(results != null && results.size() >0){
docResults = buildResultList(results, null, factory, null);
nResults = docResults.size();
} else {
final SolrDocument solrDoc = (SolrDocument)response.getResponse().get(DOC);
if(solrDoc != null) {
final SolrDocumentList solrDocuments = new SolrDocumentList();
solrDocuments.add(solrDoc);
docResults = buildResultList(solrDocuments, null, factory, null);
nResults = 1;
}
}
return new GetResult(nResults,docResults,query,factory);
}
示例2: testGetDocument
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* Test of getDocument method, of class SolrDocumentServiceImpl.
*/
@Test
public void testGetDocument() {
final SolrQuery solrQuery = new SolrQuery("query");
final SolrDocument resultDocument = new SolrDocument();
resultDocument.setField("id", "documentId");
final SolrDocumentList resultList = new SolrDocumentList();
resultList.add(resultDocument);
context.checking(new Expectations() {
{
oneOf(queryFactory).createDocumentQuery("documentId");
will(returnValue(solrQuery));
oneOf(dao).getDocuments(solrQuery);
will(returnValue(resultList));
}
});
final SolrDocument result = instance.getDocument("documentId");
assertEquals(resultDocument, result);
assertEquals("documentId", result.getFieldValue("id"));
}
示例3: testGetDocuments
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* Test of getDocuments method, of class SolrDocumentServiceImpl.
*/
@Test
public void testGetDocuments() {
final QueryFacetsSelection selection = new QueryFacetsSelection("query", Collections.<String, FacetSelection>emptyMap());
final int first = 100;
final int count = 15;
final SolrQuery solrQuery = new SolrQuery("query");
final SolrDocumentList resultList = new SolrDocumentList();
resultList.add(new SolrDocument());
resultList.add(new SolrDocument());
context.checking(new Expectations() {
{
oneOf(queryFactory).createDocumentQuery(selection, first, count);
will(returnValue(solrQuery));
oneOf(dao).getDocuments(solrQuery);
will(returnValue(resultList));
}
});
final List<SolrDocument> result = instance.getDocuments(selection, first, count);
assertEquals(resultList, result);
}
示例4: getDocs
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private SolrDocumentList getDocs(int start, int rows) {
SolrDocumentList docs = new SolrDocumentList();
docs.setNumFound(docsData.size());
docs.setStart(start);
int endIndex = start + rows;
int end = docsData.size() < endIndex ? docsData.size() : endIndex;
for (int i = start; i < end; i++) {
SolrDocument doc = new SolrDocument();
SolrTestCaseJ4.Doc testDoc = docsData.get(i);
doc.addField("id", testDoc.id);
doc.addField("description", testDoc.getValues("description"));
docs.add(doc);
}
return docs;
}
示例5: getHistory
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public SolrDocumentList getHistory(long since, AtomicBoolean found) {
if(history==null) {
return null;
}
SolrDocumentList docs = new SolrDocumentList();
Iterator<E> iter = history.iterator();
while(iter.hasNext()) {
E e = iter.next();
long ts = getTimestamp(e);
if(ts == since) {
if(found!=null) {
found.set(true);
}
}
if(ts>since) {
docs.add(toSolrDocument(e));
}
}
docs.setNumFound(docs.size()); // make it not look too funny
return docs;
}
示例6: transform
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void transform(Map<String, ?> result, ResponseBuilder rb, SolrDocumentSource solrDocumentSource) {
Object value = result.get(rb.getGroupingSpec().getFields()[0]);
if (TopGroups.class.isInstance(value)) {
@SuppressWarnings("unchecked")
TopGroups<BytesRef> topGroups = (TopGroups<BytesRef>) value;
SolrDocumentList docList = new SolrDocumentList();
docList.setStart(rb.getGroupingSpec().getOffset());
docList.setNumFound(rb.totalHitCount);
Float maxScore = Float.NEGATIVE_INFINITY;
for (GroupDocs<BytesRef> group : topGroups.groups) {
for (ScoreDoc scoreDoc : group.scoreDocs) {
if (maxScore < scoreDoc.score) {
maxScore = scoreDoc.score;
}
docList.add(solrDocumentSource.retrieve(scoreDoc));
}
}
if (maxScore != Float.NEGATIVE_INFINITY) {
docList.setMaxScore(maxScore);
}
rb.rsp.add("response", docList);
}
}
示例7: createQueryResponse
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* Creates a query response
* @param qTime
* @return
*/
protected QueryResponse createQueryResponse(int qTime) {
QueryResponse response = new QueryResponse();
NamedList<Object> headerNamedList = new NamedList<Object>();
headerNamedList.add("QTime", qTime);
NamedList<Object> responseNamedList = new NamedList<Object>();
responseNamedList.add("responseHeader", headerNamedList);
SolrDocumentList resultsNamedList = new SolrDocumentList();
resultsNamedList.add(new SolrDocument());
resultsNamedList.add(new SolrDocument());
resultsNamedList.add(new SolrDocument());
resultsNamedList.setNumFound(10);
responseNamedList.add("response", resultsNamedList);
response.setResponse(responseNamedList);
return response;
}
示例8: createSummaryItems
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
@Override
public List<SummaryItem> createSummaryItems(QueryResponse response) {
if (!search.searchType("problem")) return null; // don't create results if we documents are filtered out
List<SummaryItem> items = new ArrayList<>();
if (response.getGroupResponse() == null) return items;
for (GroupCommand cmd : response.getGroupResponse().getValues()) {
for (Group group : cmd.getValues()) {
//Group potentially can have more then one result, we are interested in first one.
String icdGroup = (String) group.getResult().get(0).get("icd_group");
if (icdGroup != null && icdGroup.equals("799")) {
for (SolrDocument doc : group.getResult()) {
// don't group these results for this catch-all ICD code, create a summary item for each one
SolrDocumentList docs = new SolrDocumentList();
docs.add(doc);
items.add(createSummaryItem(response, docs));
}
} else {
// do the normal thing
items.add(createSummaryItem(response, group.getResult()));
}
}
}
return items;
}
示例9: readDocuments
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
protected SolrDocumentList readDocuments( XMLStreamReader parser ) throws XMLStreamException
{
SolrDocumentList docs = new SolrDocumentList();
// Parse the attributes
for( int i=0; i<parser.getAttributeCount(); i++ ) {
String n = parser.getAttributeLocalName( i );
String v = parser.getAttributeValue( i );
if( "numFound".equals( n ) ) {
docs.setNumFound( Long.parseLong( v ) );
}
else if( "start".equals( n ) ) {
docs.setStart( Long.parseLong( v ) );
}
else if( "maxScore".equals( n ) ) {
docs.setMaxScore( Float.parseFloat( v ) );
}
}
// Read through each document
int event;
while( true ) {
event = parser.next();
if( XMLStreamConstants.START_ELEMENT == event ) {
if( !"doc".equals( parser.getLocalName() ) ) {
throw new RuntimeException( "should be doc! "+parser.getLocalName() + " :: " + parser.getLocation() );
}
docs.add( readDocument( parser ) );
}
else if ( XMLStreamConstants.END_ELEMENT == event ) {
return docs; // only happens once
}
}
}
示例10: testSingleVal4Array
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
public void testSingleVal4Array() {
DocumentObjectBinder binder = new DocumentObjectBinder();
SolrDocumentList solDocList = new SolrDocumentList();
SolrDocument d = new SolrDocument();
solDocList.add(d);
d.setField("cat", "hello");
List<Item> l = binder.getBeans(Item.class, solDocList);
assertEquals("hello", l.get(0).categories[0]);
}
示例11: transform
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public void transform(Map<String, ?> result, ResponseBuilder rb, SolrDocumentSource solrDocumentSource) {
NamedList<Object> commands = new SimpleOrderedMap<>();
for (Map.Entry<String, ?> entry : result.entrySet()) {
Object value = entry.getValue();
if (TopGroups.class.isInstance(value)) {
@SuppressWarnings("unchecked")
TopGroups<BytesRef> topGroups = (TopGroups<BytesRef>) value;
NamedList<Object> command = new SimpleOrderedMap<>();
command.add("matches", rb.totalHitCount);
if (topGroups.totalGroupCount != null) {
command.add("ngroups", topGroups.totalGroupCount);
}
SolrDocumentList docList = new SolrDocumentList();
docList.setStart(rb.getGroupingSpec().getOffset());
docList.setNumFound(topGroups.totalHitCount);
Float maxScore = Float.NEGATIVE_INFINITY;
for (GroupDocs<BytesRef> group : topGroups.groups) {
for (ScoreDoc scoreDoc : group.scoreDocs) {
if (maxScore < scoreDoc.score) {
maxScore = scoreDoc.score;
}
docList.add(solrDocumentSource.retrieve(scoreDoc));
}
}
if (maxScore != Float.NEGATIVE_INFINITY) {
docList.setMaxScore(maxScore);
}
command.add("doclist", docList);
commands.add(entry.getKey(), command);
}
}
rb.rsp.add("grouped", commands);
}
示例12: testJSONSolrDocument
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
@Test
public void testJSONSolrDocument() throws IOException {
SolrQueryRequest req = req(CommonParams.WT,"json",
CommonParams.FL,"id,score");
SolrQueryResponse rsp = new SolrQueryResponse();
JSONResponseWriter w = new JSONResponseWriter();
ReturnFields returnFields = new SolrReturnFields(req);
rsp.setReturnFields(returnFields);
StringWriter buf = new StringWriter();
SolrDocument solrDoc = new SolrDocument();
solrDoc.addField("id", "1");
solrDoc.addField("subject", "hello2");
solrDoc.addField("title", "hello3");
solrDoc.addField("score", "0.7");
SolrDocumentList list = new SolrDocumentList();
list.setNumFound(1);
list.setStart(0);
list.setMaxScore(0.7f);
list.add(solrDoc);
rsp.add("response", list);
w.write(buf, req, rsp);
String result = buf.toString();
assertFalse("response contains unexpected fields: " + result,
result.contains("hello") ||
result.contains("\"subject\"") ||
result.contains("\"title\""));
assertTrue("response doesn't contain expected fields: " + result,
result.contains("\"id\"") &&
result.contains("\"score\""));
req.close();
}
示例13: getDocList
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
private SolrDocumentList getDocList(String ... ids) {
SolrDocumentList list = new SolrDocumentList();
for (String id : ids) {
SolrDocument doc = new SolrDocument();
doc.addField("id", id);
list.add(doc);
}
return list;
}
示例14: testSimpleUpdate
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
@Test
public void testSimpleUpdate() throws Exception {
String query = "Update example set field = 'some' where name = 'teiid'";
SolrDocument doc = new SolrDocument();
doc.addField("price", 1.10f);
doc.addField("weight", 2.23f);
doc.addField("popularity", 5);
doc.addField("name", "teiid");
doc.addField("nis", "any");
SolrDocumentList list = new SolrDocumentList();
list.add(doc);
QueryResponse queryResponse = Mockito.mock(QueryResponse.class);
Mockito.stub(queryResponse.getResults()).toReturn(list);
QueryResponse queryResponse2 = Mockito.mock(QueryResponse.class);
Mockito.stub(queryResponse2.getResults()).toReturn(new SolrDocumentList());
UpdateRequest request = helpUpdate(query, queryResponse, queryResponse2);
List<SolrInputDocument> docs = request.getDocuments();
assertEquals(1, docs.size());
SolrInputDocument update = new SolrInputDocument();
update.addField("price", 1.10f);
update.addField("weight", 2.23f);
update.addField("popularity", 5);
update.addField("name", "teiid");
update.addField("nis", "some");
assertEquals(update.toString(), docs.get(0).toString());
}
示例15: testSimpleDelete
import org.apache.solr.common.SolrDocumentList; //導入方法依賴的package包/類
@Test
public void testSimpleDelete() throws Exception {
String query = "Delete from example where name = 'teiid'";
SolrDocument doc = new SolrDocument();
doc.addField("price", 1.10f);
doc.addField("weight", 2.23f);
doc.addField("popularity", 5);
doc.addField("name", "teiid");
doc.addField("nis", "any");
SolrDocumentList list = new SolrDocumentList();
list.add(doc);
QueryResponse queryResponse = Mockito.mock(QueryResponse.class);
Mockito.stub(queryResponse.getResults()).toReturn(list);
QueryResponse queryResponse2 = Mockito.mock(QueryResponse.class);
Mockito.stub(queryResponse2.getResults()).toReturn(new SolrDocumentList());
UpdateRequest request = helpUpdate(query, queryResponse, queryResponse2);
List<SolrInputDocument> docs = request.getDocuments();
UpdateRequest expected = new UpdateRequest();
expected.deleteById("teiid");
assertEquals(expected.getDeleteById().toString(), request.getDeleteById().toString());
}