
class QueryBuilder {
    constructor() {
        this.content = []
        this.timestamp = []
        this.offset = null;
        this.pageSize = null;
    }

    _setDate = field => time => {
        const current = this.timestamp.length ? this.timestamp[0] : {}
        const updated = [{ ...current, [field]: String(time) }]

        // Search index needs defaults if they're missing
        if (!updated[0].gte) updated[0].gte = '0'
        if (!updated[0].lte) updated[0].lte = String(Date.now())

        this.timestamp = updated
        return this
    }

    get = () => {
        const query = {
            query: {
                AND: { content: this.content, timestamp: this.timestamp },
            },
        }

        if (this.offset) query.offset = this.offset
        if (this.pageSize) query.pageSize = this.pageSize

        return query
    }

    skipUntil = skip => {
        this.offset = skip
        return this
    }

    limit = limit => {
        this.pageSize = limit
        return this
    }

    searchTerm = term => {
        if (term) this.content.push(term)
        return this
    }

    startDate = this._setDate('gte')
    endDate = this._setDate('lte')
}

export default QueryBuilder

@@ -74,25 +74,67 @@
    this.
-t
+bookmarkTimestamps = %5B%5D%0A        this.visitT
 imestamp
  = %5B%5D%0A  
@@ -125,16 +125,17 @@
 imestamp
+s
  = %5B%5D%0A  
@@ -154,25 +154,24 @@
 ffset = null
-;
 %0A        thi
@@ -191,9 +191,8 @@
 null
-;
 %0A   
@@ -203,76 +203,445 @@
     
-_setDate = field =%3E time =%3E %7B%0A        const current = this.timestamp
+/**%0A     * Sets up the query on time-based fields. Currently mirrors for both, as%0A     * our current search does not differentiate between visits and bookmarks.%0A     */%0A    _setDate = op =%3E time =%3E %7B%0A        // Don't add anything if the time isn't given%0A        if (!time) %7B return this %7D%0A        const currentBookmarks = this.bookmarkTimestamps.length ? this.bookmarkTimestamps%5B0%5D : %7B%7D%0A        const currentVisits = this.visitTimestamps
 .len
@@ -651,25 +651,30 @@
  ? this.
-t
+visitT
 imestamp
 %5B0%5D : %7B%7D
@@ -665,16 +665,17 @@
 imestamp
+s
 %5B0%5D : %7B%7D
@@ -696,16 +696,25 @@
  updated
+Bookmarks
  = %5B%7B ..
@@ -725,31 +725,119 @@
 rent
-, %5Bfield%5D: String(
+Bookmarks, %5Bop%5D: %60bookmark/$%7Btime%7D%60 %7D%5D%0A        const updatedVisits = %5B%7B ...currentVisits, %5Bop%5D: %60visit/$%7B
 time
-)
+%7D%60
  %7D%5D%0A
@@ -852,15 +852,15 @@
  // 
-S
+s
 earch
- 
+-
 inde
@@ -911,24 +911,33 @@
 if (!updated
+Bookmarks
 %5B0%5D.gte) upd
@@ -936,24 +936,33 @@
 gte) updated
+Bookmarks
 %5B0%5D.gte = '0
@@ -960,17 +960,25 @@
 .gte = '
-0
+bookmark/
 '%0A      
@@ -987,24 +987,33 @@
 if (!updated
+Bookmarks
 %5B0%5D.lte) upd
@@ -1016,16 +1016,25 @@
  updated
+Bookmarks
 %5B0%5D.lte 
@@ -1039,15 +1039,167 @@
 e = 
-String(
+%60bookmark/$%7BDate.now()%7D%60%0A        if (!updatedVisits%5B0%5D.gte) updatedVisits%5B0%5D.gte = 'visit/'%0A        if (!updatedVisits%5B0%5D.lte) updatedVisits%5B0%5D.lte = %60visit/$%7B
 Date
@@ -1204,17 +1204,18 @@
 te.now()
-)
+%7D%60
 %0A%0A      
@@ -1216,30 +1216,122 @@
         
-this.t
+// Set updated query fields%0A        this.bookmarkTimestamps = updatedBookmarks%0A        this.visitT
 imestamp
  = updat
@@ -1322,16 +1322,17 @@
 imestamp
+s
  = updat
@@ -1333,16 +1333,22 @@
  updated
+Visits
 %0A       
@@ -1400,20 +1400,16 @@
  const q
-uery
  = %7B%0A   
@@ -1424,17 +1424,114 @@
  query: 
-%7B
+%5B%0A                %7B AND: %7B content: this.content, bookmarkTimestamps: this.bookmarkTimestamps %7D %7D,
 %0A       
@@ -1538,16 +1538,18 @@
         
+ %7B
  AND: %7B 
@@ -1571,25 +1571,30 @@
 ontent, 
-t
+visitT
 imestamp
 : this.t
@@ -1589,24 +1589,30 @@
 tamp
+s
 : this.
-t
+visitT
 imestamp
  %7D,%0A
@@ -1607,16 +1607,19 @@
 imestamp
+s %7D
  %7D,%0A    
@@ -1626,17 +1626,17 @@
         
-%7D
+%5D
 ,%0A      
@@ -1666,20 +1666,16 @@
 ffset) q
-uery
 .offset 
@@ -1716,20 +1716,16 @@
 eSize) q
-uery
 .pageSiz
@@ -1759,20 +1759,16 @@
 return q
-uery
 %0A    %7D%0A%0A

Update index QueryBuilder field handling