mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Require all terms when searching kinds
This commit is contained in:
parent
b50be1b27a
commit
1474a0ac02
2 changed files with 63 additions and 7 deletions
|
|
@ -258,8 +258,6 @@
|
|||
<script>
|
||||
import scrollIntoView from 'scroll-into-view-if-needed'
|
||||
|
||||
import { StorkFilters } from '~/helpers/stork/browser.js'
|
||||
|
||||
import {
|
||||
defaultStatusFilters,
|
||||
} from '~/helpers/statuses.js'
|
||||
|
|
@ -268,6 +266,7 @@ import {
|
|||
} from '~/helpers/app-derived.js'
|
||||
import {
|
||||
StorkClient,
|
||||
StorkFilters,
|
||||
makeHighlightedMarkup,
|
||||
makeHighlightedResultTitle
|
||||
} from '~/helpers/stork/browser.js'
|
||||
|
|
@ -447,7 +446,9 @@ export default {
|
|||
|
||||
// console.log('rawQuery', rawQuery)
|
||||
|
||||
const storkQuery = await storkClient.lazyQuery( this.storkQuery )
|
||||
const requiredTerms = this.storkQuery.split(' ')
|
||||
|
||||
const storkQuery = await storkClient.lazyQuery( this.storkQuery, requiredTerms )
|
||||
|
||||
// If the query response is empty
|
||||
// then return
|
||||
|
|
@ -455,6 +456,8 @@ export default {
|
|||
return
|
||||
}
|
||||
|
||||
// console.log( 'storkQuery', storkQuery )
|
||||
|
||||
this.listingsResults = storkQuery.results.map( result => {
|
||||
return {
|
||||
name: makeHighlightedResultTitle( result ),
|
||||
|
|
|
|||
|
|
@ -87,6 +87,42 @@ export class StorkClient {
|
|||
return this.setupState === 'complete'
|
||||
}
|
||||
|
||||
resultHasTerm ( result, term ) {
|
||||
const {
|
||||
entry: {
|
||||
url,
|
||||
title
|
||||
},
|
||||
excerpts
|
||||
} = result
|
||||
|
||||
if ( title.toLowerCase().includes( term.toLowerCase() ) ) return true
|
||||
|
||||
if ( url.toLowerCase().includes( term.toLowerCase() ) ) return true
|
||||
|
||||
for ( const excerpt of excerpts ) {
|
||||
if ( excerpt.text.toLowerCase().includes( term.toLowerCase() ) ) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
resultHasAnyTerm ( result, terms ) {
|
||||
for ( const term of terms ) {
|
||||
if ( this.resultHasTerm( result, term ) ) return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
resultHasAllTerms ( result, terms ) {
|
||||
for ( const term of terms ) {
|
||||
if ( !this.resultHasTerm( result, term ) ) return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
search ( query ) {
|
||||
if ( !this.isSetup ) throw new Error('Not setup')
|
||||
|
||||
|
|
@ -96,7 +132,7 @@ export class StorkClient {
|
|||
|
||||
// Loads the Stork WASM and Index into the browser on first query
|
||||
// so that we don't have to load them initially.
|
||||
async lazyQuery ( query ) {
|
||||
async lazyQuery ( query, requiredTerms = [] ) {
|
||||
|
||||
// Sleep
|
||||
// await new Promise( resolve => setTimeout( resolve, 50000000 ) )
|
||||
|
|
@ -118,11 +154,24 @@ export class StorkClient {
|
|||
|
||||
// console.log('debounce', this.query)
|
||||
|
||||
const result = this.search( query )
|
||||
const queryResponse = this.search( query )
|
||||
|
||||
// this.cancelCurrentQuery = null
|
||||
if ( requiredTerms.length !== 0 ) {
|
||||
// Filter out results that don't have the required terms
|
||||
const filteredResults = queryResponse.results.filter( result => {
|
||||
return this.resultHasAllTerms( result, requiredTerms )
|
||||
})
|
||||
|
||||
resolve( result )
|
||||
|
||||
resolve( {
|
||||
...queryResponse,
|
||||
results: filteredResults
|
||||
} )
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
resolve( queryResponse )
|
||||
|
||||
}).catch( err => {
|
||||
console.log('Query rejected', err)
|
||||
|
|
@ -248,6 +297,10 @@ export class StorkFilters {
|
|||
return this.list.join(' ')
|
||||
}
|
||||
|
||||
getByKey ( key ) {
|
||||
return `${ key }${ filterSeparator }${ this.filters[ key ] }`
|
||||
}
|
||||
|
||||
isQueryValue ( filterNameOrQueryValue ) {
|
||||
return filterNameOrQueryValue.includes( filterSeparator )
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue