Weigh items in same folder (or ancestor folder) higher in search results

Recently there was a search weighting change that prioritizes items in the same document, which I’ve found to be particularly helpful in the “Move item” dialog. However, it would be great if this could be extended to prioritize items in documents that are “close” to the source document (weighted by shortest path between documents in the folder hierarchy graph, but prioritizing documents with closer shared ancestors).

For instance, if the document folder hierarchy is as follows:

- Folder 1
  - Document 1.1
  - Document 1.2
- Folder 2
  - Document 2.1
  - Folder 2.2
    - Document 2.2.1  <--- Document we're in and bring up "Move item"
    - Document 2.2.2
  - Folder 2.3
    - Document 2.3.1
    - Folder 2.3.2
       - Folder
          - Document

If we’re currently in Document 2.2.1 and search for a keyword that’s present in all documents, I think the document ranking should be as follows (with justification):

  1. Document 2.2.1: Distance 0. Already has top priority thanks to the recent change!
  2. Document 2.2.2: Distance 2. Same parent folder.
  3. Document 2.1: Distance 3. Same grandparent folder.
  4. Document 2.3.1: Distance 4. Same grandparent folder, but nested deeper than Document 2.1 causing a longer path and thus lower weighting.
  5. Document Distance 6. Shared common ancestor of Folder 2.
  6. Document 1.1/Document 1.2: Distance 5. This is the tricky one, as technically the path distance is less than the one above, but since its nearest ancestor is further away it should likely be weighed less than Document (perhaps though these should be weighed higher since they are more “top-level” documents, and deeply nested documents are more likely to be “archived” documents?)

A variant of BFS should generate this ranking, where parent nodes are not added to the normal BFS queue but instead placed in a separate queue that is only pulled from when the regular BFS queue is drained.