[SERVER-26959] Make text queries work on views whenever possible Created: 08/Nov/16 Updated: 22/Mar/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Diagnostics, Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Kyle Suarez | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | read-only-views | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||
| Participants: | |||||||||||||
| Case: | (copied to CRM) | ||||||||||||
| Description |
| Comments |
| Comment by Kyle Suarez [ 28/Nov/17 ] | ||
|
Hello ashraf.seventech@gmail.com, No, you cannot perform a $text query on a view. Again, the fix version of this ticket is marked as "Backlog", meaning that we have not yet scheduled to work on it. Please vote for this issue, so that we know how to prioritize this improvement when planning for future releases. Regards, | ||
| Comment by Ashraf Kamal [ 23/Nov/17 ] | ||
|
Hi Kyle Oh! you mean the $text query was not working on view is fixed? wow the it would be good news for us. Please let us know when it is released. | ||
| Comment by Kyle Suarez [ 22/Nov/17 ] | ||
|
Hey ashraf.seventech@gmail.com, Sorry, that wasn't a great example. In your case, the text search varies with user input, so you cannot perform your text search on a view. Instead, you will have to perform the text search against the base collection. For example, if you had a view that filters food based on type:
You could issue a query on "foodCollection" that both applies a text search and performs the view transformation:
In general, though, this won't work for every view, depending on the what the view transformation pipeline is. Though we're aware of this limitation, this ticket has a fix version of "Backlog", meaning we have not yet scheduled it for an upcoming release. Please vote for this issue and follow the ticket for further updates. I hope this helps! | ||
| Comment by Ashraf Kamal [ 21/Nov/17 ] | ||
|
Hi Kyle. Thanks | ||
| Comment by Kyle Suarez [ 15/Nov/17 ] | ||
|
Hi ashraf.seventech@gmail.com, In general you cannot issue an aggregation with $text matching on a view because the $text must be the first stage in the pipeline. When you query a view the view definition's pipeline always comes first. I'd say there's three options for you, depending on what you're trying to accomplish. First, if the text search is something you always want to perform on the view, you can accomplish that by changing the view definition to include a $match with a $text search as the very first stage of the pipeline. Second, if you don't always want to perform the text query but the text search string is fixed, you could also make a second view (say, textSearchView) that is identical to the first view except that it includes a $match with a $text search. For example, if you created a view like
and you needed to make queries with a fixed text search, just make a second view:
Lastly, if the text being searched for is variable or you wanted to perform ad-hoc queries, then you'd have to attempt a workaround by performing an aggregation on the underlying collection like I described above. Kyle | ||
| Comment by Ashraf Kamal [ 15/Nov/17 ] | ||
|
Hi Kyle Suarez, Can you please tell me how to use aggregation pipeline for $text on view. I actually a beginner. It would be helpul for me if you give me one example to use aggregation pipeline. Thanks | ||
| Comment by Kyle Suarez [ 09/Nov/17 ] | ||
|
Hello ashraf.seventech@gmail.com, Like I mentioned in the description of the ticket it is not possible to use a $text query on a view in the same way that you would use a $text query on a collection. Recall that a view is just an aggregation pipeline that is applied to a collection (or another view). It might be possible to work around this limitation by issuing an aggregation pipeline with a $text query against the underlying collection. Note that a $text query has to be the first stage in the pipeline. The Query Team is planning on improvements to $text search on views in the future. As you can see, the "fixVersion" here is "Backlog", meaning that we have not yet scheduled this work for a definitive release target. Please vote for this issue and continue watching this ticket for updates. Regards, | ||
| Comment by Ashraf Kamal [ 09/Nov/17 ] | ||
|
HI, Please give me solution how can I use $text query on view. How can I get search result using $text query from view |