@@ -3,7 +3,7 @@ import Autosuggest from 'react-autosuggest';
3
3
import './AutoSuggest.css'
4
4
import ListIndex from './ListIndex'
5
5
import axios from 'axios'
6
- import { serverUrl , localUrl } from './url'
6
+ import { suggestionsUrl , searchUrl } from './url'
7
7
import { suggest } from './suggest'
8
8
9
9
// Imagine you have a list of languages that you'd like to autosuggest.
@@ -51,6 +51,7 @@ var suggestionJson = {
51
51
const getSuggestionOnSearch = value => {
52
52
const suggestion = { ...suggestionJson }
53
53
suggestion . query . match [ "tags.edgengram" ] = value
54
+ console . log ( suggestion )
54
55
return suggestion
55
56
}
56
57
@@ -66,11 +67,11 @@ const renderData = data => {
66
67
67
68
const renderDataNew = data => {
68
69
var listOfSuggestions = [ ] ,
69
- firstResponseValue = ''
70
+ firstResponseValue = [ ]
70
71
const maxScore = data . hits . max_score
71
72
data . hits . hits . map ( ( value , index ) => {
72
73
listOfSuggestions . push ( `${ value . _source . tags } (score -- ${ Math . round ( ( value . _score / maxScore ) * 100 ) } )` )
73
- if ( index === 0 ) { firstResponseValue = value . _source . tags } // for do you mean
74
+ if ( index === 0 || index === 1 || index === 2 ) { firstResponseValue . push ( value . _source . tags ) } // for do you mean
74
75
} )
75
76
return [ listOfSuggestions , firstResponseValue ]
76
77
}
@@ -90,7 +91,7 @@ class AutoSuggest extends React.Component {
90
91
showResults : false ,
91
92
searchResult : [ ] ,
92
93
searchValue : '' ,
93
- firstResponseValue : ''
94
+ firstResponseValue : [ ]
94
95
} ;
95
96
}
96
97
@@ -104,14 +105,15 @@ class AutoSuggest extends React.Component {
104
105
// You already implemented this logic above, so just use it.
105
106
onSuggestionsFetchRequested = ( { value } ) => {
106
107
this . setState ( { searchValue : value } )
107
- var suggestion = getSuggestionOnSearch ( value )
108
- // value.length >= 1 ? suggestion = getSuggestionOnSearch(value) : null
108
+ var suggestion = null // getSuggestionOnSearch(value)
109
+ value . length >= 1 ? suggestion = getSuggestionOnSearch ( value ) : null
109
110
if ( suggestion !== null ) {
110
- axios . post ( serverUrl , suggestionJson )
111
+ axios . post ( suggestionsUrl , suggestionJson )
111
112
. then ( ( response ) => {
112
- // console.log(response.data.suggest)
113
- // var data = renderData(response.data.suggest)
114
- var data = renderDataNew ( suggest )
113
+ console . log ( response . data )
114
+ if ( response . data . hits . length === 0 ) return
115
+ var data = renderDataNew ( response . data )
116
+ // var data = renderDataNew(suggest)
115
117
if ( data !== undefined ) {
116
118
this . setState ( {
117
119
suggestions : data [ 0 ] ,
@@ -134,25 +136,25 @@ class AutoSuggest extends React.Component {
134
136
// api call to get final suggestions
135
137
var searchQuery = {
136
138
"query" : {
137
- "multi_match" : {
138
- "query" : "plastic card ",
139
- "fields" : [ "ParameterValueForSearch.trigram" , "NodeName.keywordstring" , "NodeTitle.keywordstring "]
140
- }
141
- } ,
142
- "highlight" : {
143
- "fields" : {
144
- "ParameterValueForSearch" : { } ,
145
- "NodeName" : { } ,
146
- "NodeTitle " : { }
147
- }
148
- }
149
- }
139
+ "multi_match" : {
140
+ "query" :"movies ",
141
+ "fields" :[ "ParameterValueForSearch.ngram" , "NodeTitle.ngram" , "NodeName.ngram "]
142
+ }
143
+ } ,
144
+ "highlight" : {
145
+ "fields" : {
146
+ "ParameterValueForSearch.ngram " : { } ,
147
+ "NodeTitle.ngram" : { } ,
148
+ "NodeName.ngram " : { }
149
+ }
150
+ }
151
+ }
150
152
searchQuery . query . multi_match . query = this . state . value
151
153
// console.log(searchQuery)
152
- axios . post ( serverUrl , searchQuery )
154
+ axios . post ( searchUrl , searchQuery )
153
155
. then ( ( response ) => {
154
156
console . log ( response . data . hits )
155
- const searchResult = response . data . hits . hits
157
+ const searchResult = response . data
156
158
this . setState ( { searchResult, showResults : true } )
157
159
} )
158
160
event . preventDefault ( )
0 commit comments