How to add a powerful search functionality to my web app - angularjs

I am building an app to browse events. The front end uses angular framework and the backend uses laravel.
How do I add a powerful search functianlity, wherein the user enter his query using an input element and I pass the same to laravel controller.
I now need to return relevant events based on the query.
As of now I am using a very basic algorithm - each word in a query is pushed into an array. Article's are discarded. Based on the length of the array, I try to match each words to some fileds in the table and return unique events.
Is there a better, faster and more efficient way of doing this.

You could use laravel-search
It has support for a few advanced search methods.

I recommend you to use Elastic search for your goals. You can find tutorial here: http://www.fullstackstanley.com/read/simple-search-with-laravel-and-elasticsearch. Also you can use good wrapper https://github.com/mmanos/laravel-search for elastic and another search engines.

Well you added the tag elasticSearch so I guess that's what you are interested in. ElasticSearch has no authentication system so the best way is to create a controller in Laravel that comunicates with elasticSearch a returns the JSON response.
A basic setup will not be hard to do, anything beyond that will need you to learn more advanced concepts of ElasticSearch.
ElasticSearch will handle the search algorithm for you, you just need to pass the value the user is searching and that's it.

Related

Should I filter data in backend or frontend?

I have a web service built with Spring, my view is built with React and I use Redux for state management.
Let's say my API has an endpoint /api/products and I've implemenented search functionality, which pulls all the products from the enpoint, stores them in Redux store and displays them. Now I want to implement sorting functionality and I have two ideas for achieving it:
Modify my api endpoint /api/products to take parameters. For example /api/products?sortBy=price (less logic in UI, more network requests)
Use the products that I have stored in the store. (less network requests, more logic in UI)
Which one of these, if any, would be considered as the best practice?
It would depend on
What is the acceptable latency? How often do you need to call this list? Almost every second, like in an autocomplete field? Say, a few times a minute, for a report which is sorted by different parameters by the user? Or something like a rarely used settings page?
How much data do you have? Is it a few million? or a few dozen? If it is too many, better to filter in the backend and send only the required rows.
How big is each row? If each row is big with many fields, your payload will increase.
Are you having to make a tradeoff between initial load time (to load all the data from the backend once) vs responsiveness (when the user is interacting with the data)?
I hope this will give you the general idea on how to decide. Maybe able to discuss more if you have details of your specific situation.
You have to use backend. If you have like 3000 records, you need to use pagination. You shouldn't sort all pages on frontend, because it would be too much data. You need to use backend to sort and send only data you want to display on specific page.
Please dont use backend functionality in your Frontend.
Spring Boot is an great framework and offers you Sort and Pageing functionalities.
Example:
public interface UserRepository extends CrudRepository<User, Long> {
Page<User> findAll(Pageable pageable);
List<User> findByLastname(String lastname, Sort sort);
}
Please look into the Documentation -> Spring Data Jpa

How to index the landing page of many URLs using Solr?

I have a list of thousands of Web URLs (originated from bookmarks). I have a need to be able to search the landing page of these URLs. I don't need the web crawler function but I need the de-duplication function.
I'm new to solr and try to figure out the simplest way to create the index. I'm thinking about using SimplePostTool that accepts multi URLs as its parameters. However, I have difficulty understanding how to use the de-duplication with this SimplePostTool.
Is there any other method to do this indexing?
Appreciate for any hints.
Thanks.

Should I use Servlet for Database access and Display results in JSP using JSTL?

I've been learning Java for more than 6 months. I'm developing a web app and learning through building it. I'm using Glassfish Server and MySql. No frameworks. Using Servlet, JSP and EJB.
Now I'm querying database through JSP page and displaying results. Is this the best way? or Should I use servlet for querying database and displaying results in JSP?
I want to display only part of the resultset object and show the remaining if the user wants to see it. So Could I implement this using jsp alone?
I would recommend usind your Servlet to handle the database-connunication only and perhaps some logging on the usage of the Connection. The logic would best be implemented in JSP alone since you can better maintenance it.
Querying database through JSP page is not the best way. And because you are not using any framework is definitely not the best way to learn. While learning you need to try as much frameworks as possible to find out which one you can use or not to use. You are also need to learn patterns for building Java EE applications.
Should I use servlet for querying database and displaying results in jsp?
This approach is much better, but is not enough because of coupling database code with servlet code.
I want to display only part of the resultset object and show the remaining if the user wants to see it. So Could I implement this using jsp alone?
What do you want to display should be coded in the servlet.
You should avoid coding your business logic codes in your JSPs. Segrate your application into multiple layers, take a look at MVC design pattern.
Model: These are plain POJO classes where your DB transaction and business logic happens.
Controller: This is where your servlets goes. These classes accept user request, call appropriate Model classes and send response to view.
View: This is you JSPs, displays data to users. Avoid using Scriptlets in your Jsps. Use JSTL and EL.
Take a quick look at this example MVC application, and do your own searching on MVC. Hope it helps you to get started.

Should I use Angular JS for faceted search?

I'm planning to build a webpage that compares large amounts of products.
I need faceted search/filters for that, so the visitor can filter the product on price/color etc.
I couldn't find a ready to implement webshop script for that, so I'm planning to build it myself.
I'm a fan of Laravel, but to avoid page refreshes if the user is changing the filters in the side bar, you need a kind of AJAX calls to your Eloquent ORM.
So that's when AngularJS can be handy, but now I'm confused if I do need Laravel for such a stack. Because if you use AngularJS and MongoDB, you don't need Laravel at all.
So I'm not sure what is best practice.
Disclaimer: I know nothing about Laravel, but a quick google tells me it's a PHP framework for making a restful API.
The 'standard' stack for angular apps at the moment is the "MEAN" stack. That is: MongoDb, Express, Angular, Node. I'm not sure this can be considered a "Best Practice", because it's not necessarily better, but it is definitely the common practice, and as such will be easier to get support and help with.
All that being said, angular really doesn't care about the back-end. It's a front-end framework for making single page web applications. All it really needs is a decent API that you can access by creating a custom service. There is no reason you can't replace node and express with PHP and laravel, and mongo with SQL, you just won't get such a nice acronym!

DotNetNuke -- Inserting URL parameters in forms

We are migrating our website to DotNetNuke and are looking to replicate the functionality of our survey page. Currently, on the bottom of every e-mail we send through our CRM system, there is a link to a satisfaction survey along with some parameters to pre-populate some of the fields. So the URL looks something like like:
/survey.aspx?ticketID=1234&userName=John+Doe
I found the custom module "helferlein_Form" which seems okay for actually creating the form that the user fills in, but I don't see a way to pre-populate the fields. DotNetNuke does let you insert tokens(ex: [Date:now], [User:username]), but I don't see a way to grab individual parameters from the URL. Is there something I'm missing that will let me do that?
I'm not familiar with that module either, but I would strongly recommend using Xmod for customized forms that allow you to easily grab url parameters.
I'm not sure about the module you reference.
However, in my experience Dynamic Forms from Data Springs would fit the bill perfect. It has the ability to pre-fill and even run custom SQL queries to get data.
You should definitely try our My Tokens module.
It allows you to access the URL parameters using [Get:ticketID] or [QueryString:tickedID]. You can also build SQL tokens that use these parameters to return a list of items for example to populate a dropdown.
Also try our Action Form module which integrates very nice with My Tokens.
If you have a module you like and want to use you can always write a little javascript to grab the variables out of the URL and pre-populate your form fields using javascript.

Resources