Skip to content

Commit

Permalink
Search: Help link to ElasticSearch docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed Feb 8, 2024
1 parent 284f007 commit 984e201
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 38 deletions.
14 changes: 12 additions & 2 deletions catalog/app/containers/NavBar/Provider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { useHistory, useLocation, useRouteMatch } from 'react-router-dom'
import * as M from '@material-ui/core'

import * as SearchUIModel from 'containers/Search/model'
import * as BucketConfig from 'utils/BucketConfig'
Expand All @@ -26,9 +27,15 @@ function useSearchUIModel() {
return React.useContext(SearchUIModel.Context)
}

interface InputState extends M.InputBaseProps {
expanded: boolean
focusTrigger: number
helpOpen: boolean
push: (str: string) => void
}

interface SearchState {
// input: SearchInputProps
input: $TSFixMe
input: InputState
onClickAway: () => void
reset: () => void
suggestions: ReturnType<typeof Suggestions.use>
Expand Down Expand Up @@ -125,6 +132,8 @@ function useSearchState(bucket?: string): SearchState {
if (expanded || helpOpen) handleCollapse()
}, [expanded, helpOpen, handleCollapse])

const push = React.useCallback((str: string) => change(`${value} ${str}`), [value])

Check warning on line 135 in catalog/app/containers/NavBar/Provider.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Provider.tsx#L135

Added line #L135 was not covered by tests

