DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Facet Over The Same Field Multiple Times With Different Filters in Solr

John Berryman user avatar by
John Berryman
·
Feb. 21, 13 · Interview
Like (0)
Save
Tweet
Share
4.37K Views

Join the DZone community and get the full member experience.

Join For Free

Did you know that you can facet over the same field more than once? Did you know that you can rename the facet field? Did you know that you have display the facet with different filters?

Let’s say I want to look at the number of StackOverflow answers for recent questions as compared to the number of answers across all questions ever asked. I did this be creating a filter query tagged with “moreRecent.” And then I faceted over the AnswerCount field twice, once with the alias of RecentAnswerCount and once with the alias of TotalAnswerCount. The later facet excluded the “moreRecent” filter query.

Here’s the query:

http://localhost:8983/solr/collection1/select
?q=*:*
&facet=on
&fq={!tag=moreRecent}CreationDate:[2011-08-05T19:34:49.473Z TO NOW]
&facet.field={!key=RecentAnswerCount}AnswerCount
&facet.field={!key=TotalAnswerCount ex=moreRecent}AnswerCount

And here is the response:

<lst name="facet_fields">
        </lst><lst name="RecentAnswerCount">
            <int name="2">2543</int>
            <int name="1">2059</int>
            <int name="3">1831</int>
            <int name="4">1015</int>
            <int name="5">514</int>
            <int name="6">222</int>
            <int name="7">114</int>
            <int name="0">95</int>
            <int name="8">77</int>
            <int name="9">44</int>
            <int name="10">24</int>
            <int name="11">12</int>
            <int name="12">9</int>
            <int name="14">8</int>
            <int name="13">6</int>
            <int name="15">4</int>
            <int name="16">4</int>
            <int name="18">3</int>
            <int name="17">2</int>
            <int name="19">2</int>
            <int name="21">2</int>
            <int name="22">2</int>
            <int name="20">1</int>
            <int name="23">1</int>
            <int name="25">1</int>
            <int name="26">1</int>
            <int name="28">1</int>
            <int name="24">0</int>
            <int name="42">0</int>
            <int name="116">0</int>
        </lst>
        <lst name="TotalAnswerCount">
            <int name="2">4862</int>
            <int name="3">3729</int>
            <int name="1">3582</int>
            <int name="4">2116</int>
            <int name="5">1172</int>
            <int name="6">560</int>
            <int name="7">297</int>
            <int name="8">183</int>
            <int name="0">173</int>
            <int name="9">109</int>
            <int name="10">62</int>
            <int name="11">38</int>
            <int name="12">26</int>
            <int name="14">19</int>
            <int name="13">16</int>
            <int name="15">12</int>
            <int name="16">7</int>
            <int name="18">6</int>
            <int name="19">5</int>
            <int name="21">5</int>
            <int name="17">3</int>
            <int name="22">3</int>
            <int name="20">2</int>
            <int name="23">1</int>
            <int name="24">1</int>
            <int name="25">1</int>
            <int name="26">1</int>
            <int name="28">1</int>
            <int name="42">1</int>
            <int name="116">1</int>
        </lst>
Filter (software)

Published at DZone with permission of John Berryman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Automated Performance Testing With ArgoCD and Iter8
  • Secrets Management
  • Using AI and Machine Learning To Create Software
  • Top Authentication Trends to Watch Out for in 2023

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: