How to add a search feature in jsf page - java

I want to add a search box that will return results from a mysql database. Does anyone know of any good tutorials for this? Let me know if you need more info. Thanks!

Why not just pass the search text to a query and return the result?
For example, you would pass the search String to some persistence layer (JDBC, JPA etc.) and use the correct query syntax for that layer.
A more flexible yet more complicated approach would be to use a search engine like Lucene and create a search index for your database.

Related

How to build an index search for a read-only database table?

I'm building a WebService (CXF with Spring and JPA) to search a read-only database table, i.e., a table which is in a database I only have read permissions, I must not change anything there.
I need to implement a full-text search for some fields of this table, and querying it is too slow (it is a books database, with title, author and keywords for each book) so I need to build an index for it.
I'm trying to understand if Hibernate Search help me with that, and how I could go about it.
I think it can't cause the documentation says it builds the index when the entities are updated (which are never the case in my WebService). But I'm new to all of its terminology, so I can misinterpreting things.
What would be a good path to go about this?
What should I study first to understand better what I need to do?
Thanks in advance!
I think Hibernate Search can be a perfect fit for your problem, because it allows you to build/keep the index on the file system. This way the database stays untouched. Given that you are already using JPA it should be extremely easy to enable Hibernate Search. You basically just need to get the Hibernate Search jar file and add it to your project, then annotate the entities you want to have indexed with #Indexed and the fields you want to index with #Field. Of course that's very simplified, but the online documentation should help you out there. There is a getting started section which explain the basics. Once you get this, you can dive deeper into different analyzers etc - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/
I'm trying to understand if Hibernate Search help me with that, and
how I could go about it. I think it can't cause the documentation says
it builds the index when the entities are updated (which are never the
case in my WebService). But I'm new to all of its terminology, so I
can misinterpreting things.
Well, Search will help you via automatic index updates to keep your index and database in sync for read/write application. However, Search also has a programmatic API for creating an initial index or manually rebuild the index whenever you see fit. There are several ways to do that, but it can be as simple as:
EntityManager em = entityManagerFactory.createEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
fullTextEntityManager.createIndexer().startAndWait();
Again, the documentation has more examples. I recommend you follow the getting started examples and follow up with concrete questions/problems you encounter.

Best Strategy for get results and a counted/filter list

we're developing a jobs-search site and we'd like to present search result like infojobs does, i mean:
|more |result
|filter |list
|with |(abstract
|result |of job
|count |request)
the critical part is the filter list with counter,
for example we need
developer (30)
|-Java (20)
|-C# (5)
|-Ruby (5)
we're using ejb3, jpa on jboss7 (so hibernate + ecache under the hood)
jsf2 (mojarra) with jquery for the presentation layer
i'm wondering what's the best strategy to achieve this,
is affordable to load from db all the result and then populate the filter/count part?
i think is better to fetch the result we're going to show and then another query to get the filter/count part!
Thanks!
I would use Lucene for this. Makes it much easier for you with both search and filtering. I would not recommend that you take in the whole result set and filter afterwards, that will give you performance issues in the end.

Content searching in a web application

I want to do a content search in my database. And the requirement is it has to be like a google search completely based on Ajax. Can you guys suggest me any framework or architecture or any kind of idea?
Example:
Employee Table contains Employee First Name, Last Name , Middle Name and Email. I have to search the table by providing any one of the field and the details of that employee should be populated
Consider using an index-based search engine. Apache Lucene is immensely popular, high-performant and well documented.
There are different parts to your question:
1) Ajax library: you could use Jquery which provides simple ajax methods http://api.jquery.com/jQuery.ajax/
2) On the server end there are a couple of options depending on the type of database youre using. Is it relational, is it nosql? Is your choice of database flexible or is it set in stone?
Lucene provides a query language for an index with more complex information and search requirements. But if your use case is as simple as the one above, you might just shoot off different SQL queries (assuming your database is relational).

How can I query for root entities in the App Engine DataStore (Java)

I'm trying to write a query which will identify and return all root entities (i.e. entities which have no ancestor). I initially tried calling Query.setAncestor(null) but later found out from the datastore Query docs that this doesn't work:
Passing null as a parameter to Query.setAncestor(String ancestor) does not query for entities without ancestors (this type of query is not currently supported).
So now I'm a bit stuck, given what the Query API contains I can't figure out how one would construct a query which identified all the root entities.
This needs to be app functionality so I'm looking for a solution which works programatically as opposed to some manual intervention wnich requires me to log in to the admin console and click a button :-)
Anyone know how to do this?
Cheers,
Edd
You will need to add a property to your models that you can query on. Perhaps a boolean named is_root or something similar.
As the documentation indicates, there's no way to do this - other than working around it as #Robert suggests. If you tell us what you're trying to achieve - as opposed to how you're trying to achieve it - perhaps we can provide a suggestion on how best to go about it.

Using Hibernate-Search for Complex Queries instead of Criteria API

In an app using Wicket+Spring+JPA/Hibernate stack, I have an Inbox/Search page which should have quite complex search capabilities, where records saved in a database are filtered using a myriad of filtering options. So far I've used JPA Criteria API to build the database query but it's getting quite messy. I was wondering if Hibernate-Search would be a good fit for this even though I don't really need any full-text search capabilities, I just feel (from what I read about it) that producing the query might be a bit easier?
Sorry, but Hibernate Search is based on Lucence. It is not just an other query language.
Lucene does not serach for entities in your database, it search for attibutes in the Lucene index.
Hibernate Search add the functionality to connect the Entities from your Database to the Lucene Index.
Hibernate Search and Lucene are create tool when you need advanced full text search. But if you don't need it, it is only a lot of unnesseary work (and problems).
So, as long as you do not use Lucene, Hibernate Search does not fit your needs.
The primary use case for Hibernate Search is fulltext search. However, it can also be used to index/search simple attributes/criteria. Whether the syntax for writing the queries is simpler than a criteria query is a matter of taste.
If you are not using the fulltext search capabilities you have to consider that you are adding an additional step in your application. The search query will be run against the Lucene index which will return entity ids (unless projection is used). The matching entities will then be fetched from the database.
On the other hand, once you use Hibernate Search it is easy to "improve" your search by adding some fulltext search capabilities to some of your criteria (if possible).
Whether or not you are using Search, I think the key is to write some sort of framework which programmatically builds your queries - Search or Criteria queries.

Categories

Resources