const reset = React.useCallback(() => {
change('')
// NOTE: wait for location change (making help closed),
Expand All @@ -143,6 +152,7 @@ function useSearchState(bucket?: string): SearchState {
onChange,
onFocus: handleExpand,
onKeyDown,
push,
value: value === null ? query : value,
},
reset,
Expand Down
4 changes: 2 additions & 2 deletions catalog/app/containers/NavBar/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ function Search(props: SearchProps) {
const navbarState = useNavBar()
if (!navbarState) return <SearchNotAvailable />
const {
input: { helpOpen, ...input },
input: { helpOpen, push, ...input },

Check warning on line 153 in catalog/app/containers/NavBar/Search.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Search.tsx#L153

Added line #L153 was not covered by tests
onClickAway,
} = navbarState

return (
<Container onClickAway={onClickAway}>
<Suggestions classes={helpClasses} open={helpOpen} />
<Suggestions classes={helpClasses} open={helpOpen} onClick={push} />
<SearchInput placeholder="Search" {...input} {...props} />
</Container>
)
Expand Down
45 changes: 43 additions & 2 deletions catalog/app/containers/NavBar/Suggestions/Suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { Link } from 'react-router-dom'
import * as M from '@material-ui/core'

import * as style from 'constants/style'
import { docs } from 'constants/urls'
import StyledLink from 'utils/StyledLink'

Check warning on line 7 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L6-L7

Added lines #L6 - L7 were not covered by tests

import { useNavBar } from '../Provider'
import type { Suggestion } from './model'

const ES_V = '6.7'

Check warning on line 12 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L12

Added line #L12 was not covered by tests

const displaySuggestion = (s: Suggestion) => (
<>
Search {s.what} {s.where}
Expand All @@ -17,15 +21,27 @@ const useSuggestionsStyles = M.makeStyles((t) => ({
item: {
paddingLeft: t.spacing(5.5),
},
help: {
...t.typography.caption,
borderTop: `1px solid ${t.palette.divider}`,
marginTop: t.spacing(1),
padding: t.spacing(1, 5.5, 0.5),
},
helpExample: {
borderBottom: `1px dotted ${t.palette.text.primary}`,
cursor: 'help',
},
}))

interface SuggestionsProps {
items: Suggestion[]
selected: number
onClick: (help: string) => void
}

function SuggestionsList({ items, selected }: SuggestionsProps) {
function SuggestionsList({ onClick, items, selected }: SuggestionsProps) {

Check warning on line 42 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L42

Added line #L42 was not covered by tests
const classes = useSuggestionsStyles()
const examples = { and: 'termA AND termB', regex: '/lmnb[12]/' }

Check warning on line 44 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L44

Added line #L44 was not covered by tests
return (
<M.List>
{items.map((item, index) => (
Expand All @@ -40,6 +56,29 @@ function SuggestionsList({ items, selected }: SuggestionsProps) {
<M.ListItemText primary={displaySuggestion(item)} />
</M.MenuItem>
))}
<div className={classes.help}>
Quilt uses ElasticSearch {ES_V} query string queries. For example, you can use{' '}
<span
className={classes.helpExample}
onClick={() => onClick(examples.and)}

Check warning on line 63 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L63

Added line #L63 was not covered by tests
title={`e.g., "${examples.and}"`}
>
logical operators
</span>{' '}
and{' '}
<span
className={classes.helpExample}
onClick={() => onClick(examples.regex)}

Check warning on line 71 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L71

Added line #L71 was not covered by tests
title={`e.g., "${examples.regex}"`}
>
regular expressions
</span>
.{' '}
<StyledLink href={`${docs}/catalog/searchquery#search-bar`} target="_blank">
Learn more
</StyledLink>
.
</div>
</M.List>
)
}
Expand Down Expand Up @@ -71,11 +110,13 @@ interface SuggestionsContainerProps {
contents?: string
}
open: boolean
onClick: (help: string) => void
}

export default function SuggestionsContainer({
classes,
open,
onClick,

Check warning on line 119 in catalog/app/containers/NavBar/Suggestions/Suggestions.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/NavBar/Suggestions/Suggestions.tsx#L119

Added line #L119 was not covered by tests
}: SuggestionsContainerProps) {
const navbarModel = useNavBar()
if (!navbarModel) return null
Expand All @@ -85,7 +126,7 @@ export default function SuggestionsContainer({
if (!Array.isArray(items) || !items.length) return null
return (
<PaperWrapper classes={classes} open={open}>
{open && <SuggestionsList items={items} selected={selected} />}
{open && <SuggestionsList items={items} selected={selected} onClick={onClick} />}
</PaperWrapper>
)
}
25 changes: 21 additions & 4 deletions catalog/app/containers/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as FiltersUI from 'components/Filters'
import Layout from 'components/Layout'
import * as SearchResults from 'components/SearchResults'
import Skeleton from 'components/Skeleton'
import { docs } from 'constants/urls'

Check warning on line 10 in catalog/app/containers/Search/Search.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Search/Search.tsx#L10

Added line #L10 was not covered by tests
import * as GQL from 'utils/GraphQL'
import * as JSONPointer from 'utils/JSONPointer'
import MetaTitle from 'utils/MetaTitle'
Expand All @@ -20,6 +21,8 @@ import ResultTypeSelector from './ResultType'
import { EmptyResults, ResultsSkeleton } from './Results'
import SortSelector from './Sort'

const ES_V = '6.7'

Check warning on line 24 in catalog/app/containers/Search/Search.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Search/Search.tsx#L24

Added line #L24 was not covered by tests

function useMobileView() {
const t = M.useTheme()
return M.useMediaQuery(t.breakpoints.down('sm'))
Expand Down Expand Up @@ -256,13 +259,20 @@ function KeywordWildcardFilterWidget({
},
[onChange, state],
)
// TODO: link to docs:
// https://www.elastic.co/guide/en/elasticsearch/reference/6.7/query-dsl-wildcard-query.html
return (
<FiltersUI.TextField
onChange={handleChange}
placeholder="Match against (wildcards supported)"
value={state.wildcard}
helperText={
<>
Quilt uses ElasticSearch {ES_V}.{' '}
<StyledLink href={`${docs}/catalog/searchquery#search-bar`} target="_blank">
Learn more
</StyledLink>
.
</>
}
/>
)
}
Expand All @@ -277,13 +287,20 @@ function TextFilterWidget({
},
[onChange, state],
)
// TODO: link to docs:
// https://www.elastic.co/guide/en/elasticsearch/reference/6.7/query-dsl-simple-query-string-query.html
return (
<FiltersUI.TextField
onChange={handleChange}
placeholder="Search for"
value={state.queryString}
helperText={
<>
Quilt uses ElasticSearch {ES_V}.{' '}
<StyledLink href={`${docs}/catalog/searchquery#search-bar`} target="_blank">
Learn more
</StyledLink>
.
</>
}
/>
)
}
Expand Down
58 changes: 30 additions & 28 deletions docs/Catalog/SearchQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ to deep index can be customized per Bucket in the Catalog Admin settings.

![Example of Admin Bucket indexing options](../imgs/elastic-search-indexing-options.png)

### Navigation Bar
### Search Bar

The navigation bar on every page in the catalog provides a convenient
The search bar on every page in the catalog provides a convenient
shortcut for searching objects and packages in an Amazon S3
bucket.

Expand All @@ -47,38 +47,40 @@ The following are all valid search parameters:

**Fields**

- `comment`: Package comment. `comment: TODO`
- `content`: Object content. `content:Hello`
- `ext`: Object extension. `ext:*.fastq.gz`
- `handle`: Package name. `handle:examples\/metadata`
- `hash`: Package hash. `hash:3192ac1*`
- `key`: Object key. `key:phase*`
- `key_text`: Analyzed object key. `key:"phase"`
- `last_modified`: Last modified date. `last_modified:[2022-02-04 TO
2022-02-20]`
- `metadata`: Package metadata. `metadata:dapi`
- `size`: Object size in bytes. `size:>=4096`
- `version_id`: Object version id. `version_id:t.LVVCx*`
- `pointer_file`: Package revision tag in S3; either "latest" or a top hash. `pointer_file: latest`
- `package_stats.total_files`: Package total files.
`package_stats.total_files:>100`
- `package_stats.total_bytes`: Package total bytes.
`package_stats.total_bytes:<100`
| Keyword | Description | Example |
|- | - | - |
| `comment`| Package comment | `comment:TODO` |
| `content`| Object content | `content:Hello` |
| `ext`| Object extension | `ext:*.fastq.gz` |
| `handle`| Package name | `handle:examples\/metadata` |
| `hash`| Package hash | `hash:3192ac1*` |
| `key`| Object key | `key:phase*` |
| `key_text`| Analyzed object key | `key:"phase"` |
| `last_modified`| Last modified date | `last_modified:[2022-02-04 TO 2022-02-20]`|
| `metadata` | Package metadata | `metadata:dapi` |
| `size` | Object size in bytes | `size:>=4096` |
| `version_id` | Object version id | `version_id:t.LVVCx*` |
| `pointer_file` | Package revision tag in S3; either "latest" or a top hash | `pointer_file:latest` |
| `package_stats.total_files` | Package total files | `package_stats.total_files:>100` |
| `package_stats.total_bytes` | Package total bytes | `package_stats.total_bytes:<100` |

**Logical operators and grouping**

- `AND`: Conjunction. `a AND b`
- `OR`: Disjunction. `a OR b`
- `NOT`: Negation. `NOT a`
- `_exists_`: Matches any non-null value for the given field. `_exists_: content`
- `()`: Group terms. `(a AND b) NOT c`
| Keyword | Description | Example |
|- | - | - |
| `AND` | Conjunction | `a AND b` |
| `OR` | Disjunction | `a OR b` |
| `NOT` | Negation | `NOT a` |
| `_exists_` | Matches any non-null value for the given field | `_exists_: content` |
| `()` | Group terms | `(a AND b) NOT c` |

**Wildcard and regular expressions**

- `*`: Zero or more characters, avoid leading `*` (slows performance).
`ext:config.y*ml`
- `?`: Exactly one character. `ext:React.?sx`
- `//`: Regular expression (slows performance). `content:/lmnb[12]/`
| Keyword | Description | Example |
|- | - | - |
| `*` | Zero or more characters, avoid leading `*` (slows performance) | `ext:config.y*ml` |
| `?` | Exactly one character | `ext:React.?sx` |
| `//` | Regular expression (slows performance) | `content:/lmnb[12]/` |

### QUERIES > ELASTICSEARCH tab

Expand Down

0 comments on commit 984e201

Please sign in to comment.