reactivesearch: Autocomplete dropdown shows inconsistent results in `DataSearch` component
Affected Projects React Web
Library Version:
3.0.0-alpha.3
Describe the bug
I use customQuery
in a DataSearch
component. When I type a query in the search box I see 2 issues,
- The query generated by autocomplete (the one that shows instance results as a drop down list form the search box) is the stock query that is fired as if there was no
customQuery
being specified. This results in a disparity in results shown in the connectedReactiveList
because I wantcross_fields
while searching, which is not present in stock query for data search component. - Even though there are results for a query in the autocomplete they are not being rendered. I found this out when I was wanted to customize what info was shown in the autocomplete using
parseSuggestion
. Here I printed thesuggestion
on console & I also monitor the query & response from server. I do not see the results as I would expect. Note that this does not happen all the time.
To Reproduce Steps to reproduce the behavior:
- Basically specify a
customQuery
onDataSearch
& see the query fired when you are typing in the search box versus when you finally hit the enter which then renders theReactiveList
- Again you need to monitor the
parseSuggestions
method & see what suggestions are being printed on the consiole versus what are actually shown in the autocomplete section.
Expected behavior
- Use the same query as
customQuery
specified - Render all the suggestions/results form the query.
Screenshots
Desktop (please complete the following information):
- OS: MacOS
- Browser: Brave/Chrome
Additional context
My DataSearch
component invocation,
<DataSearch
componentId="nameReactor"
placeholder="Search for Name, Address, Phone, Email"
dataField={['full_name', 'address', 'primary_email', 'primary_cell_phone']}
fieldWeights={[10, 8, 6, 4]}
searchInputId="universal-search"
filterLabel="Search"
iconPosition="right"
autosuggest={true}
fuzziness="AUTO"
showClear={true}
customQuery={
function(value, props) {
if (!value || !props) {
return;
}
let fields = [];
let currentDataField = props.dataField || [];
let currentFieldWeights = props.fieldWeights || [];
currentDataField.forEach(function(currentField, index) {
let currentFieldWeight = currentField;
if (index < currentFieldWeights.length) {
currentFieldWeight += "^" + currentFieldWeights[index];
}
fields.push(currentFieldWeight);
});
const multiMatchTypes = ["best_fields", "cross_fields", "phrase_prefix"];
const fuzzinessCapableTypes = ["best_fields"];
let multiMatchDefinitions = [];
multiMatchTypes.forEach(function(currentMultiMatchType) {
let currentDefinition = {
"query": value,
"fields": fields,
"type": currentMultiMatchType,
"operator": "or"
};
if (props.fuzziness) {
if (fuzzinessCapableTypes.includes(currentMultiMatchType)) {
currentDefinition["fuzziness"] = props.fuzziness;
}
}
multiMatchDefinitions.push({
"multi_match": currentDefinition
})});
return {
"query": {
"bool": {
"should": multiMatchDefinitions,
"minimum_should_match": "1"
}
}
}
}
}
parseSuggestion={
function(suggestion) {
if (!suggestion || suggestion === undefined) {
return;
}
console.log("suggestion:", suggestion)
return {
label: (
<div>
{suggestion.source.first_name} {suggestion.source.middle_name} {suggestion.source.last_name}
| {suggestion.source.address_line_1}
<span style={{ color: 'dodgerblue', marginLeft: 5 }}>
{suggestion.source.zone}
</span>
</div>
),
value: suggestion.value,
source: suggestion.source // for onValueSelected to work with parseSuggestion
}
}
}
renderError={error => (
<div>
Something went wrong with DataSearch
<br />
Error details
<br />
{error}
</div>
)}
renderNoSuggestion={() => (
<div>
No suggestions found
</div>
)
}
/>
I also keep on seeing the below error when I load the page,
index.js:1375 Warning: Failed prop type: Invalid prop `show` of type `boolean` supplied to `PoweredBy`, expected `number`.
in PoweredBy (created by ReactiveList)
in ReactiveList
in Unknown (created by Context.Consumer)
in Connect(Component) (created by ForwardRef)
in ForwardRef (at App.js:348)
in div (at App.js:346)
in div (at App.js:227)
in div
in Unknown (created by Styled(Component))
in Styled(Component) (created by URLParamsProvider)
in URLParamsProvider
in Unknown (created by Context.Consumer)
in Connect(Component) (created by ForwardRef)
in ForwardRef (created by ReactiveBase)
in Provider (created by ReactiveBase)
in ThemeProvider (created by ReactiveBase)
in ReactiveBase (at App.js:78)
in div (at App.js:77)
in App (at src/index.js:7)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (9 by maintainers)
Commits related to this issue
- fix: showDistinctSuggestion prop in suggestions parsing #1148 — committed to appbaseio/reactivesearch by bietkul 3 years ago
The second solution will work for you now, use
rawData
instead ofdata
. Please check the docs ofrender
prop here.We can have a new prop in the search components to disable this behavior, currently, we parse the suggestions which may lead to duplicates if someone customizes the
label
key. For now, the only solution is to use custom renderer.showDistinctSuggestions is not returning 1 suggestion per document. Could you please fix it? At least on react side of it.