title: In Solr, can I sort on the matching value from a multi-valued field?
body: <p>We are considering a schema with two multi-valued fields. Search is performed on the first field, but sorting should be done on the second field, using the corresponding value. E.g. if documents match because of the n-th value in the first field (where n may be different for each match), then they should be returned sorted by the n-th value in the second field.</p>
  
  <p>Is that possible?</p>
  
  <p>Background: each document has a list of similar documents (IDs) and a corresponding list of similarity scores (value between 0 and 1). Given ID 42, we need to return all similar documents (e.g. documents with 42 in the first field), sorted by their similarity to document 42. </p>
  
  <p>Other schemas we are considering are:</p>
  
  <ol>
  <li>Dynamic fields for each ID so we can sort by the field Similarity_ID42 when searching for documents similar to 42. This does not seem to scale, at 800K+ documents, CPU goes to 100% during indexing.</li>
  <li>A single multi-valued field storing "ID.score" as a decimal (e.g. 42.563) and then searching for all documents that have a value that is > 42 AND &lt; 43, and sorting by that value (I'm not even sure this is possible). </li>
  </ol>