Skip to content

Commit

Permalink
Enables advanced query syntax: "", +, -, AND, OR, NOT, ( )
Browse files Browse the repository at this point in the history
  • Loading branch information
mrharpo committed Oct 30, 2024
1 parent 60ebb3a commit dd91a09
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 14 additions & 1 deletion app/classes/search-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Index,
Pagination,
HitsPerPage,
Configure,
} from 'react-instantsearch'
import {
Error,
Expand All @@ -31,7 +32,18 @@ import { useLoaderData, useRouteError } from '@remix-run/react'

const sk = new Searchkit(searchkit_options)

export const searchClient = Client(sk)
export const searchClient = Client(sk, {
getQuery: (query, search_attributes) => {
console.log('search query', query, search_attributes)
return [
{
query_string: {
query,
},
},
]
},
})

export const Search = () => {
const { serverUrl, aapb_host }: SearchProps = useLoaderData()
Expand Down Expand Up @@ -61,6 +73,7 @@ export const Search = () => {
// queryHook={(query, search) => {
// // console.log('searchbox', search)
// // debounce the search input box

// clearTimeout(timerId)
// timerId = setTimeout(() => search(query), timeout)
// }}
Expand Down
13 changes: 11 additions & 2 deletions app/components/AAPBResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { useInstantSearch } from 'react-instantsearch'
import debounce from 'lodash/debounce'
import { Spinner } from './Spinner'

const gbh_query =
'+(contributing_organizations:%20WGBH(MA)%20OR%20producing_organizations:%20WGBH%20Educational%20Foundation)&'

export const AAPBResults = ({ aapb_host }) => {
const { indexUiState } = useInstantSearch()

Expand All @@ -13,7 +16,9 @@ export const AAPBResults = ({ aapb_host }) => {
debounce(currentQuery => {
console.log('fetching AAPB results for', currentQuery)
fetch(
`${aapb_host}/api.json?q=${encodeURIComponent(currentQuery)}&rows=0`
`${aapb_host}/api.json?q=${encodeURIComponent(
currentQuery
)}${gbh_query}&rows=0`
)
.then(response => response.json())
.then(data => setResults(data.response.numFound))
Expand All @@ -30,7 +35,11 @@ export const AAPBResults = ({ aapb_host }) => {
}, [fetchResults, indexUiState])

return (
<a href={`${aapb_host}/catalog?q=${indexUiState.query}`} target="_blank">
<a
href={`${aapb_host}/catalog?q=${indexUiState.query}${gbh_query}`}
target="_blank"
>
View
<span className="ais-RefinementList-count">
{result_count || <Spinner />}
</span>
Expand Down

0 comments on commit dd91a09

Please sign in to comment.