MCPcopy
hub / github.com/perkeep/perkeep / addContinueConstraint

Method addContinueConstraint

pkg/search/query.go:196–234  ·  view source on GitHub ↗

addContinueConstraint conditionally modifies q.Constraint to scroll past the results as indicated by q.Continue.

()

Source from the content-addressed store, hash-verified

194// addContinueConstraint conditionally modifies q.Constraint to scroll
195// past the results as indicated by q.Continue.
196func (q *SearchQuery) addContinueConstraint() error {
197 cont := q.Continue
198 if cont == "" {
199 return nil
200 }
201 if q.Constraint.onlyMatchesPermanode() {
202 tokent, lastbr, ok := parsePermanodeContinueToken(cont)
203 if !ok {
204 return errors.New("Unexpected continue token")
205 }
206 if q.Sort == LastModifiedDesc || q.Sort == CreatedDesc {
207 var lastMod, lastCreated time.Time
208 switch q.Sort {
209 case LastModifiedDesc:
210 lastMod = tokent
211 case CreatedDesc:
212 lastCreated = tokent
213 }
214 baseConstraint := q.Constraint
215 q.Constraint = &Constraint{
216 Logical: &LogicalConstraint{
217 Op: "and",
218 A: &Constraint{
219 Permanode: &PermanodeConstraint{
220 Continue: &PermanodeContinueConstraint{
221 LastCreated: lastCreated,
222 LastMod: lastMod,
223 Last: lastbr,
224 },
225 },
226 },
227 B: baseConstraint,
228 },
229 }
230 }
231 return nil
232 }
233 return errors.New("token not valid for query type")
234}
235
236func (q *SearchQuery) checkValid(ctx context.Context) (sq *SearchQuery, err error) {
237 if q.Sort >= maxSortType || q.Sort < 0 {

Callers 1

plannedQueryMethod · 0.80

Calls 2

onlyMatchesPermanodeMethod · 0.80

Tested by

no test coverage detected