Crash with Lucene.NET when using Sort - lucene.net

I have a date field inserted in a Lucene database with the following code:
Document.Add(new NumericField("TimeStamp", Field.Store.YES, true).SetLongValue(Data.TimeStamp.ToBinary()));
And I have the following query:
var Sort = new Sort(new SortField("TimeStamp", SortField.LONG, true));
var ParsedQuery = ParseQuery(_Parser, SearchQuery);
var Filter = new QueryWrapperFilter(ParsedQuery);
var Hits = _Searcher.Search(ParsedQuery, Filter, Skip + Limit, Sort);
But it crashes when executing the search method with the following:
A first chance exception of type 'Lucene.Net.QueryParsers.QueryParser.LookaheadSuccess' occurred in Lucene.Net.dll
A first chance exception of type 'System.IO.IOException' occurred in Lucene.Net.dll
A first chance exception of type 'System.IO.IOException' occurred in Lucene.Net.dll
A first chance exception of type 'System.AccessViolationException' occurred in HDIndexing.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
If I replace the Sort variable with one of the constants, such as Sort.RELEVANCE then the search works properly.
The problem comes from my custom search.
Incidentally I noticed something else odd and I do not know if these is a connection: If I inspect my Lucene DB with the Luke tool, all my fields are reported to be strings:
http://i.stack.imgur.com/SnlSD.png
I do not know if this is a bug in Luke or something is wrong with how Lucene is set up on my end.
I tried to change the sort to a type 'string' to see what would happen, but it crashes the same way, so either way, the type of the field doesn't seem to have an impact.
Has anyone experienced that problem before?
It could be similar to someone else's post: lucene.net sort not working access violation

Related

Trying to write a simple code in mongoldb, receiving an error

