Esempio n. 1
0
  /**
   * Find words for a more-like-this query former.
   *
   * @param docNum the id of the lucene document from which to find terms
   */
  private PriorityQueue<ScoreTerm> retrieveTerms(int docNum) throws IOException {
    Map<String, Int> termFreqMap = new HashMap<>();
    for (String fieldName : fieldNames) {
      final Fields vectors = ir.getTermVectors(docNum);
      final Terms vector;
      if (vectors != null) {
        vector = vectors.terms(fieldName);
      } else {
        vector = null;
      }

      // field does not store term vector info
      if (vector == null) {
        StoredDocument d = ir.document(docNum);
        StorableField[] fields = d.getFields(fieldName);
        for (StorableField field : fields) {
          final String stringValue = field.stringValue();
          if (stringValue != null) {
            addTermFrequencies(new StringReader(stringValue), termFreqMap, fieldName);
          }
        }
      } else {
        addTermFrequencies(termFreqMap, vector);
      }
    }

    return createQueue(termFreqMap);
  }
  private static SolrInputDocument toSolrInputDocument(StoredDocument doc, IndexSchema schema) {
    SolrInputDocument out = new SolrInputDocument();
    for (StorableField f : doc.getFields()) {
      String fname = f.name();
      SchemaField sf = schema.getFieldOrNull(f.name());
      Object val = null;
      if (sf != null) {
        if (!sf.stored() || schema.isCopyFieldTarget(sf)) continue;
        val = sf.getType().toObject(f); // object or external string?
      } else {
        val = f.stringValue();
        if (val == null) val = f.numericValue();
        if (val == null) val = f.binaryValue();
        if (val == null) val = f;
      }

      // todo: how to handle targets of copy fields (including polyfield sub-fields)?
      out.addField(fname, val);
    }
    return out;
  }
Esempio n. 3
0
 @Override
 public void write(TextResponseWriter writer, String name, StorableField f) throws IOException {
   writer.writeStr(name, f.stringValue(), true);
 }
 /** Given the stored field, return the indexed form */
 public String storedToIndexed(StorableField f) {
   // right now, the transformation of single valued fields like SortableInt
   // is done when the Field is created, not at analysis time... this means
   // that the indexed form is the same as the stored field form.
   return f.stringValue();
 }
 /**
  * Convert the stored-field format to an external (string, human readable) value
  *
  * @see #toInternal
  */
 public String toExternal(StorableField f) {
   // currently used in writing XML of the search result (but perhaps
   // a more efficient toXML(IndexableField f, Writer w) should be used
   // in the future.
   return f.stringValue();
 }