Skip to content

Commit 1d3197e

Browse files
do you mean - showing values only for words not in suggestions
1 parent 36bf382 commit 1d3197e

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/AutoSuggest.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ const renderData = data => {
4242

4343
const renderDataNew = data => {
4444
var listOfSuggestions = [],
45-
firstResponseValue = []
45+
responseSuggestions = []
4646
// const maxScore = data.hits.max_score
4747
data.hits.hits.map ((value, index) => {
4848
listOfSuggestions.push(`${value._source.tags} (score -- ${value._score.toFixed(2)})`)
49-
if (index === 0 || index === 1 || index === 2) { firstResponseValue.push(value._source.tags)} // for do you mean
49+
responseSuggestions.push(value._source.tags) // for do you mean
5050
})
51-
return [listOfSuggestions, firstResponseValue]
51+
return [listOfSuggestions, responseSuggestions]
5252
}
5353

5454
class AutoSuggest extends React.Component {
@@ -60,7 +60,7 @@ class AutoSuggest extends React.Component {
6060
showResults: false,
6161
searchResult: [],
6262
searchValue: '',
63-
firstResponseValue: []
63+
responseSuggestions: []
6464
};
6565
}
6666

@@ -87,7 +87,7 @@ class AutoSuggest extends React.Component {
8787
if (data !== undefined) {
8888
this.setState({
8989
suggestions: data[0],
90-
firstResponseValue: data[1]
90+
responseSuggestions: data[1]
9191
})
9292
}
9393
})
@@ -140,8 +140,8 @@ class AutoSuggest extends React.Component {
140140
}
141141

142142
render() {
143-
const { value, suggestions, searchValue, firstResponseValue } = this.state;
144-
// console.log(value, suggestions)
143+
const { value, suggestions, searchValue, responseSuggestions } = this.state;
144+
// console.log(value, responseSuggestions, responseSuggestions.includes(value))
145145
// Autosuggest will pass through all these props to the input.
146146
const inputProps = {
147147
placeholder: 'Search ...',
@@ -169,7 +169,7 @@ class AutoSuggest extends React.Component {
169169
this.state.showResults
170170
? <ListIndex searchResult={this.state.searchResult}
171171
searchValue={value}
172-
firstResponseValue={firstResponseValue}
172+
responseSuggestions={responseSuggestions}
173173
searchSuggestedValue = {this.searchSuggestedValue}
174174
/>
175175
: null

src/ListIndex.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,23 @@ class ListIndex extends Component {
5757
}
5858

5959
render() {
60-
const {searchResult, searchValue, firstResponseValue} = this.props
61-
const responseLength = firstResponseValue.length - 1
60+
const {searchResult, searchValue, responseSuggestions} = this.props
61+
const responseLength = responseSuggestions.length - 1
6262

6363
return (
6464
<Fragment>
6565
{
6666
!this.state.showDescription
6767
? <div style={{padding:'2px 10px', margin:'1% 10%'}}>
6868
{
69-
searchValue !== firstResponseValue[0] && firstResponseValue.length > 0
69+
!responseSuggestions.includes(searchValue) && responseSuggestions.length > 0
7070
? <div style={{margin: '0 auto', width: '40vw'}}>
7171
<span style={{color: 'red', fontSize:'1.3em'}}>Did you mean:{' '}</span>
7272
{
73-
firstResponseValue.map((value, index) => (
74-
<span key={index}>
75-
<a href='#' onClick={this.sendSuggestedValue}
76-
style={{color: "blue"}}>
77-
{value}
78-
</a>
79-
{index !== responseLength ? ', ' : ''}
80-
</span>
81-
))
73+
<a href='#' onClick={this.sendSuggestedValue}
74+
style={{color: "blue"}}>
75+
{responseSuggestions[0]}
76+
</a>
8277
}
8378
</div>
8479
: null

0 commit comments

Comments
 (0)