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 f6c4655
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
28 changes: 21 additions & 7 deletions 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: query,
},
},
]
},
})

export const Search = () => {
const { serverUrl, aapb_host }: SearchProps = useLoaderData()
Expand All @@ -58,12 +70,13 @@ export const Search = () => {
<SearchBox
autoFocus
placeholder="Search exhibits, collections, and Series from GBH"
// queryHook={(query, search) => {
// // console.log('searchbox', search)
// // debounce the search input box
// clearTimeout(timerId)
// timerId = setTimeout(() => search(query), timeout)
// }}
queryHook={(query, search) => {
// console.log('searchbox', search)
// debounce the search input box

clearTimeout(timerId)
timerId = setTimeout(() => search(query), timeout)
}}
className="search-box"
/>
<Error />
Expand All @@ -79,6 +92,7 @@ export const Search = () => {
</Tabs>
{activeTab === 0 && (
<Index indexName="wagtail__wagtailcore_page">
{/* <Configure removeStopWords={true} advancedSyntax={true} /> */}
<NoResultsBoundary fallback={<NoResults />}>
<h2>Open Vault results</h2>
<Refinements />
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 f6c4655

Please sign in to comment.