Hi Folks,

For any of you who encounter this issue I found the solution by looking at the QueryParser code in LUCENE_2_3_2. I found that the DateTools was formatting dates the way I had been and that QueryParser supports setting Date formatting and locales for the expected dates also. I switched my Indexing Routine to use DateTools; setting the resolution to the level I required, and then used the settings on the Parser once it was created to set the date resolution to the correct level for it to use. After that all worked fine.

Kind Regards & Best Wishes
Noel


--------------------------------------------------
From: "Noel Lysaght" <[email protected]>
Sent: Friday, August 28, 2009 5:54 PM
To: <[email protected]>
Subject: Problem using QueryParser with a custom analyzer and ranges.


Hi Folks,

I have an issue which I hope someone can help me with.

I've developed a custom analyzer which is working perfectly well during indexing, formats dates & numbers and everything else just as we require for proficient indexing.

When searching it works fine for single fields, but if i need to search on a Range the custom parser is not invoked to format the field correctly and I'm wondering if anyone has any idea why or what i need to do to correct the problem.

For example, the following works perfectly
var queryRunner = new lugen.lib.QueryRunner("DATE_CREATED:27-May-2009");

but this does not, the custom parser which format dates/numbers etc correctly does not get invoked. var queryRunner = new lugen.lib.QueryRunner("DATE_CREATED:[1-Jan-2008 TO 31-DEC-2010]");

Anyone any ideas what could be happening, or an approach I should take to get it working, I'm sure I'm doing something wrong as this must be a requirement for many people.

Kind Regards

Noel Lysaght

I include the QueryRunner class for completeness. It just invokes a QueryParser at the moment, everything is in the constructor while testing so please forgive me that.
public class QueryRunner
{
const string INDEX_FILE = "c:\\temp\\lucene\\lugen.index";
string _queryString = null;
public QueryRunner(string queryString)
{
_queryString = queryString;

var dir = Lucene.Net.Store.FSDirectory.GetDirectory(INDEX_FILE, false);
var reader = Lucene.Net.Index.IndexReader.Open(dir);
var searcher = new Lucene.Net.Search.IndexSearcher(reader);
Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser("defaultField", new CustomFieldAnalyzer());
var query = parser.Parse(_queryString);
var hits = searcher.Search(query);
}
}



Reply via email to