sinequa / sba-angular

Sinequa's Angular-based Search Based Application (SBA) Framework
https://sinequa.github.io/sba-angular/
MIT License
30 stars 23 forks source link

Remove a specific field on new suggest strategy #114

Closed Guillaume-Developer closed 9 months ago

Guillaume-Developer commented 9 months ago

I am currently implementing the newest version of the SBA for a customer, and I am having troubles with the new strategy for the autocomplete.

When using the autocomplete, if no suggestions are returned, a new suggestion query is sent using only the last word. This works fine, but it then returns suggestions for the last word in all fields of my suggestions service, including the Title field. The Title field is not really a good fit for this kind of autocompletion, and I would like to remove it from my suggestion results, but I couldn't find a way to do that.

I have tried the following changes in the get(suggestQuery: string | undefined, text: string, fields?: string | string[], query?: Query, maxCount = 10) of the suggestions.service.ts but none of them worked.

Add a filter() on the suggests results

else {
  // Fall back to a strategy of autocompleting only the last token
  const i = text.lastIndexOf(" ")+1;
  if(i > 0) {
    const prefix = text.substring(0, i);
    return this.suggestQueryWebService.get(sugQuery, text.substring(i), ccquery).pipe(
      tap(suggests => suggests?.filter(suggest => suggest.category.toLowerCase() !== "title").forEach(s => s.display = prefix + s.display))
    );
  }
}

Add the kinds parameter when fetching the suggestions

else {
  // Fall back to a strategy of autocompleting only the last token
  const i = text.lastIndexOf(" ")+1;
  if(i > 0) {
    const prefix = text.substring(0, i);
    return this.suggestQueryWebService.get(sugQuery, text.substring(i), ccquery, "concepts").pipe(
      tap(suggests => suggests?.forEach(s => s.display = prefix + s.display))
    );
  }
}
ericleib commented 9 months ago

Hi Guillaume, Not sure why the second approach doesn't work, but for the first approach, you can replace tap() with a map() (and the forEach() also needs to be replaced):

return this.suggestQueryWebService.get(sugQuery, text.substring(i), ccquery).pipe(
      map(suggests => suggests?.filter(suggest => suggest.category.toLowerCase() !== "title").map(s => ({...s, display: prefix + s.display})))
    );
Guillaume-Developer commented 9 months ago

Hi Eric, map() instead of tap() did the trick. Thank you.

Not sure why the second approach doesn't work either though. I did set the kinds in my Suggestion Lexicon and I do see the kinds parameter being sent correctly as a parameter in the network tab.