Examples of SolrDocumentList


Examples of org.apache.solr.common.SolrDocumentList

   * {@inheritDoc}
   */
  public void process(ResponseBuilder rb, ShardRequest shardRequest) {
    boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
    ShardResponse srsp = shardRequest.responses.get(0);
    SolrDocumentList docs = (SolrDocumentList)srsp.getSolrResponse().getResponse().get("response");
    String uniqueIdFieldName = rb.req.getSchema().getUniqueKeyField().getName();

    for (SolrDocument doc : docs) {
      Object id = doc.getFieldValue(uniqueIdFieldName).toString();
      ShardDoc shardDoc = rb.resultIds.get(id);
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    queryParams.setFields("description", "title");//<co id="solrj-search.co.fields"/>
    queryParams.setQuery("description:win OR description:all");//<co id="solrj-search.co.terms"/>
    queryParams.setRows(10);
    QueryResponse response = solr.query(queryParams);//<co id="solrj-search.co.process"/>
    assertTrue("response is null and it shouldn't be", response != null);
    SolrDocumentList documentList = response.getResults();
    System.out.println("Docs: " + documentList);
    assertTrue("response.getResults() Size: " + documentList.size() +
            " is not: " + 3, documentList.size() == 3);
    /*
<calloutlist>
    <callout arearefs="solrj-search.co.query"><para>A <classname>SolrQuery</classname> is a easy-to-use container for creating the most common types of queries.</para></callout>
    <callout arearefs="solrj-search.co.fields"><para>Set the names of the Fields to be returned in the documents.</para></callout>
    <callout arearefs="solrj-search.co.terms"><para>Set the terms to search.  The "OR" is a boolean operator which allows one or the other or both to be present in the query.</para></callout>
    <callout arearefs="solrj-search.co.process"><para>Submit the query to Solr and get back a <classname>QueryResponse</classname> which contains the results of the search.</para></callout>

</calloutlist>
*/
    //<end id="solrj-search-1"/>

    //<start id="solrj-search-dismax"/>
    queryParams.setQuery("lazy");
    queryParams.setParam("defType", "dismax");//<co id="solrj-search.co.dismax"/>
    queryParams.set("qf", "title^3 description^10");//<co id="sorlj-search.co.qf"/>
    System.out.println("Query: " + queryParams);
    response = solr.query(queryParams);
    assertTrue("response is null and it shouldn't be", response != null);
    documentList = response.getResults();
    assertTrue("documentList Size: " + documentList.size() +
            " is not: " + 2, documentList.size() == 2);
/*
<calloutlist>
    <callout arearefs="solrj-search.co.dismax"><para>Tell Solr to use the <classname>DisMax</classname> Query Parser (named dismax in solrconfig.xml). </para></callout>
    <callout arearefs="sorlj-search.co.qf"><para>The DisMax parser will search across the fields given by the "qf" parameter and boosts the terms accordingly.</para></callout>

</calloutlist>
*/
    //<end id="solrj-search-dismax"/>

    //<start id="solrj-search-facets"/>
    queryParams = new SolrQuery();
    queryParams.setQuery("description:number");
    queryParams.setRows(10);
    queryParams.setFacet(true);//<co id="solrj-search-facets-facetOn"/>
    queryParams.set("facet.field", "date");//<co id="solrj-search-facets-date"/>
    response = solr.query(queryParams);
    assertTrue("response is null and it shouldn't be", response != null);
    System.out.println("Query: " + queryParams);
    documentList = response.getResults();
    assertTrue("documentList Size: " + documentList.size() +
            " is not: " + 10, documentList.size() == 10);
    System.out.println("Facet Response: " + response.getResponse());//<co id="solrj-search-facets-print"/>
    /*
<calloutlist>
  <callout arearefs="solrj-search-facets-facetOn"><para>Turn on faceting for this query</para></callout>
  <callout arearefs="solrj-search-facets-date"><para>Specify the Field to facet on</para></callout>
  <callout arearefs="solrj-search-facets-print"><para>Print out the facet information</para></callout>

</calloutlist>
*/
    //<end id="solrj-search-facets"/>
    //<start id="solrj-search-more-like-this"/>
    queryParams = new SolrQuery();
    queryParams.setQueryType("/mlt");//<co id="solrj-search.co.mlt"/>
    queryParams.setQuery("description:number");
    queryParams.set("mlt.match.offset", "0");//<co id="solrj-search.co.mlt.off"/>
    queryParams.setRows(1);
    queryParams.set("mlt.fl", "description, title");//<co id="solrj-search.co.mlt.fl"/>
    response = solr.query(queryParams);
    assertTrue("response is null and it shouldn't be", response != null);
    SolrDocumentList results = (SolrDocumentList) response.getResponse().get("match");
    assertTrue("results Size: " + results.size() + " is not: " + 1,
            results.size() == 1);
    /*
<calloutlist>
    <callout arearefs="solrj-search.co.mlt"><para>Create a "MoreLikeThis" search to find similar documents to the specified document.</para></callout>
    <callout arearefs="solrj-search.co.mlt.fl"><para>Specify the field to use to generate the "MoreLikeThis" query.</para></callout>
    <callout arearefs="solrj-search.co.mlt.off"><para>Specify which document in the original results to use as the "similar" document. </para></callout>
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

      SolrIndexSearcher searcher,
      Set<String> fields,
      Map<SolrDocument, Integer> ids ) throws IOException
  {
    DocumentBuilder db = new DocumentBuilder(searcher.getSchema());
    SolrDocumentList list = new SolrDocumentList();
    list.setNumFound(docs.matches());
    list.setMaxScore(docs.maxScore());
    list.setStart(docs.offset());

    DocIterator dit = docs.iterator();
    while (dit.hasNext()) {
      int docid = dit.nextDoc();

      Document luceneDoc = searcher.doc(docid, fields);
      SolrDocument doc = new SolrDocument();
      db.loadStoredFields(doc, luceneDoc);

      // this may be removed if XMLWriter gets patched to
      // include score from doc iterator in solrdoclist
      if (docs.hasScores()) {
        doc.addField("score", dit.score());
      } else {
        doc.addField("score", 0.0f);
      }

      list.add( doc );

      if( ids != null ) {
        ids.put( doc, new Integer(docid) );
      }
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

        query.setParam("mlogtime", fmt.format(new Date()));

        query.setParam("rows", "0");
        query.setQuery("*:*");
        QueryResponse qr3 = server.query(query);
        SolrDocumentList result3 = qr3.getResults();
        if(result3!=null)
        {
          return result3.getNumFound();
        }else{
          SolrCore.log.info("checkSolrRecord result is null "+
            "http://localhost:" + port + context+"?"+query.toString());
        }
      } catch (SolrServerException e) {
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

          }

          for (Object oGrp : groupsArr) {
            SimpleOrderedMap grpMap = (SimpleOrderedMap) oGrp;
            Object sGroupValue = grpMap.get( "groupValue");
            SolrDocumentList doclist = (SolrDocumentList) grpMap.get( "doclist");
            Group group = new Group(sGroupValue != null ? sGroupValue.toString() : null, doclist) ;
            groupedCommand.add(group);
          }

          _groupResponse.add(groupedCommand);
        } else if (queryCommand != null) {
          Integer iMatches = (Integer) oMatches;
          GroupCommand groupCommand = new GroupCommand(fieldName, iMatches);
          SolrDocumentList docList = (SolrDocumentList) queryCommand;
          groupCommand.add(new Group(fieldName, docList));
          _groupResponse.add(groupCommand);
        }
      }
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

                "groupValue", groupFieldType.toObject(groupField.createField(group.groupValue, 0.0f))
            );
          } else {
            groupResult.add("groupValue", null);
          }
          SolrDocumentList docList = new SolrDocumentList();
          docList.setNumFound(group.totalHits);
          if (!Float.isNaN(group.maxScore)) {
            docList.setMaxScore(group.maxScore);
          }
      docList.setSum(group.sum);
          docList.setMax(group.max);
          docList.setMin(group.min);
          docList.setStart(groupingSpecification.getGroupOffset());
          for (ScoreDoc scoreDoc : group.scoreDocs) {
            docList.add(solrDocumentSource.retrieve(scoreDoc));
          }
          groupResult.add("doclist", docList);
          groups.add(groupResult);
        }
        command.add("groups", groups);
        commands.add(entry.getKey(), command);
      } else if (QueryCommandResult.class.isInstance(value)) {
        QueryCommandResult queryCommandResult = (QueryCommandResult) value;
        NamedList<Object> command = new SimpleOrderedMap<Object>();
        command.add("matches", queryCommandResult.getMatches());
        SolrDocumentList docList = new SolrDocumentList();
        docList.setNumFound(queryCommandResult.getTopDocs().totalHits);
        if (!Float.isNaN(queryCommandResult.getTopDocs().getMaxScore())) {
          docList.setMaxScore(queryCommandResult.getTopDocs().getMaxScore());
        }
    docList.setSum(queryCommandResult.getTopDocs().getSum());
        docList.setMax(queryCommandResult.getTopDocs().getMax());
        docList.setMin(queryCommandResult.getTopDocs().getMin());

        docList.setStart(groupingSpecification.getGroupOffset());
        for (ScoreDoc scoreDoc :queryCommandResult.getTopDocs().scoreDocs){
          docList.add(solrDocumentSource.retrieve(scoreDoc));
        }
        command.add("doclist", docList);
        commands.add(entry.getKey(), command);
      }
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

      Object val = nl.getVal(i);
      if ("responseHeader".equals(name)) {
        Boolean omitHeader = request.getParams().getBool(CommonParams.OMIT_HEADER);
        if (omitHeader == null || !omitHeader) responseWriter.writeResponseHeader((NamedList) val);
      } else if (val instanceof SolrDocumentList) {
        SolrDocumentList list = (SolrDocumentList) val;
        DocListInfo info = new DocListInfo((int)list.getNumFound(), list.size(), (int)list.getStart(), list.getMaxScore());
        if (responseWriter.isStreamingDocs()) {
          responseWriter.startDocumentList(name,info);
          for (SolrDocument solrDocument : list)
            responseWriter.writeDoc(solrDocument);
          responseWriter.endDocumentList();
        } else {
          responseWriter.writeAllDocs(info, list);
        }
      } else if (val instanceof DocList) {
        DocList docList = (DocList) val;
        int sz = docList.size();
        IdxInfo idxInfo = new IdxInfo(request.getSchema(), request
            .getSearcher(), response.getReturnFields());
        DocListInfo info = new DocListInfo(docList.matches(), docList.size(),docList.offset(),
            docList.maxScore());
        DocIterator iterator = docList.iterator();
        if (responseWriter.isStreamingDocs()) {
          responseWriter.startDocumentList(name,info);
          for (int j = 0; j < sz; j++) {
            SolrDocument sdoc = getDoc(iterator.nextDoc(), idxInfo);
            if (idxInfo.includeScore && docList.hasScores()) {
              sdoc.addField(SCORE_FIELD, iterator.score());
            }
            responseWriter.writeDoc(sdoc);
          }
        } else {
          ArrayList<SolrDocument> list = new ArrayList<SolrDocument>(docList
              .size());
          for (int j = 0; j < sz; j++) {
            SolrDocument sdoc = getDoc(iterator.nextDoc(), idxInfo);
            if (idxInfo.includeScore && docList.hasScores()) {
              sdoc.addField(SCORE_FIELD, iterator.score());
            }
            list.add(sdoc);
          }
          responseWriter.writeAllDocs(info, list);
        }

      } else {
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    }
  }
 
  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 ) );
      }
    else if( "sum".equals( n ) ) {
        docs.setSum( Double.parseDouble( v ) );
      }
      else if( "max".equals( n ) ) {
          docs.setMax( Double.parseDouble( v ) );
      }
      else if( "min".equals( n ) ) {
          docs.setMin( Double.parseDouble( 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( "shoudl be doc! "+parser.getLocalName() + " :: " + parser.getLocation() );
        }
        docs.add( readDocument( parser ) );
      }
      else if ( XMLStreamConstants.END_ELEMENT == event ) {
        return docs;  // only happens once
      }
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

    MoreLikeThisRequest request //<co id="trc.request"/>
      = new MoreLikeThisRequest(query, content);
    QueryResponse response = request.process(server);

    SolrDocumentList documents = response.getResults(); //<co id="trc.results"/>
    ScoreTag[] rankedTags = rankTags(documents, maxTags);
    return rankedTags;
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocumentList

public Iterator<SolrDocument> getCandidates(String title)
    throws SolrServerException {
    String etitle = escape(title); //<co id="co.rm.escape"/>   
    query.setQuery("title:\""+etitle+"\"")//<co id="co.rm.quotes"/>
    QueryResponse response = solr.query(query);
    SolrDocumentList dl = response.getResults();
    return dl.iterator();
}
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.