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

  • SEARCH
  • Home
  • 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 7712981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:45:31+00:00 2026-06-01T01:45:31+00:00

When adding a term to my query instead of a filter I am getting

  • 0

When adding a term to my query instead of a filter I am getting 0 facets. FYI I am using the tire gem with Ruby.

Here is my model code with its mapping:

class Property < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

  has_and_belongs_to_many :tags

   mapping do
    indexes :id,                type: 'integer'
    indexes :status
    indexes :refno,             type: 'integer'
    indexes :name,              :analyzer => 'snowball', :boost => 100
    indexes :description
    indexes :tags,              type: 'object',
                                  properties: {
                                    name: { type: 'multi_field',
                                      fields: {
                                        name: { type: 'string', analyzer: 'snowball' },
                                        exact: { type: 'string', index: 'not_analyzed' }
                                      }
                                    }
                                   }                                 
  end

  def to_indexed_json
    to_json( include: { 
      tags: { only: [:name] },
     })
  end

Then here is the search method

  def self.search(params={})
    tire.search(page: params[:page], per_page: 2, load: true) do
      query do
        boolean do
         must { string params[:name], default_operator: "AND" } if params[:name].present?
         must { term :status, 'live' }
         must { term :refno, params[:refno]} if params[:refno].present?
         # must { term :tag, params[:tag]} if params[:tag].present? ## does not work either
         must { term 'tags.name.exact', params[:tag]} if params[:tag].present?
        end
      end
      facet "tags" do
        terms 'tags.name.exact'
      end
      raise to_json
      # raise to_curl
    end
  end

I get 0 Facets. But if I move facets to a filter ie below I get full facets.

  def self.search(params={})
    tire.search(page: params[:page], per_page: 2, load: true) do
      query do
        boolean do
         must { string params[:name], default_operator: "AND" } if params[:name].present?
         must { term :status, 'live' }
         must { term :refno, params[:refno]} if params[:refno].present?
        end
      end
      filter :term, 'tags.name.exact' => params[:tag] if params[:tag].present?
      facet "tags" do
        terms 'tags.name.exact'
      end
      raise to_json
      # raise to_curl
    end
  end

While this is ok it’s not want, When a facet filter is clicked I want to remove non available tags from my facet filter and update the new facet count.

If it helps here is the json for the query which works and does not.

## No Factes
{
   "query":{
      "bool":{
         "must":[
            {
               "query_string":{
                  "query":"England",
                  "default_operator":"AND"
               }
            },
            {
               "term":{
                  "status":"live"
               }
            },
            {
               "term":{
                  "tags.name.exact":[
                     "Pet Friendly"
                  ]
               }
            }
         ]
      }
   },
   "facets":{
      "tags":{
         "terms":{
            "field":"tags.name.exact",
            "size":10,
            "all_terms":false
         }
      }
   },
   "size":2
}

## Facets working
{
   "query":{
      "bool":{
         "must":[
            {
               "query_string":{
                  "query":"England",
                  "default_operator":"AND"
               }
            },
            {
               "term":{
                  "status":"live"
               }
            }
         ]
      }
   },
   "facets":{
      "tags":{
         "terms":{
            "field":"tags.name.exact",
            "size":10,
            "all_terms":false
         }
      }
   },
   "filter":{
      "term":{
         "tags.name.exact":[
            "Pet Friendly"
         ]
      }
   },
   "size":2
}

Really hope someone can advise. Starting to pull my hair out on this one.

  • 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-06-01T01:45:32+00:00Added an answer on June 1, 2026 at 1:45 am

    I was actually very close. As my tags can have multiple I needed to use terms not term ie,

      def self.search(params={})
        tire.search(page: params[:page], per_page: 2, load: true) do
          query do
            boolean do
             must { string params[:name], default_operator: "AND" } if 
             must { term :status, 'live' }
             must { term :refno, params[:refno]} if params[:refno].present?
             must { terms 'tags.name.exact', params[:tag]} if params[:tag].present?
            end
          end
          facet "tags" do
            terms 'tags.name.exact'
          end
          # raise to_json
          # raise to_curl
        end
      end
    

    Thank you for your advise though imotov, Hoang.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is javascript code (jquery) for adding a row of images: var tr =
I am using Dev-C++. It doesn't show any code error, but fails to work.
I need to manipulate some URL in term of adding component to it in
Each new term in the Fibonacci sequence is generated by adding the previous two
EDIT: I'm adding a new rough table model for comment. Is this what you
I'm trying to start using lucene. The code, I'm using to index documents is:
When adding a taxonomy term in Drupal, it redirects back to itself to add
Is there anyway of doing this by using rules or by some custom code?
I am adding subscriptions to a site using Paypal IPN which works very well,
At the moment I have spotlight-api code which searches email's body. I'm using NSMetadataQuery

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.