This returns the results that come from the search query that is used
Endpoint URL
http://127.0.0.1:8080/api/search
Query parameters
Name
Type
Description
book
string
The search that is used for the book
Example code
constsearchBooks=async(text)=>{ // If the text is undefined, return an empty arrayif (text===undefined) {return [];}try{constresponse=awaitfetch(`/api/search?book=${text}`);constbooks=awaitresponse.json(); // Sort the books based on the similarity to the search textbooks.sort((a,b)=>{constsimilarityA=calculateSimilarity(a.title,text);constsimilarityB=calculateSimilarity(b.title,text); // Sort in descending order of similarityreturnsimilarityB-similarityA;});returnbooks;}catch (error) {console.error("Error fetching search results:",error);throwerror;}};
Here is a function that could be used to sort the books, it compares the elements of each string and counts the number of letters that are in the same position as letters in the search results then orders them based on which books have the highest count of similar letters
Example response
Below are the search results for "android" they are ordered by _id
Response fields
Name
Type
Description
_id
integer
This is the identification number, which is unique to each specific book
newrelease
Boolean
A Boolean value to determine whether or not the book is a new release and would therefore show up in the new release section if this is true
title
string
The title of the book
isbn
string
The International Standard Book Number for this specific book
pageCount
integer
The number of pages in the book, all pages are included
publishedDate
date
The date at which this copy of the book was first published
thumbnailUrl
string
Image URL for the thumbnail or cover of the book
shortDescription
string
A short description of the book, acting as a blurb
longDescription
string
A more extensive description which covers the major points of the book
status
string
Whether or not the book is currently published, so far all the books in the library are
authors
array of strings
An array of all authors who contributed to the book
categories
array of strings
The listed genres / categories of the book as all books are non-fiction at the moment
favourited
Boolean
Whether or not the book is a favourite for the user, as no identification system is being used, this is a global property
const calculateSimilarity = (str1, str2) => {
// Convert both strings to lowercase
str1 = str1.toLowerCase();
str2 = str2.toLowerCase();
// Calculate the number of matching characters
let matches = 0;
for (let i = 0; i < str1.length; i++) {
if (str1[i] === str2[i]) {
matches++;
}
}
// Return the number of matches as the similarity
return matches;
};
{
"_id": 1,
"title": "Unlocking Android",
"isbn": "1933988673",
"pageCount": 416,
"publishedDate": { "$date": "2009-04-01T00:00:00.000-0700" },
"thumbnailUrl": "https://s3.amazonaws.com/AKIAJC5RLADLUMVRPFDQ.book-thumb-images/ableson.jpg",
"shortDescription": "Unlocking Android: A Developer's Guide provides concise, hands-on instruction for the Android operating system and development tools. This book teaches important architectural concepts in a straightforward writing style and builds on this with practical and useful examples throughout.",
"longDescription": "Android is an open source mobile phone platform based on the Linux operating system and developed by the Open Handset Alliance, a consortium of over 30 hardware, software and telecom companies that focus on open standards for mobile devices. Led by search giant, Google, Android is designed to deliver a better and more open and cost effective mobile experience. Unlocking Android: A Developer's Guide provides concise, hands-on instruction for the Android operating system and development tools. This book teaches important architectural concepts in a straightforward writing style and builds on this with practical and useful examples throughout. Based on his mobile development experience and his deep knowledge of the arcane Android technical documentation, the author conveys the know-how you need to develop practical applications that build upon or replace any of Androids features, however small. Unlocking Android: A Developer's Guide prepares the reader to embrace the platform in easy-to-understand language and builds on this foundation with re-usable Java code examples. It is ideal for corporate and hobbyists alike who have an interest, or a mandate, to deliver software functionality for cell phones. WHAT'S INSIDE: * Android's place in the market * Using the Eclipse environment for Android development * The Intents - how and why they are used * Application classes: o Activity o Service o IntentReceiver * User interface design * Using the ContentProvider to manage data * Persisting data with the SQLite database * Networking examples * Telephony applications * Notification methods * OpenGL, animation & multimedia * Sample Applications ",
"status": "PUBLISH",
"authors": ["W. Frank Ableson", "Charlie Collins", "Robi Sen"],
"categories": ["Open Source", "Mobile"],
"favourited": true
},
{
"_id": 2,
"title": "Android in Action, Second Edition",
"isbn": "1935182722",
"pageCount": 592,
"publishedDate": { "$date": "2011-01-14T00:00:00.000-0800" },
"thumbnailUrl": "https://s3.amazonaws.com/AKIAJC5RLADLUMVRPFDQ.book-thumb-images/ableson2.jpg",
"shortDescription": "Android in Action, Second Edition is a comprehensive tutorial for Android developers. Taking you far beyond \"Hello Android,\" this fast-paced book puts you in the driver's seat as you learn important architectural concepts and implementation strategies. You'll master the SDK, build WebKit apps using HTML 5, and even learn to extend or replace Android's built-in features by building useful and intriguing examples. ",
"longDescription": "When it comes to mobile apps, Android can do almost anything and with this book, so can you! Android runs on mobile devices ranging from smart phones to tablets to countless special-purpose gadgets. It's the broadest mobile platform available. Android in Action, Second Edition is a comprehensive tutorial for Android developers. Taking you far beyond \"Hello Android,\" this fast-paced book puts you in the driver's seat as you learn important architectural concepts and implementation strategies. You'll master the SDK, build WebKit apps using HTML 5, and even learn to extend or replace Android's built-in features by building useful and intriguing examples. ",
"status": "PUBLISH",
"authors": ["W. Frank Ableson", "Robi Sen"],
"categories": ["Java"]
},
{
"_id": 34,
"newrelease": false,
"title": "Android in Practice",
"isbn": "1935182927",
"pageCount": 500,
"publishedDate": { "$date": "2011-09-30T00:00:00.000-0700" },
"thumbnailUrl": "https://s3.amazonaws.com/AKIAJC5RLADLUMVRPFDQ.book-thumb-images/collins.jpg",
"shortDescription": "Android in Practice is treasure trove of Android goodness, with over 100 tested, ready-to-use techniques including complete end-to-end example applications and practical tips for real world mobile application developers. Written by real world Android developers, this book addresses the trickiest questions raised in forums and mailing lists. Using an easy-to-follow problem/solution/discussion format, it dives into important topics not covered in other Android books, like advanced drawing and graphics, testing and instrumentation, building and deploying applications, using alternative languages, and native development.",
"longDescription": "Android, Google's platform for mobile application development, provides powerful features, a robust SDK, and almost limitless possibilities. It's not hard to find the information you need to build your first Android app, but then what If you want to build real apps for real users, you have real questions and you need real answers. Android in Practice is treasure trove of Android goodness, with over 100 tested, ready-to-use techniques including complete end-to-end example applications and practical tips for real world mobile application developers. Written by real world Android developers, this book addresses the trickiest questions raised in forums and mailing lists. Using an easy-to-follow problem/solution/discussion format, it dives into important topics not covered in other Android books, like advanced drawing and graphics, testing and instrumentation, building and deploying applications, using alternative languages, and native development. If you're new to Android, or even if you have a few cycles under your belt, you'll love the quick \"pre-flight check,\" where you'll review key platform details and tools and the building blocks of all Android applications. Then, you'll delve into Android use cases from visual elements and style, to saving and sharing data, networking, background tasks, concurrency, and more.",
"status": "PUBLISH",
"authors": ["Charlie Collins", "Michael D. Galpin", "Matthias Kaeppler"],
"categories": ["Mobile Technology"],
"favourited": false
}