I'm interested in returning the minimum "distance" between two terms within an (analyzed) text document. For example, given a sentence of "The quick brown fox jumped over the lazy dog," I'd like to be able to extract (ignoring stop words for simplicity):
min_distance("brown", "fox") => 1 min_distance("brown", "dog") => 6
From what I've been able to find, the most straightforward way to do this would be to store the term_vector positions, find the positions for the terms I'm interested in, and then compute the smallest positional distance between them.
Is there a more clever, direct way to go about it? Is there some way to use a wide-open span query but have the response include the computed slop between the terms, for example?