NHibernate and NHibernate Search Version Problem - nhibernate

I have sample application on Nhibernate with Nhibernate Search with the following version nos,
Nhibernate - v2.0.0.1001
Nhibernate Search - v2.0.0.1001
I am not sure if it custom build, but everything seems to work fine here. But as soon as I change the Nhibernate version to v2.0.1.4000 (a later minor version and build), things start breaking at,
IList result = s.CreateCriteria(typeof(DomainObject)).Add(NHibernate.Search.Search.Query("Summary:NHibernate or Name:NHibernate"))
VStudio complains "'Query' is not supported language."
Has anyone had a similar issue? How could I get a port for v2.0.1.4000?
Thanks.

I guess the way to create a lucene query was to just use the Query Parser:
QueryParser queryP = new QueryParser("id", new StandardAnalyzer());
Lucene.Net.Search.Query q = queryP.Parse("Summary:NHibernate or Name:NHibernate");
IList result = s.CreateFullTextQuery(q, typeof(DomainObject)).List();

Related

LINQ unable to translate query after update to EF Core 6/7

I have recently updated a project to .NET 6 with EF Core 7 and NPGSQL 7 from .NET 5.
I have added the following to my startup:
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
Most of my queries are running ok, but I am having issues with it translating a few date queries.
An example of a query that is no longer functioning is:
var roomlistlatest1 = _context.roomlistlatest
.Where(c => c.statusdate.Value.Date == DateTime.Today.AddDays(-1).Date);
I get the following error:
The LINQ expression 'DbSet() .Where(r => r.statusdate.Value.Date == DateTime.Today.AddDays(-1).Date)' could not be translated.
_context.roomlistlatest is a view that has a model and statusdate is a timestamp that has been set in the model to a nullable DateTime.
The reason I am using .Date is that I need to get the date without the time for this specific query.
Has anybody come across this after upgrading a project, and if so, any ideas on how I can get passed this?
I have many queries that use similar behaviour so need a generic work around if there is one.
Thanks
Chris

Why does Lucene (Hibernate Search) ignore my own operator?

I recently updated my Hibernate Search to 5.0.0.Alpha4, which uses Lucene 4.8.1.
I still use the same codes to create my search query as before (I used Lucene 3.3 before updating, it was a really old version:)). But I noticed a problem, that the new version just ignores my operator and uses the default operator all the time, however the codes worked fine in the older version:
For Example: Now I set "AND" as default Operator. I just typed "java or php" in the search field. And I made a breakpoint at the line of queryParser.parse(searchString). It tells me that my searchString is now "java or php", which is correct. But the created searchQuery after queryParser.parse() is:
+(title:java) +(title:php)
Which means that Lucene deals my searchString as "AND" LOGIC!
I don't know if it is a bug of newer Lucene or just i did something wrong.
Here are the codes:
StandardAnalyzer analyzer = new StandardAnalyzer(
Version.LUCENE_47);
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
Version.LUCENE_47,
mySearchFields,
analyzer);
queryParser.setAllowLeadingWildcard(true);
queryParser.setDefaultOperator(myDefaultOperator);
queryParser.setAutoGeneratePhraseQueries(true);
Query searchQuery = queryParser.parse(searchString);
FullTextQuery jpaQuery = getFullTextEntityManager()
.createFullTextQuery(searchQuery, entities);
jpaQuery.setMaxResults(ORACLE_MAXIMUM_ELEMENTS_IN_EXPRESSION);
Boolean Operators must be in CAPS. That is: java OR php is correct, java or php is not.
To explain exactly what is going on, without or being in caps, it's treated as another term. With AND being the default operator, this makes it:
java AND or AND php
or, something like
+(title:java) +(title:or) +(title:php)
However, or is a standard stop word, and so it will be eliminated during analysis of the query, and you are left with simply:
+(title:java) +(title:php)

NHibernate HiLo algorithm re-using hi as lo?

I'm using NHibernate 3.1 with FluentNHibernate 1.2.0.712.
We're using the HiLo generator to generate Ids - with standard settings except max_lo is set to 100 (default 1000).
Our mappings all have this line in the ctor:
Id(m => m.Id)
.GeneratedBy.HiLo("100");
Hovewer, when we start fresh with a new SessionFactory, and the first item is saved - let's say the next hi is 12 it gets Id 1212 (I would have expected 1200 or 1201). Is this intended behaviour or am I missing some vital part of the configuration?
I've tried using default values ("1000") as the max_lo, but then the above would result in 12012 - still not exactly what I would expect.
I read through the nhibernate code-base. This is apparently intended behaviour - for the initial set, it 'clocks over' (for a reason beyond me - but probably has something to do with keeping parity with hibernate (since that has that exact same comment :-)).
For all subsequent increments - all is performing as expected.
So, closing down this question.

UniFile ReadNamedFields

I'm currently using IBM's UniObjects and I trying to retrieve multiple fields from a UniFile at once to increase efficiency.
UniFile uFile = uSession.CreateUniFile("fileName");
uFile.RecordID = inputID;
string[] fieldNames = {"I_Field_1", "D_Field_1", "I_Field_2", "D_Field_2"};
UniDynArray uFields = uFile.ReadNamedFields(fieldNames);
uFields value:
þvalue1þþvalue2
þ = delimiter for the UniDynArray
The problem is that half of these fields are I-descriptors and half are D-descriptors. The I-descriptors will not output unless only a single one of them is in the array fieldNames like so:
string[] fieldNames = {"I_Field_1"};
UniDynArray uFields = uFile.ReadNamedFields(fieldNames);
So I guess my question is why are the I-descriptor fields not being displayed and if there is a way they can be using this or a similar method.
I'm new to stackoverflow as well as an entry-level developer so thank you for any help you can provide.
It sounds like an defect with UniObject's. Since you say it is IBM's UniObject's, you most likely have an old version (UniData/UniVerse is owned by Rocket Software now).
Assuming you are on an old version, it is possible this works in a newer version. You should look into scheduling an update of your UniData server and hence client software such as UniObjects.
Outside of this, you can probably raise a bug with your VAR/Support Provider or Rocket Software directly.

nHibernate 3.0 queries

Working through the summer of nHibernate tutorials have gotten to the section on queries. Seems there have been changes since that series was made. So I went to the online docs for nHB 3.0 but code such as:
IList cats = session.CreateCriteria(typeof(Cat))
.Add(Expression.Like("Name", "Fritz%"))
.Add(Expression.Between("Weight", minWeight, maxWeight))
.List();
Generates the error "The name 'Expression' does not exist in the current context"
Code like:
return session.CreateCriteria(typeof(DataTransfer.Customer))
.Add(new NHibernate.Criterion.LikeExpression("Firstname", firstname))
.Add(new NHibernate.Criterion.LikeExpression("Lastname", lastname))
.List<Customer>();
Works but it seems that it is missing a number of query methods like GtExpression.
Are the online docs up to date, and if so, why can't I use Expression...
If the online docs aren't up to date then where do I get a description of the Criterion interface?
Thanks
You forgot to add using NHibernate.Criterion;.
Anyway, the Expression class is deprecated. Use Restrictions instead.
Weird thing. I still use Expression.* static methods and these are still work. Are you sure you use the latest version of NH3.0? I use Alpha 2 version.
If you need to make it work urgently, let's try the QueryOver<> feature:
return session.QueryOver<DataTransfer.Customer>()
.WhereRestrictionOn(u => u.Name).IsLike("Fritz%")
.AndRestrictionOn(u => u.Weight).IsBetween(minWeight).And(maxWeight)
.List();
It works well for simple queries