Skip to content

SCI & criteria support - #37

Closed
tomasc wants to merge 58 commits into
mongoid:masterfrom
tomasc:sci-support
Closed

tomasc wants to merge 58 commits into
mongoid:masterfrom
tomasc:sci-support

Conversation

@tomasc

@tomasc tomasc commented May 5, 2018 •

Copy link
Copy Markdown
Contributor

The search now respects SCI.

From the included spec:

class MyDoc
  include Mongoid::Document
  include Mongoid::FullTextSearch

  field :title
  fulltext_search_in :title
end

class MyInheritedDoc < MyDoc
end
MyDoc.fulltext_search(…) # => will return both MyDoc as well as MyInheritedDoc documents
MyInheritedDoc.fulltext_search(…) # => will return only MyInheritedDoc documents

It is also possible to pre-empt the search with Monogid criteria:

MyDoc.where(value: 10).fulltext_search(…)

Please note that this will obviously not work in case an index is shared by multiple classes (that are not connected through inheritance), since a criteria applies only to one class.

@tomasc

tomasc commented May 5, 2018

Copy link
Copy Markdown
Contributor Author

builds upon #35 , will rebased once that one is merged

@tomasc tomasc mentioned this pull request May 5, 2018
@tomasc

tomasc commented May 8, 2018

Copy link
Copy Markdown
Contributor Author

@dblock here we keep failing miserably on Mongoid 3 (but not 3.1). No idea why, again …

@dblock

dblock commented May 8, 2018 •

Copy link
Copy Markdown
Contributor

I can reproduce this locally and it looks like a clear bug introduced in this PR. We could drop support for 3.0, but I'd like to understand what's going on.

With Mongoid 3.

Both ExternalArtist and ExternalArtwork are using the same index, mongoid_fulltext.artworks_and_artists.

I am supposed to get back 2 objects, an external artist and artwork via ExternalArtwork.fulltext_search. The correct result is:

[#<ExternalArtist _id: 5af21a8f9b0b58e214000001, _type: nil, full_name: "Pablo Picasso">,
 #<ExternalArtwork _id: 5af21a8f9b0b58e214000002, _type: nil, title: "Portrait of Picasso">]

In Mongoid 3 the query is {"ngram"=>"picasso", "class"=>{"$in"=>["ExternalArtwork"]}} which is incorrect.

The code in document_type_filters does return {} unless fields['_type'].present?, in Mongoid 3 fields['_type'] returns #<Mongoid::Fields::Standard:...>", and in Mongoid > 3.1 that's nil. I am not sure what that means ;)

@dblock

dblock commented May 9, 2018

Copy link
Copy Markdown
Contributor

I tried fields['_type'].default_val.call instead, and that passed all tests, which tells me you're missing a test here for a descendant type, that is never not nil in the entire test suite.

@dblock

dblock commented May 9, 2018

Copy link
Copy Markdown
Contributor

This is simpler and works for all versions:

return {} if descendants.none?

@dblock

dblock commented May 10, 2018

Copy link
Copy Markdown
Contributor

@tomasc Got a moment to wrap this up?

@tomasc

tomasc commented Jul 11, 2018

Copy link
Copy Markdown
Contributor Author

@dblock will try to get to that this week. In the end I ended up not using the gem, but yes, let's wrap this up.

dblock added a commit to dblock/mongoid_fulltext that referenced this pull request Oct 17, 2026
Adapt the SCI and criteria proposal from @tomasc in mongoid#37; preserve shared-index searches and apply limits after excluding missing/scoped-out documents.

Co-authored-by: Tomas Celizna <tomas.celizna@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dblock added a commit to dblock/mongoid_fulltext that referenced this pull request Oct 17, 2026
Adapt the SCI and criteria proposal from @tomasc in mongoid#37; preserve shared-index searches and apply limits after excluding missing/scoped-out documents.

Co-authored-by: Tomas Celizna <tomas.celizna@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dblock

dblock commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

AI posting on behalf of @dblock: adapted this proposal onto the modernized code in #57, with @tomasc credited in the changelog, PR description, and commit coauthor. The replacement adds regression coverage for result limits after filtering, dangling references with strict Mongoid settings, scores, descendants, and unscoped/shared-index compatibility, including Mongoid 3.0. Its complete fork matrix is green: https://github.com/dblock/mongoid_fulltext/actions/runs/38996842235. Closing this older PR in favor of #57; thank you for the original implementation.

@dblock dblock closed this Oct 17, 2026
dblock added a commit to dblock/mongoid_fulltext that referenced this pull request Oct 17, 2026
Adapt the SCI and criteria proposal from @tomasc in mongoid#37; preserve shared-index searches and apply limits after excluding missing/scoped-out documents.

Co-authored-by: Tomas Celizna <tomas.celizna@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dblock added a commit that referenced this pull request Oct 17, 2026
Adapt the SCI and criteria proposal from @tomasc in #37; preserve shared-index searches and apply limits after excluding missing/scoped-out documents.

Co-authored-by: Tomas Celizna <tomas.celizna@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants