Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dots in keywords when searching on exact words #203

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/soft-coins-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'contexture-react': patch
---

Allow dots in keywords tags

It is very common for users to search for keywords with dots in them when matching on exact words
10 changes: 9 additions & 1 deletion packages/react/src/exampleTypes/ExpandableTagsQuery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import ActionsMenu from '../TagsQuery/ActionsMenu.js'
import { useOutsideClick } from '@chakra-ui/react-use-outside-click'
import { sanitizeTagInputs } from 'contexture-elasticsearch/utils/keywordGenerations.js'
import KeywordGenerations from './KeywordGenerations.js'
import {
alphaNumericRegEx,
alphaNumericRegExWithDots,
} from '../../greyVest/utils.js'

let innerHeightLimit = 40

Expand Down Expand Up @@ -132,7 +136,11 @@ let TagsWrapper = observer(
popoverOffsetY,
theme: { Icon, TagsInput, Tag, Popover },
joinOptions,
wordsMatchPattern,
// Allow tag keywords to contain dots in them if the user is searching for exact
// words instead of their variations.
wordsMatchPattern = node.exact
? alphaNumericRegExWithDots
: alphaNumericRegEx,
Copy link
Member

@dubiousdavid dubiousdavid Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we not always use alphaNumericRegExWithDots? Also, why are the regexs so strange looking?

Copy link
Member Author

@stellarhoof stellarhoof Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that's we had agreed on, that if you didn't search for exact you'd get the current behavior?

I think they are strange looking because they were copied from lodash. See this comment

sanitizeTags = true,
splitCommas = true,
maxTags = 1000,
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/greyVest/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ export let splitTagOnComma = _.flow(
export let alphaNumericRegEx =
// eslint-disable-next-line no-control-regex
/[^\x00-\x2C\x2E-\x2F\x3a-\x40\x5b-\x60\x7b-\x7f]+/g

// Same as above but allowing dots
export let alphaNumericRegExWithDots =
// eslint-disable-next-line no-control-regex
/[^\x00-\x2C\x2F\x3a-\x40\x5b-\x60\x7b-\x7f]+/g
Loading