Project Description

BoboBrowse.Net is a faceted browse engine implemented on a top of Lucene.Net.

Originally ported from wonderful Java library developed by John Wang (http://javasoze.github.com/bobo/ ).

private const string fieldName = "File Type";

        [Test]
        public void BrowseTest()
        {
            FacetHandler facetHandler = new MultiValueFacetHandler(fieldName);

            ICollection<FacetHandler> handlerList = new FacetHandler[] { facetHandler };

            // opening a lucene index

            string indexDir = Utils.GetTestData("Index");

            Directory idx = FSDirectory.Open(new System.IO.DirectoryInfo(indexDir));
            IndexReader reader = IndexReader.Open(idx, true);

            // decorate it with a bobo index reader
            BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, handlerList);

            // creating a browse request
            BrowseRequest browseRequest = new BrowseRequest();
            browseRequest.Count = 10;
            browseRequest.Offset = 0;
            browseRequest.FetchStoredFields = true;

            // add a selection
            BrowseSelection sel = new BrowseSelection(fieldName);
            //sel.addValue("21");
            browseRequest.AddSelection(sel);

            // parse a query
            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Entity", new KeywordAnalyzer());
            Query q = parser.Parse("SPListItem");
            browseRequest.Query = q;

            // add the facet output specs
            FacetSpec colorSpec = new FacetSpec();
            colorSpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;

            FacetSpec categorySpec = new FacetSpec();
            categorySpec.MinHitCount = 2;
            categorySpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;

            browseRequest.SetFacetSpec(fieldName, colorSpec);

            // perform browse
            IBrowsable browser = new BoboBrowser(boboReader);

            BrowseResult result = browser.Browse(browseRequest);

            // Showing results now
            int totalHits = result.GetNumHits();
            BrowseHit[] hits = result.GetHits();

            Dictionary<String, IFacetAccessible> facetMap = result.GetFacetMap();

            IFacetAccessible colorFacets = facetMap[fieldName];

            IEnumerable<BrowseFacet> facetVals = colorFacets.GetFacets();

            Debug.WriteLine("Facets:");

            foreach (BrowseFacet facet in facetVals)
            {
                Debug.WriteLine(facet.ToString());
            }

            Debug.WriteLine("Actual items:");

            for (int i = 0; i < hits.Length; ++i)
            {
                BrowseHit browseHit = hits[i];
                Debug.WriteLine(browseHit.StoredFields.Get("LeafName"));
            }
        }

And here is the output:

Facets:
dwp(60)
thmx(40)
webpart(26)
aspx(11)
master(7)
xsn(6)
png(4)
rules(3)
vdw(3)
xml(3)
xoml(3)
xlsx(2)
gif(1)
pdf(1)
Actual items:
default.master
v4.master
minimal.master
mysite.master
1_.000
3_.000
1073741823_.000
owatasks.dwp
owacalendar.dwp
Microsoft.Office.InfoPath.Server.BrowserForm.webpart

Last edited Aug 19, 2011 at 3:31 PM by Shcherbachev, version 4