PathFacetHandler fails on partial match


For an index only containing deep paths (e.g. A/B/C, A/B/D, but NOT A) a parent value (A) will not match.

PathFacetHandler.GetFilters(List<int>, string, int, bool) identifies the range of terms matching the selected path.

It does this by finding the first path prefix match in the ordered termList and selecting subsequent terms until the prefix no longer matches.

Current code calls IndexOf(T) on a list from dataCache.valArray.GetInnerList() - a List<T>, returning the index or -1.
But the code expects to be calling the IndexOf(object) from a ITermValueList, which does a BinarySearch, returning the index or a negative number that is the bitwise complement of the index of the next larger element.

Although TermValueList<T> implements ITermValueList and derives from List<T>, List<T>'s IndexOf() isn't virtual (and has a different signature - T vs object), so different IndexOf() methods are called when it's cast as List<T> or ITermValueList.

Calling List<T>.IndexOf() instead of ITermValueList.IndexOf() means that indexes containing an exact match for the parent, will succeed - and indexes not containing an exact match for the parent, will fail.

Possible fix (closer to original Java sources) follows.

diff --git a/BoboBrowse.Net/Facets/impl/PathFacetHandler.cs b/BoboBrowse.Net/Facets/impl/PathFacetHandler.cs
--- a/BoboBrowse.Net/Facets/impl/PathFacetHandler.cs
+++ b/BoboBrowse.Net/Facets/impl/PathFacetHandler.cs
@@ -123,7 +123,7 @@
     private void GetFilters(List<int> intSet, string val, int depth, bool strict)
  • List<string> termList = dataCache.valArray.GetInnerList();
  • ITermValueList termList = dataCache.valArray;
         int index = termList.IndexOf(val);
         int startDepth = GetPathDepth(val);
    @@ -141,7 +141,7 @@
         for (int i = index; i < termList.Count; ++i)
  • string path = termList[i];
  • string path = termList.Get(i);
             if (path.StartsWith(val))
                 if (!strict || GetPathDepth(path) - startDepth == depth)


Shcherbachev wrote Sep 24, 2012 at 12:14 PM

Thank you. Sources updated.