Hi Sabarish
I might do something like this:
class ArticleAttributes
def self.call(interpreter)
interpreter.has interpreter.created_at, interpreter.view_count,
interpreter.helpful_count
end
end
And then in each index, instead of your attributes, use the following
(double-colon prefix is necessary):
::ArticleAttributes.call self
You’ll also notice I wrapped up all attributes into a single call - they can be
separate if you like:
class ArticleAttributes
def self.call(interpreter)
interpreter.has interpreter.created_at
interpreter.has interpreter.view_count
interpreter.has interpreter.helpful_count
end
end
If the columns are integer types, then you don’t need to specify the type
manually, and all attributes are sortable by their very nature - so the
:sortable option only applies to fields.
Also, with this DRYing up - if you’re getting attributes via associations, then
you just chain those methods between interpreter and the column - it’s all
method_missing magic:
interpreter.has interpreter.user.name, :as => :username
Cheers
—
Pat
> On 10 Dec 2014, at 9:04 pm, Sabarish Sankar <[email protected]>
> wrote:
>
> Hi Pat,
>
> We have a requirement where we want to ignore stop words for indexing title
> but consider the stop words for other attributes of the model. From the
> following reference <https://github.com/pat/thinking-sphinx/issues/580>, we
> have created two different indices for the same model.
>
> Index 1:
>
> ThinkingSphinx::Index.define :article, with: :active_record, delta:
> ThinkingSphinx::Deltas::DelayedDelta do
>
> indexes article_content.body, as: :body
> indexes article_content.source, as: :source
> has :created_at
> has view_count, type: :integer, sortable: true
> has helpful_count, type: :integer, sortable: true
> set_property stopwords: "/stopwords.txt"
>
> end
>
> Index 2:
>
> ThinkingSphinx::Index.define :article, name: 'article_1', with:
> :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta do
>
> indexes article_content.title, as: :title
> has :created_at
> has view_count, type: :integer, sortable: true
> has helpful_count, type: :integer, sortable: true
>
> end
>
> As per the documentation
> <http://pat.github.io/thinking-sphinx/indexing.html#multiple>, we had to
> define all the attributes both the indices. This looks repetitive to have the
> same attributes in multiple places. Can you help us with the right way to DRY
> the attributes and use it in both the indices ? Thanks in advance.
>
> Regards,
> Sabarish S
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/thinking-sphinx
> <http://groups.google.com/group/thinking-sphinx>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.