Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoboBrowser.Browse method exception #5

Closed
dtosato opened this issue Jan 13, 2015 · 1 comment
Closed

BoboBrowser.Browse method exception #5

dtosato opened this issue Jan 13, 2015 · 1 comment

Comments

@dtosato
Copy link

dtosato commented Jan 13, 2015

Executing this test, I get back the following error from BoboBrowser.Browse method:

BoboBrowse.Net.BrowseException was unhandled
  HResult=-2146233088
  Message=Length cannot be less or equal than 0.
Nome parametro: length
  Source=BoboBrowse.Net
  StackTrace:
       in BoboBrowse.Net.BoboSubBrowser.Browse(BrowseRequest req, Weight weight, Collector collector, IDictionary`2 facetMap, Int32 start)
       in BoboBrowse.Net.MultiBoboBrowser.Browse(BrowseRequest req, Weight weight, Collector hitCollector, IDictionary`2 facetMap, Int32 start)
       in BoboBrowse.Net.MultiBoboBrowser.Browse(BrowseRequest req, Collector hitCollector, IDictionary`2 facetMap, Int32 start)
       in BoboBrowse.Net.MultiBoboBrowser.Browse(BrowseRequest req, Collector hitCollector, IDictionary`2 facetMap)
       in BoboBrowse.Net.MultiBoboBrowser.Browse(BrowseRequest req)
       in ResultNumberTest.Program.CategoryFacetNavigation(Type facetHandlerType) in D:\TEMP\ResultNumberTest\ResultNumberTest\ResultNumberTest\Program.cs:riga 90
       in ResultNumberTest.Program.Main(String[] args) in D:\TEMP\ResultNumberTest\ResultNumberTest\ResultNumberTest\Program.cs:riga 32
       in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       in System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ArgumentOutOfRangeException
       HResult=-2146233086
       Message=Length cannot be less or equal than 0.
Nome parametro: length
       Source=mscorlib
       ParamName=length
       StackTrace:
            in System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
            in BoboBrowse.Net.Facets.Filter.FacetRangeFilter.GetRangeStrings(String rangeString)
            in BoboBrowse.Net.Facets.Filter.FacetRangeFilter.Parse(FacetDataCache dataCache, String rangeString)
            in BoboBrowse.Net.Facets.Filter.FacetRangeFilter.ConvertIndexes(FacetDataCache dataCache, String[] vals)
            in BoboBrowse.Net.Facets.Filter.FacetRangeFilter.FacetRangeValueConverter.Convert(FacetDataCache dataCache, String[] vals)
            in BoboBrowse.Net.Facets.Range.ValueConverterBitSetBuilder.BitSet(FacetDataCache dataCache)
            in BoboBrowse.Net.Facets.Filter.BitSetFilter.GetBitSet(FacetDataCache dataCache)
            in BoboBrowse.Net.Facets.Filter.BitSetFilter.GetRandomAccessDocIdSet(BoboIndexReader reader)
            in BoboBrowse.Net.Facets.Filter.RandomAccessAndFilter.GetRandomAccessDocIdSet(BoboIndexReader reader)
            in BoboBrowse.Net.Facets.Filter.RandomAccessFilter.GetDocIdSet(IndexReader reader)
            in BoboBrowse.Net.Search.BoboSearcher2.Search(Weight weight, Filter filter, Collector collector, Int32 start, IBoboMapFunctionWrapper mapReduceWrapper)
            in BoboBrowse.Net.BoboSubBrowser.Browse(BrowseRequest req, Weight weight, Collector collector, IDictionary`2 facetMap, Int32 start)
       InnerException: 

This exception pops out only when RangeFacetHandler is used.

@NightOwl888
Copy link
Owner

As I mentioned previously, the values that are specified for selections in a RangeFacetHandler must correspond to the range strings that are specified when creating the handler.

// Specify range handler
categoryFacetHandler = new RangeFacetHandler(category, new List<string> { "[Articoli TO Clienti]", "[Clienti TO *]" });

// Specify selections
sel1.AddValue("[Articoli TO Clienti]");

Corrected version of CategoryFacetNavigation:

private static int CategoryFacetNavigation(Type facetHandlerType)
{
    // Definizione facce.
    string category = "Category";
    IFacetHandler categoryFacetHandler;
    if (facetHandlerType == typeof(SimpleFacetHandler))
    {
        categoryFacetHandler = new SimpleFacetHandler(category);
    }
    else if (facetHandlerType == typeof(MultiValueFacetHandler))
    {
        categoryFacetHandler = new MultiValueFacetHandler(category);
    }
    else if (facetHandlerType == typeof(RangeFacetHandler))
    {
        categoryFacetHandler = new RangeFacetHandler(category, new List<string> { "[Articoli TO Clienti]", "[Clienti TO *]" }); 
    }
    else
    {
        throw new InvalidOperationException("Unknown facet.");
    }

    ICollection<IFacetHandler> handlerList = new IFacetHandler[] { categoryFacetHandler };
    string indexDir = @"../../../data/index";
    using (Lucene.Net.Store.Directory idx = FSDirectory.Open(new System.IO.DirectoryInfo(indexDir)))
    {
        using (IndexReader reader = IndexReader.Open(idx, true))
        {
            using (BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, handlerList))
            {
                // Request.
                BrowseRequest browseRequest = new BrowseRequest();
                browseRequest.Count = 10;
                browseRequest.Offset = 0;

                BrowseSelection sel1 = new BrowseSelection(category);
                if (facetHandlerType == typeof(RangeFacetHandler))
                {
                    sel1.AddValue("[Articoli TO Clienti]");
                }
                else
                {
                    sel1.AddValue("Articoli");
                    sel1.AddValue("Clienti");
                    sel1.AddNotValue("Ordini");
                    sel1.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationOr;
                }
                browseRequest.AddSelection(sel1);

                // Query.
                MatchAllDocsQuery query = new MatchAllDocsQuery();

                // Add the facet output specs.
                FacetSpec spec1 = new FacetSpec();
                spec1.OrderBy = FacetSpec.FacetSortSpec.OrderValueAsc;
                spec1.MaxCount = 20;
                browseRequest.SetFacetSpec(category, spec1);

                // Browse.
                IBrowsable browser = new BoboBrowser(boboReader);
                BrowseResult result = browser.Browse(browseRequest);

                // Result.
                return result.NumHits;
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants