How to add wildcard query in Hibernate Search 3.1.1GA - hibernate-search

how add wildcard query when using hibernate search. I am using Hibernate Search 3.1.1GA jar and unable to upgrade my jar to upper version. In upper version of hibernate we can use wildcard method using Query Builder.
I am stuck please help me out.

I assume you are referring to the Hibernate Search query DSL. Something like this:
Query luceneQuery = queryBuilder
.keyword()
.wildcard()
.onField("foo")
.matching("bar*")
.createQuery();
This DSL is indeed not part Search 3.1.1 and was added later. In this version you need to build your queries by using native Lucene queries. Really all the Search DSL does is under the hood building these native queries for you. In your case you want to look at org.apache.lucene.search.WildcardQuery or you could use the org.apache.lucene.queryParser.QueryParser to use the Lucene query syntax which also allows wildcards.

Related

How to make a selection by the part of expression after "WHERE" using CriteriaApi or JPA

How can I make a selection by the certain field using any possible expression using Criteria API or JPA?
For example I have a "price" field in my table.
So I want to implement an ability in UI to enter: "> 10 and < 50" and get all relevant results
">= 20" and get all relevant results
"!= 10" and get all relevant results
Or in text field:
"like %substring%"
And so on
Is it possible?
Sure this is possible, depending on how complex you want these expressions allowed to be it might not be easy or not safe though.
You basically have two options:
you parse the expression and then use the parsed result to build your criteria.
As Abinash Ghosh noted: You can make that in the form of a Specification builder to interoperate nicely with Spring Data JPA.
This is not recommended to use, I'm putting it mainly here so that I can note it as not safe You can assemble a SQL or JPQL String and just use that as a query. It's simpler, because JPA will do the parsing for you. This will open up your application to SQL injection (or JPQL injection I guess). So don't use this.

How to query for elements in a collection in Spring Mongo JPA

I'm using JPA repositories and I see they all have findBy methods. How can I do the equivalent of SQL IN clause e.g. findAll(where field in 'a','b','c')?
findByFieldNameIn(List<String> fieldList);
This should work fine.
You can refer this link to learn to build repository methods.

CQ QueryBuilder API.. why?

Why is there need of QueryBuilder API in AEM / CQ when we can use JCR Query API? What does it provide that the former doesn't? Or is it just a non-SQL alternative to JCR API?
We are currently building a module which fetches info from JCR nodes and wanted to know the best way to go about it.
Thank you.
Query Builder is built on top of JCR Query API. What does query builder provide that JCR API doesn't ? IMHO it would be Usability. You deal with a map of predicates instead of queries. The Out of the box predicates work in most situations. The limit and offset features work like a charm for pagination situations. Grouping let's you write complex queries in a very readable manner. One more nice feature is the faceted search , your search results can be split by tags. Query Builder returns Resources and not nodes so you don't have to handle to deal with those checked repository exceptions that come along with JCR api ( https://cqdump.wordpress.com/2012/11/06/cq5-coding-patterns-sling-vs-jcr-part-1/ ).
Since it is exposed as a REST servlet it is often used in building interfaces like custom dashboards and the familiarity helps.
It's an abstraction so you are shielded from changes at lower level. Some of the queries that used to work in JackRabbit 2 don't work in the newer Oak (Aem 6) but all the query builder one's still work.
Faceted search example :
http://localhost:4502/libs/cq/search/content/querydebug.html?charset=UTF-8&facets=on&isURL=on&query=http%3A%2F%2Flocalhost%3A4502%2Fbin%2Fquerybuilder.json%3Ftype%3Dcq%3APage%26tagid%3Dmarketing%3Ainterest%2Fproduct%26tagid.property%3Djcr%3Acontent%2Fcq%3Atags
Query Builder Details : http://www.slideshare.net/alexkli/cq5-querybuilder-adapttoberlin-2011

Generating DAO with Hibernate Tools on Eclipse

How can I use the tools to generate DAOs?
In fact, instead of passing through the hbm files, I need to configure hibernate tools to generate the DAO and the annotations.
See Hibernate Tools - DAO generation and How generate DAO with Hibernate Tools in Eclipse?
First let me assume DAO as POJO/Entity beans. Basically you can accomplish your task either through forward or reverse engineering. In case of forward engineering, probably you can look into AndroMDA tool. In case If u wish to accomplish it through reverse engineering Click here ..
Hope this will be helpful.
Welcome. You got to write all your data access logic by your hand (if I’m not wrong). Hiberante let you interact with database in three ways.
Native SQL which is nothing but DDL/plain SQL query. This can be used very rarely in hibernate projects even though this is faster than below mentioned options. Reason is simple “One of the key advantage of hibernate or any other popular ORM framework over JDBC Is you can get rid of database specific queries from your application code!”
HQL stands for hibernate query language which is proprietary query language of hibernate. This looks similar to native SQL queries but the key difference is object/class name will be used instead of table name and public variable names will be used instead of column names. This is more Object oriented approach. Some interesting things will be happening in background and check if you are keen!
Criteria API is a more object oriented and elegant alternative to Hibernate Query Language (HQL). It’s always a good solution to an application which has many optional search criteria.
You can find lots of examples on internet. Please post your specific requirements for further clarification on your problem.
Cheers!

Mongo C# Driver OData issue "Where with predicate after a project is not supported"

Request: /api/person?$filter Name eq 'John' with server backed up method that
return repo.GetAll().Select(o => Mapper.Map<>PersonDTO>(o));
Only the $filter requests error out with "Where with predicate after a project is not supported" but $top / $skip / $orderby work fine. My guess is, Mongo C# has a bug while generating the query & projects before applying the filter. Instead it should apply filter first and then project. I am using OData 5.2.0-rc1 and Mongo C# driver is 1.7.
Any inputs are much appreciated. Thanks...
That is a limitation in the current implementation of Linq. We are working to correct that with this ticket: https://jira.mongodb.org/browse/CSHARP-601.
However, I'd encourage you to figure out what you are actually attempting to do. Projecting prior to a filter could mean you are filtering on computed expressions, such as adding 2 columns together. MongoDB queries do not support this type of behavior, which is why this is currently disallowed by our linq provider. Aggregation framework allows this to a point, but there are a different set of limitations imposed by the Aggregation framework.
In your particular case, what you are wanting us to do is impossible. You are asking us to know how to create a MongoDB query based on an AutoMapper generated object. This simply impossible unless we (at runtime) read the AutoMapper mapping and apply it to our internal class models.