Just trying out MongoDB. So this might be a very basic issue. Trying to create a collection "info", but encountering errors as below. Appreciate the help.
uncaught exception: SyntaxError: missing : after property id :
#(shell):1:42
The code is as below :
db.info.insert({"userName":"John","mail”:"John#gmail.com","mobile":12345678},{"Transaction":[{"itemId":"a100","price":200},{"itemId":"a110","price":200}]},{"Payment":["Type":"Credi
t-card","Total":400,"Success":true]},{"Remarks":"1st complete record,payment successful"})
When you try, most of the developers would recommend to read the documentation of Insert data in mongodb. If you clearly understand, then you might understand the problem. The document was not well formatted which means you created object for each key:value pair. And payment is an array which holds objects. It was also not formatted.
You can try below code, and have fun with MongoDB
db.info.insert(
{
"userName":"John",
"mail":"John#gmail.com",
"mobile":12345678,
"Transaction":[{"itemId":"a100","price":200},{"itemId":"a110","price":200}],
"Payment":[{"Type":"Credit-card","Total":400,"Success":true}],
"Remarks":"1st complete record,payment successful"
}
)

Add a missing key to JSON in a Postgres table via Rails

I'm trying to use update_all to update any records that is missing a key in a JSON stored in a table cell. ids is the ids of those records and I've tried the below...
User.where(id: ids).
update_all(
"preferences = jsonb_set(preferences, '{some_key}', 'true'"
)
Where the error returns is...
Caused by PG::SyntaxError: ERROR: syntax error at or near "WHERE"
LINE 1: ...onb_set(preferences, '{some_key}', 'true' WHERE "user...
The key takes a string value so not sure why the query is failing.
UPDATE:
Based on what was mentioned, I added the parentheses and also added / modified the last two arguments...
User.where(id: ids).
update_all(
"preferences = jsonb_set(preferences, '{some_key}', 'true'::jsonb, true)"
)
still running into issues and this time it seems related to the key I'm passing
I know this key doesn't currently exist for the set of ids
I added true for create_missing so that 1 isn't an issue
I get this error now...
Caused by PG::UndefinedFunction: ERROR: function jsonb_set(hstore, unknown, jsonb, boolean) does not exis
some_key should be a key in preferences
You're passing in raw SQL so you are 100% responsible for ensuring that is actually valid SQL. What you have there isn't. Check your parentheses:
User.where(id: ids).
update_all(
"preferences = jsonb_set(preferences, '{some_key}', 'true')"
)
If you look more closely at the error message it was telling you there was a problem precisely at the introduction of the WHERE clause, and right after ...true' so that was a good place to look for problems.
Syntax errors like this can be really annoying, but don't forget your database will usually do its best to pin down the place where the problem occurs.

EF Core throws NullReferenceException while comparing strings with CompareOptions

I have a Worker entity with string Name property, and just want to filter all Workers whose Name contains some specific string (from frontend text input).
When I do the filtering with:
_context.Workers.Where(w => w.Name.ToUpper().Contains(filter.ToUpper()).ToList()
it is working but it does not solves some specific diacritics in filter term.
When i try with:
var compareInfo = CultureInfo.InvariantCulture.CompareInfo;
_context.Workers.Where(w => compareInfo.IndexOf(w.Name, filter, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase) > -1).ToList()
i get System.NullReferenceException: 'Object reference not set to an instance of an object.'
and console An exception occurred in the database while iterating the results of a query for context type 'Project.MyDbContext'.
I've also tried with
_context.Workers.Where(w => compareInfo.IndexOf((w.Name??""), filter, CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreCase) > -1).ToList()
to perform a null check, but same.
Did anyone have same problem, or maybe idea what could be changed here so I could accompiish searching with diacritics?
Thx!

Running a query using date from a form MS Access

How do I run a query using a value from a textbox from a form I have? I know that there is another post here at Stackoverflow dealing with this issue but I found it to be insufficient for my needs.
I formated my textbox into Medium Date format with its default value being =Date(). However, when I pick up a date and open my report I get this error:
Runtime error 3071: Expression Too Complex
My where clause is this
WHERE
(
(AllInfo.DateOpened >= CDate([Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value))
)
and I am sure it is this code piece that is throwing the problem since when I take it out of the query the error message simply disappears.
Any ideas?
Try with:
(AllInfo.DateOpened >= DateValue([Forms]![Main Form]![WindowPrintOptions].[Form]!txtDateOpenedFrom))
)
Folks,
I got the problem. It was the "AllInfo" alias. It wasn't applicable at that escope inside the query. By changing the proper things, it was enough to write:
[Forms]![Main Form]![WindowPrintOptions]![CustomizedReport]!txtDateOpenedFrom.Value
Issue solved. Thank you all!

TermQuery not returning on a known search term, but WildcardQuery does

Am hoping someone with enough insight into the inner workings of Lucene might be able to point me in the right direction =)
I'll skip most of the surrounding irellevant code, and cut right to the chase. I have a Lucene index, to which I am adding the following field to the index (variables replaced by their literal values):
document.Add( new Field("Typenummer", "E5CEB501A244410EB1FFC4761F79E7B7",
Field.Store.YES , Field.Index.UN_TOKENIZED));
Later, when I search my index (using other types of queries), I am able to verify that this field does indeed appear in my index - like when looping through all Fields returned by Document.GetFields()
Field: Typenummer, Value: E5CEB501A244410EB1FFC4761F79E7B7
So far so good :-)
Now the real problem is - why can I not use a TermQuery to search against this value and actually get a result.
This code produces 0 hits:
// Returns 0 hits
bq.Add( new TermQuery( new Term( "Typenummer",
"E5CEB501A244410EB1FFC4761F79E7B7" ) ), BooleanClause.Occur.MUST );
But if I switch this to a WildcardQuery (with no wildcards), I get the 1 hit I expect.
// returns the 1 hit I expect
bq.Add( new WildcardQuery( new Term( "Typenummer",
"E5CEB501A244410EB1FFC4761F79E7B7" ) ), BooleanClause.Occur.MUST );
I've checked field lengths, I've checked that I am using the same Analyzer and so on and I am still on square 1 as to why this is.
Can anyone point me in a direction I should be looking?
I finally figured out what was going on. I'm expanding the tags for this question as it, much to my surprise, actually turned out to be an issue with the CMS this particular problem exists in. In summary, the problem came down to this:
The field is stored UN_TOKENIZED, meaning Lucene will store it excactly "as-is"
The BooleanQuery I pasted snippets from gets sent to the Sitecore SearchManager inside a PreparedQuery wrapper
The behaviour I expected from this was, that my query (having already been prepared) would go - unaltered - to the Lucene API
Turns out I was wrong. It passes through a RewriteQuery method that copies my entire set of nested queries as-is, with one exception - all the Term arguments are passed through a LowercaseStrategy()
As I indexed an UPPERCASE Term (UN_TOKENIZED), and Sitecore changes my PreparedQuery to lowercase - 0 results are returned
Am not going to start an argument of whether this is "by design" or "by design flaw" implementation of the Lucene Wrapper API - I'll just note that rewriting my query when using the PreparedQuery overload is... to me... unexpected ;-)
Further teachings from this; storing the field as TOKENIZED will eliminate this problem too, as the StandardAnalyzer by default will lowercase all tokens.