lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Itamar Syn-Hershko <ita...@code972.com>
Subject Re: Wildcard Search with Special Characters "#" Not Working
Date Thu, 24 Aug 2017 07:54:57 GMT
You are using StandardAnalyzer but it removes those characters on indexing
and search. Use another analyzer e.g. WhitespaceAnalyzer.

On Aug 22, 2017 12:41, "Singaravelu R" <singaravelu.r@hotmail.com> wrote:

> Hello,
>
> I’m using Lucene.Net 3.0.3.0 version in my website to search list of
> courses.
> I have few courses which contains the special character “#” like, C#,
> C#.Net, etc.
>
> But When I search with the term “C#” it showing 0 results.
>
> I’m using StandardAnalyzer and MultiFieldQueryParser also allowing
> wildcard search (AllowLeadingWildcard = true).
> Here is my code:
> var analyzer = new StandardAnalyzer(Version.LUCENE_30, stopWords);
> {
> BooleanQuery query = new BooleanQuery();
> var nameParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] {
> "Column1", " Column2", " Column3" }, analyzer);
> if (!string.IsNullOrEmpty(searchCriteria.CourseName))
> {
> query.Add(parseQuery(GetTerms(searchCriteria.CourseName.ReplaceDiacritics()),
> nameParser), Occur.MUST);
> }
> ScoreDoc[] hits = searcher.Search(query, null, hits_limit,
> Sort.RELEVANCE).ScoreDocs;
> var results = _mapLuceneToDataList(hits, searcher);
> analyzer.Close();
> searcher.Dispose();
> return results;
> }
>
> For indexing:
> The word “C#” indexed and stored correctly.
> doc.Add(new Field("Title", sampleData.CourseName, Field.Store.YES,
> Field.Index.ANALYZED));
>
> Kindly let me know what I have to do to retrieve the result when I search
> with the term “C#”.
>
> Thanks & Regards,
> Singaravelu R
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message