"Semantic-UI Search" Custom lookout expression

224 views
Skip to first unread message

Guireg

unread,
Jan 7, 2016, 7:36:30 PM1/7/16
to Semantic UI
Hi everyone,

We're using Semantic-UI in our project and it works well. We just have a more complex requirement on the Search Box module. We'd basically like to setup our own lookout expression into local files.

For example, if the user types "ships nz" , we would like to list all ships in New Zealand. 

Is it possible to customize somewhere the lookout expression ? We've found the parameter regexp in http://semantic-ui.com/modules/search.html#/settings  but unfortunately it's not that powerful.

Thank you !

Cheers,

Guireg

Jack Lukic

unread,
Jan 7, 2016, 7:59:13 PM1/7/16
to Guireg, Semantic UI
I'm fairly certain you can just overwrite the internal "search object" method

$('.ui.search').search('internal', 'search object', function(searchTerm, source, searchFields) {
  let results = [];
  // add some custom matchers
  if(searchTerm == 'ships nz') {
    results.push(source.ships.newZealand);
  }
  // do something to filter object by search terms as well as you are replacing this functionality (see line 533 of search.js)
  return results;
});

--
You received this message because you are subscribed to the Google Groups "Semantic UI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semantic-ui...@googlegroups.com.
To post to this group, send email to seman...@googlegroups.com.
Visit this group at https://groups.google.com/group/semantic-ui.
For more options, visit https://groups.google.com/d/optout.

Jack Lukic

unread,
Jan 7, 2016, 8:01:31 PM1/7/16
to Guireg, Semantic UI
I could imagine a callback which lets you add custom matchers via results callback after normal matching. 

Submit an issue on our GitHub board and ping me here, so i can tag it for a future release.

Guireg

unread,
Jan 10, 2016, 3:21:56 PM1/10/16
to Semantic UI, guireg.c...@gmail.com
Hi Jack !

Thanks for the prompt answer.

I tried your solution but the overridden method never gets called. 

I tried to put custom results with the addresult(html) method but we don't have the same rendering than with the local search. The design of the results-box is poor and dirty when we have to specify our HTML instead of the default style which is nice. 

Do you have any method that can be like addResult(json) , you put a JSON in the local search format and it add it in the results box with the default layout ? 

Cheers !

Guireg
Reply all
Reply to author
Forward
0 new messages