Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do regular expression search using lucene.Net
    primarykey
    data
    text
    <p>I m using lucene.Net version 3.0.3. I want to do regular expression search. I tried the following code:</p> <pre><code>// code String SearchExpression = "[DM]ouglas"; const int hitsLimit = 1000000; //state the file location of the index string indexFileLocation = IndexLocation; Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.Open(indexFileLocation); //create an index searcher that will perform the 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 </code></pre> <p>When I try to search with patten <code>"Do*uglas"</code>, I get the results. </p> <p>But if I search with the pattern <code>"[DM]ouglas]"</code> it is giving me the following error: </p> <pre><code>"Cannot parse '[DM]ouglas': Encountered " "]" "] "" at line 1, column 3. Was expecting one of: "TO" ... &lt;RANGEIN_QUOTED&gt; ... &lt;RANGEIN_GOOP&gt; ...". </code></pre> <p>I also tried doing simple search pattern like <code>".ouglas"</code> which should give me results, as I have <code>"Douglas"</code> in my text content.</p> <p>Does anyone know how to do regular expression search using lucene.Net version 3.0.3?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload