Examples of SolrDocument


Examples of org.apache.solr.common.SolrDocument

        public boolean next(Text key, SolrRecord value) throws IOException {
          if (currentDoc >= numDocs) {
            return false;
          }

          SolrDocument doc = solrDocs.get(currentDoc);
          String digest = (String) doc.getFieldValue(SolrConstants.DIGEST_FIELD);
          key.set(digest);
          value.readSolrDocument(doc);

          currentDoc++;
          return true;
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

    final SolrDocumentList docList = response.getResults();

    final Hit[] hitArr = new Hit[docList.size()];
    for (int i = 0; i < hitArr.length; i++) {
      final SolrDocument solrDoc = docList.get(i);

      final Object raw = solrDoc.getFirstValue(query.getParams().getSortField());
      WritableComparable sortValue;

      if (raw instanceof Integer) {
        sortValue = new IntWritable(((Integer)raw).intValue());
      } else if (raw instanceof Float) {
        sortValue = new FloatWritable(((Float)raw).floatValue());
      } else if (raw instanceof String) {
        sortValue = new Text((String)raw);
      } else if (raw instanceof Long) {
        sortValue = new LongWritable(((Long)raw).longValue());
      } else {
        throw new RuntimeException("Unknown sort value type!");
      }

      final String dedupValue = (String) solrDoc.getFirstValue(query.getParams().getDedupField());

      final String uniqueKey = (String )solrDoc.getFirstValue(searchUID);

      hitArr[i] = new Hit(uniqueKey, sortValue, dedupValue);
    }

    return new Hits(docList.getNumFound(), hitArr);
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

            results.remove(i);
        }

        public IndexRow next() {
            if (i < results.size()) {
                final SolrDocument doc = results.get(i);
                i++;
                return new IndexRow() {
                    @Override
                    public String getPath() {
                        String path = String.valueOf(doc.getFieldValue(
                                configuration.getPathField()));
                        if ("/".equals(path)) {
                            return "/";
                        } else {
                            return path.substring(0, path.length() - 1);
                        }
                    }

                    @Override
                    public PropertyValue getValue(String columnName) {
                        Object o = doc.getFieldValue(columnName);
                        return o == null ? null : PropertyValues.newString(o.toString());
                    }

                };
            } else {
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

        assertEquals(4, response.getResults().getNumFound());

        // Check fields were indexed correctly.
        response = executeSolrQuery("title:Learning XML");

        SolrDocument doc = response.getResults().get(0);
        assertEquals("Learning XML", doc.getFieldValue("id"));
        assertEquals(Arrays.asList("Web", "Technology", "Computers"), doc.getFieldValue("cat"));
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

        assertEquals(4, response.getResults().getNumFound());

        // Check fields were indexed correctly.
        response = executeSolrQuery("title:Learning XML");

        SolrDocument doc = response.getResults().get(0);
        assertEquals("Learning XML", doc.getFieldValue("id"));
        assertEquals(Arrays.asList("Web", "Technology", "Computers"), doc.getFieldValue("cat"));
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

        QueryResponse response = executeSolrQuery("*:*");

        assertEquals(0, response.getStatus());
        assertEquals(1, response.getResults().getNumFound());

        SolrDocument doc = response.getResults().get(0);
        assertEquals("Solr", doc.getFieldValue("subject"));
        assertEquals("tutorial.pdf", doc.getFieldValue("id"));
        assertEquals(Arrays.asList("application/pdf"), doc.getFieldValue("content_type"));
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

        QueryResponse response = executeSolrQuery("*:*");

        assertEquals(0, response.getStatus());
        assertEquals(1, response.getResults().getNumFound());

        SolrDocument doc = response.getResults().get(0);
        assertEquals("Solr", doc.getFieldValue("subject"));
        assertEquals("tutorial.pdf", doc.getFieldValue("id"));
        assertEquals(Arrays.asList("application/pdf"), doc.getFieldValue("content_type"));
    }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

    }
  }

   public SolrDocument readSolrDocument(FastInputStream dis) throws IOException {
    NamedList nl = (NamedList) readVal(dis);
    SolrDocument doc = new SolrDocument();
    for (int i = 0; i < nl.size(); i++) {
      String name = nl.getName(i);
      Object val = nl.getVal(i);
      doc.setField(name, val);
    }
    return doc;
  }
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

            results.remove(i);
        }

        public IndexRow next() {
            if (i < results.size()) {
                final SolrDocument doc = results.get(i);
                i++;
                return new IndexRow() {
                    @Override
                    public String getPath() {
                        String path = String.valueOf(doc.getFieldValue(
                                configuration.getPathField()));
                        if ("/".equals(path)) {
                            return "/";
                        } else {
                            return path.substring(0, path.length() - 1);
                        }
                    }

                    @Override
                    public PropertyValue getValue(String columnName) {
                        Object o = doc.getFieldValue(columnName);
                        return o == null ? null : PropertyValues.newString(o.toString());
                    }

                };
            } else {
View Full Code Here

Examples of org.apache.solr.common.SolrDocument

    results.setStart(request.paramAsInt("start", 0));

    // loop though the results and convert each
    // one to a SolrDocument
    for (SearchHit hit : hits.getHits()) {
      SolrDocument doc = new SolrDocument();

      // always add score to document
      doc.addField("score", hit.score());

      // attempt to get the returned fields
      // if none returned, use the source fields
      Map<String, SearchHitField> fields = hit.getFields();
      Map<String, Object> source = hit.sourceAsMap();
      if (fields.isEmpty()) {
        if (source != null) {
          for (String sourceField : source.keySet()) {
            Object fieldValue = source.get(sourceField);

            // ES does not return date fields as Date Objects
            // detect if the string is a date, and if so
            // convert it to a Date object
            if (fieldValue.getClass() == String.class) {
              if (datePattern.matcher(fieldValue.toString()).matches()) {
                fieldValue = dateFormat.parseDateTime(fieldValue.toString()).toDate();
              }
            }

            doc.addField(sourceField, fieldValue);
          }
        }
      } else {
        for (String fieldName : fields.keySet()) {
          SearchHitField field = fields.get(fieldName);
          Object fieldValue = field.getValue();

          // ES does not return date fields as Date Objects
          // detect if the string is a date, and if so
          // convert it to a Date object
          if (fieldValue.getClass() == String.class) {
            if (datePattern.matcher(fieldValue.toString()).matches()) {
              fieldValue = dateFormat.parseDateTime(fieldValue.toString()).toDate();
            }
          }

          doc.addField(fieldName, fieldValue);
        }
      }

      // add the SolrDocument to the SolrDocumentList
      results.add(doc);
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.