@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
88
99use crate :: collection:: Collection ;
1010use crate :: operations:: types:: { CollectionResult , UpdateResult } ;
11+ use crate :: operations:: universal_query:: formula:: ExpressionInternal ;
1112use crate :: operations:: { CollectionUpdateOperations , CreateIndex , FieldIndexOperations } ;
1213use crate :: problems:: unindexed_field;
1314use crate :: save_on_disk:: SaveOnDisk ;
@@ -103,21 +104,44 @@ impl Collection {
103104 & self ,
104105 filter : & Filter ,
105106 ) -> Option < ( JsonPath , Vec < PayloadFieldSchema > ) > {
106- self . payload_index_schema . read ( ) . one_unindexed_key ( filter)
107+ self . payload_index_schema
108+ . read ( )
109+ . one_unindexed_filter_key ( filter)
107110 }
111+
112+ pub fn one_unindexed_expression_key (
113+ & self ,
114+ expr : & ExpressionInternal ,
115+ ) -> Option < ( JsonPath , Vec < PayloadFieldSchema > ) > {
116+ self . payload_index_schema
117+ . read ( )
118+ . one_unindexed_expression_key ( expr)
119+ }
120+ }
121+
122+ enum PotentiallyUnindexed < ' a > {
123+ Filter ( & ' a Filter ) ,
124+ Expression ( & ' a ExpressionInternal ) ,
108125}
109126
110127impl PayloadIndexSchema {
111128 /// Returns an arbitrary payload key with acceptable schemas
112129 /// used by `filter` which can be indexed but currently is not.
113130 /// If this function returns `None` all indexable keys in `filter` are indexed.
114- pub fn one_unindexed_key (
131+ fn one_unindexed_key (
115132 & self ,
116- filter : & Filter ,
133+ suspect : PotentiallyUnindexed < ' _ > ,
117134 ) -> Option < ( JsonPath , Vec < PayloadFieldSchema > ) > {
118135 let mut extractor = unindexed_field:: Extractor :: new ( & self . schema ) ;
119136
120- extractor. update_from_filter_once ( None , filter) ;
137+ match suspect {
138+ PotentiallyUnindexed :: Filter ( filter) => {
139+ extractor. update_from_filter_once ( None , filter) ;
140+ }
141+ PotentiallyUnindexed :: Expression ( expression) => {
142+ extractor. update_from_expression ( expression) ;
143+ }
144+ }
121145
122146 // Get the first unindexed field from the extractor.
123147 extractor
@@ -126,4 +150,21 @@ impl PayloadIndexSchema {
126150 . next ( )
127151 . map ( |( key, schema) | ( key. clone ( ) , schema. clone ( ) ) )
128152 }
153+
154+ /// Returns an arbitrary payload key with acceptable schemas
155+ /// used by `filter` which can be indexed but currently is not.
156+ /// If this function returns `None` all indexable keys in `filter` are indexed.
157+ pub fn one_unindexed_filter_key (
158+ & self ,
159+ filter : & Filter ,
160+ ) -> Option < ( JsonPath , Vec < PayloadFieldSchema > ) > {
161+ self . one_unindexed_key ( PotentiallyUnindexed :: Filter ( filter) )
162+ }
163+
164+ pub fn one_unindexed_expression_key (
165+ & self ,
166+ expr : & ExpressionInternal ,
167+ ) -> Option < ( JsonPath , Vec < PayloadFieldSchema > ) > {
168+ self . one_unindexed_key ( PotentiallyUnindexed :: Expression ( expr) )
169+ }
129170}
0 commit comments