Search Modules: Create html element inside search result
See original GitHub issuePreviously I used type category
for my search… I want to inject a simply html to the result such as image below, what I should be do here…
$.fn.api.settings.api = {
'search': '/api/search/json/?q={query}'
};
$('.ui.search.quick-search').search({
type : 'category',
minCharacters : 1,
apiSettings : {
action: 'search',
onResultsAdd: function(html) {
// i can't inject here..
},
onResponse: function(searchApiResponse) {
var response = {
results : {}
};
// translate `searchApiResponse` response to work with search
var numbThreads = 0, numbUsers = 0;
$.each(searchApiResponse.items, function(index, item) {
var
model = item.model || 'Unknown',
maxResults = 8,
maxItems = maxResults/2
;
if(index >= maxResults) {
return false;
}
// create new model category
if(response.results[model] === undefined) {
response.results[model] = {
name : model,
results : []
};
}
if(item.model === 'Threads') {
if (numbThreads < maxItems) {
response.results[model].results.push({
title: item.title,
description: item.description,
url: item.url
});
}
numbThreads++;
}else if (item.model === 'Users') {
if (numbUsers < maxItems) {
response.results[model].results.push({
title: item.username,
description: item.username,
url: item.profile_url,
image: item.gravatar_url,
price: item.total_threads
});
}
numbUsers++;
}
});
selector = $(document).find('.ui.search.quick-search');
injector = '<div class="ui divider"></div>'+
'<button class="ui red button">'+
'Show more options...'+
'</button>';
selector.find('.results').append(injector);
console.log(response); // return Object such as image below..
return response;
}
}
});// EOF
I also has a problem to marked results by query. For example:
- Query =
text marked as bold
- Results:
- Collaboratively extend fully tested networks for 2.0
- Proactively text marked as bold customer directed solutions via multidisciplinary.
- Continually lorem ipsum matrix excellent communities vis-a-vis team driven
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Searching: getElement*, querySelector*
querySelectorAll(css) returns all elements inside elem matching the given CSS selector. ... Previous methods were searching the DOM.
Read more >Search | Semantic UI
A search module allows a user to query for results from a selection of data. ... A search can look for results inside...
Read more >Search Module in Semantic-UI - jquery - Stack Overflow
Semantic-UI (search) expects a "results" as root and nodes with childs content with title and description, and others that api specify.
Read more >search-result.tpl.php | Drupal 7.x
This template renders a single search result and is collected into search-results.tpl.php. This and the parent template are dependent to one another sharing ......
Read more >Web Scraping with Beautiful Soup - Pluralsight
Python offers an automated way, through various modules, to fetch the HTML content from the web (URL/URI) and extract data.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
finally… people suggested me to handle this problem at the backend, and of course using regex. I never think it before can be works with perfectly… 😸
http://stackoverflow.com/questions/41985525/semantic-ui-search-api-how-i-can-highlight-certain-characters-that-match-the#comment71148868_41985525
currently I doing this case with django, and here is my backend script…
Thank you so much @Cyb3rWarri0r8 and peterpeterson
Closing as requested.