Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6217235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:23:29+00:00 2026-05-24T07:23:29+00:00

Without using the latest version of Lucene with faceting enabled, I am trying to

  • 0

Without using the latest version of Lucene with faceting enabled, I am trying to implement multi-facets hitcounts. I have found a great post to get started, but not sure of the next step of multi-value facets.

The below example shows code for a singular example, e.g. Category field, and getting count for each one.

private static void FacetedSearch(string indexPath, string genre, string term)
{
    // create searcher
    var searcher = new IndexSearcher(indexPath);

    // first get the BitArray result from the genre query
    var genreQuery = new TermQuery(new Term("genre", genre));
    var genreQueryFilter = new QueryFilter(genreQuery);
    BitArray genreBitArray = genreQueryFilter.Bits(searcher.GetIndexReader());
    Console.WriteLine("There are " + GetCardinality(genreBitArray) + " document with the genre " + genre);

    // Next perform a regular search and get its BitArray result
    Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, 
                                        new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, 
                                        new StandardAnalyzer());
    var searchQueryFilter = new QueryFilter(searchQuery);
    BitArray searchBitArray = searchQueryFilter.Bits(searcher.GetIndexReader());
    Console.WriteLine("There are " + GetCardinality(searchBitArray) + " document containing the term " + term);

    // Now do the faceted search magic, combine the two bit arrays using a binary AND operation
    BitArray combinedResults = searchBitArray.And(genreBitArray);
    Console.WriteLine("There are " + GetCardinality(combinedResults) + 
                " document containing the term " + term + " and which are in the genre " + genre);
}

But, if I have two separate fields, e.g. Category and Topic, so that I could have:

  • Category1, Category2

  • Topic1, Topic2

in my UI, if each of these is a checkbox, I could select both category1, and category2, then the counts for topic1, topic2 would be different than if I just select category1.

Not sure how to do the bitarray searches for that multiple instance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:23:30+00:00Added an answer on May 24, 2026 at 7:23 am

    To work out the facet counts you need to get the cardinality of two searches. In your example above your first search is for items with genre = genre, and then counting the facets for your term in title and description.

    To achieve what you are after, you need to create your base search, which will be a query where the product is in both category1 AND category2, so to do this you would have a BooleanQuery to get your initial result set, this would be something like

    var booleanQuery = new BooleanQuery();
    booleanQuery.Add(new Term("category", "Category1"));
    booleanQuery.Add(new Term("category", "Category2"));
    var categoryFilter = new QueryFilter(booleanQuery);
    var catBits = categoryFilter.Bits(searcher.GetIndexReader());
    

    To then count for each facet you would create a query for each facet individually (in a loop) and then do your getcardinality call between your category query and each facet query.

    foreach (var topic in myTopics) {
        var topicQueryFilter = new QueryFilter(new TermQuery(new Term("topic", topic)));
        var topicBits = topicQueryFilter.Bits(searcher.GetIndexReader());
    
        var facetResults = catBits.And(topicBits);
        var topicCount = GetCardinality(facetResults);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Windows XP, TortoiseGit (latest version) and Cygwin. I have git.exe installed and
Without using plpgsql, I'm trying to urlencode a given text within a pgsql SELECT
Is it possible without using exponentiation to have a set of numbers that when
In a situation where most of the users are using the latest version of
I need to know if it is possible to start using the latest version
My problem is that I have a bunch of file names without the version
I'm using the latest version of Firefox and Chrome on Win XP. I want
I'm using the latest version of Resharper (5.1.3) with the intellisense (Code completion and
I'm using the latest wordpress version, I installed it on another machine in my
Using the latest version of NHibernate (and possibly some plugins), is that possible to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.