c# - How to do regular expression search using lucene.Net -
i m using lucene.net version 3.0.3. want regular expression search. tried following code:
// code string searchexpression = "[dm]ouglas"; const int hitslimit = 1000000; //state file location of index string indexfilelocation = indexlocation; lucene.net.store.directory dir = lucene.net.store.fsdirectory.open(indexfilelocation); //create index searcher perform search lucene.net.search.indexsearcher searcher = new lucene.net.search.indexsearcher(dir); var analyzer = new whitespaceanalyzer(); var parser = new multifieldqueryparser(lucene.net.util.version.lucene_30, new[] { field_content, }, analyzer); term t = new term(field_content, searchexpression); regexquery scriptquery = new regexquery(t); string s = string.format("{0}", searchexpression); var query = parser.parse(s); booleanquery booleanquery = new booleanquery(); booleanquery.add(query, occur.must); var hits = searcher.search(booleanquery, null, hitslimit, sort.relevance).scoredocs; foreach (var hit in hits) { var hitdocument = searcher.doc(hit.doc); string contentvalue = hitdocument.get(field_content); } // end of code
when try search patten "do*uglas"
, results.
but if search pattern "[dm]ouglas]"
giving me following error:
"cannot parse '[dm]ouglas': encountered " "]" "] "" @ line 1, column 3. expecting 1 of: "to" ... <rangein_quoted> ... <rangein_goop> ...".
i tried doing simple search pattern ".ouglas"
should give me results, have "douglas"
in text content.
does know how regular expression search using lucene.net version 3.0.3?
the standardqueryparser not support regular expressions @ all. is, instead, attempting interpret portion of query range query.
i wish use regexes search, need construct regexquery
manually. note, regexquery
performance tends poor. might able improve switching javautilregexcapabilities
jakartaregexpcapabilities
.
Comments
Post a Comment