Lucene.net 2.9.4 SimpleFacetedSearch with numeric range on NumericField - lucene

I put some fields like manufacturer, group, description, num.
SimpleFaceted works ok if I use query like sometext* with QueryParser.
Im trying to use num:[100 TO 200],
num is NumericField with SetIntValue(150).
I got nothing returned.
Am I missing something?

You can't use a normal query parser for numeric range queries. However, assuming you know at query time which fields are numeric, it isn't too hard to derive a class from the Lucene query parser and create numeric range queries as necessary.
Support for numeric queries in the standard query parser looks like it should be available in Lucene.Net when a port of v3.4 is available. (See Java Lucene issue 1768)
Good luck,

Related

Wildcard Search for a numeric range

I am trying to filter out a column (plan_name) which have internet plans of customers. Eg (200GB Fast Unlimited,Free Additional Mailbox,Unlimited VDSL...). I specifically want to filter out plans which do not have any numbers in them. The column is of type varchar2 and I'm querying an Oracle database. I have written the following code:
SELECT *
FROM plans
WHERE plan_name NOT LIKE '%[0-9]%'
However, this code still returns plans like 200GB fast that have numbers in them? Can anyone explain why this is?
Oracle's like syntax does not support the kind of pattern matching you are trying. This is SQL Server syntax. Oracle interprets the pattern as a litteral '[0-9]' (which, obviously, something like '200GB'does not match).
However, unlike SQL Server, Oracle has proper suport for regular expression, through the regexp_* functions. If you want values that contain no digit, you can do:
where not regexp_like(plan_name, '\d')

Lucene String and Numeric range queries

I'm just curious why Lucene doesn't distinguish string and numeric values in a standard way.. for example ['2' TO '6'] and [2 TO 6] for range queries and treat all of them by default as String.
Is there any particular reason to treat both of these cases as the string values?
Your range query example is based on lucene query syntax. In this definition it's not defined in what kind of field type you execute this query.
Basically if you apply this query to a TextField the evaluation will be based on String. If you apply this to a IntPoint the number will be interpreted as integer. Responsible for this is the QueryParser in which you add your query and your field you like to search.
In your case using an IntPoint would make sense because you want to search for an numeric range.
More details about the query parser see QueryParser Javadoc

hibernate query builder for lucene time range

I am building a lucene query for an indexed object to determine if current time lies between the range of start Time and end Time. I'm unable to get the exact lucene query .
org.apache.lucene.search.Query luceneQuery5=queryBuilder3.bool()
.must(queryBuilder3.keyword().onFields("TimeDependentProfileKey").matching("TimeKey").createQuery())
.must(queryBuilder3.range().onField("StartTime").above(new Time(0)).createQuery())
.must(queryBuilder3.range().onField("StopTime").below(new Time(0)).createQuery()).createQuery();`
The lucene query which was generated looks like:
+TimeDependentProfileKey:3 +StartTime:[19700101000000000 TO *] +StopTime:[* TO 19700101000000000]
how do i change the format of timestamp, can anyone please help me.
By searching for a date object, you are deferring formatting to hibernate. I would consider the format you specified as functional, though perhaps not ideal. If you want to use your own formatting, you must deal in strings, be consistent in your formatting, and make sure your format will work well for sorting and range queries as a string.
If you want to have hibernate handle formatting dates for you, you need to define your date field with a #DateBridge(resolution = ...) annotation. This ensures that hibernate will format dates effective for correct range querying and sorting in lucene, and allows you to query against the field with date objects instead of strings.

find common misspelled searches in SQL Server

IS there a way to find common misspellings in sql server?For example, if I had a legitimate search… like “Forclosure” instead of “Foreclosure”, is there a way to find the connection within a table without doing LIKE or CASE WHEN?
I’m not 100% sure it will work but you can try experimenting with SOUNDEX function and see if it can give you any results.
SOUNDEX converts an alphanumeric string to a four-character code that is based on how the string sounds when spoken.
For example:
SELECT SOUNDEX ('Smith'), SOUNDEX ('Smythe');
Gives same results for both

Apache Lucene - search by concrete date

I want to find some data of a application which allows using Apache Lucene syntax for search queries. I search data by date and want to find data from concrete date - concrete day. How can I do that?
Queries:
date: [2010-10-4 TO 2010-10-4]
or
date: 2010-10-4
does not work.
Short answer: there is no "standard" for date query syntax in Lucene. You need to find out the format(s) your app supports.
Long answer: For the last couple years or so, Lucene keeps the numeric data specially encoded. Most likely, the date in the index is kept in the timestamp format. This means the query parser needs to take in the query, chew it and spit out the timestamp. Querying against a raw timestamp is not very practical - at least for humans - and your query parser likely has some pre-defined format it is able to understand.
For example, Solr has a pre-defined set of supported date/time formats and is able to parse those into timestamps.
Don't forget Lucene is just a library and each application (including Solr and the one you are using) is meant to use it the way they like.
I found the solution.
For searching by one conrete day, query:
date: [2010-10-4T00:00:00 TO 2010-10-4T23:59:59]
is correct
I put the date range without the hyphens and It worked for me.
date: [20210901 TO 20211101 ]
See the doc Range Searches