Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:54:45+00:00 2026-05-28T07:54:45+00:00

Q1: I am making a search using Lucene. Everything works fine and quickly. When

  • 0

Q1: I am making a search using Lucene. Everything works fine and quickly. When I tried to search for the phrase “.net”, it didn’t find anything. Maybe you know how can I cope with this.

Q2: How can I search and ignore case?

Update 1

Q1:I am saving jobs using SimpleLucene. Here is the code:

DirectoryIndexWriter _indexWriter = new DirectoryIndexWriter(new DirectoryInfo(indexPath), true);
using (var indexService = new IndexService(_indexWriter))
{
   var result = indexService.IndexEntities(jobsTempArray, new JobIndexDefinition());
   Console.WriteLine("{0} products indexed in {1} milliseconds.", result.Count, result.ExecutionTime);
}

JobIndexDefinition file:

public class JobIndexDefinition : IIndexDefinition<LucenceJobModel>
{
    public Document Convert(LucenceJobModel job)
    {
        var document = new Document();

        document.Add(new Field("jobtitle", job.JobTitle, Field.Store.YES, Field.Index.ANALYZED));
        document.Add(new Field("AreaCode", job.AreaCode.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("Company", job.Company, Field.Store.YES, Field.Index.NOT_ANALYZED));
        var dateValue = DateTools.DateToString(job.DatePosted.Value, DateTools.Resolution.MILLISECOND);
        document.Add(new Field("DatePosted", dateValue, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("Description", job.Description, Field.Store.YES, Field.Index.ANALYZED));
        document.Add(new Field("Expierence", job.Expierence, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("JobType", job.JobType, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("Link", job.Link, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("LinkId", job.LinkId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("Location", job.Location, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("PayRate", job.PayRate, Field.Store.YES, Field.Index.NOT_ANALYZED));

        document.Add(new Field("Source", job.Source, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("TaxTerm", job.TaxTerm, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("Term", job.Term, Field.Store.YES, Field.Index.NOT_ANALYZED));
        document.Add(new Field("Title", job.Title, Field.Store.YES, Field.Index.NOT_ANALYZED));

        return document;
    }

    public Term GetIndex(LucenceJobModel job)
    {
        return new Term("Link", job.Link);
    }
}

I am searching for JobTitle, Description and DatePosted fields. Here is the search code:

public List<LucenceJobModel> JobsSearch(string keyword, string location, PageInfo pageInfo)
{
    string[] words = keyword.Split(new[] { ' ' });

    IndexReader reader = IndexReader.Open(SmartSearch.Instance.GetDirectory(), true);
    var searcher = new IndexSearcher(reader);

    var standardAnalyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
    var fields = new[] { "JobTitle", "Description", "DatePosted" };

    var searchQuery = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, fields, standardAnalyzer);
    //searchQuery.SetAllowLeadingWildcard(true);

    // perform the search
    var query = new BooleanQuery();

    foreach (var word in words)
    {
        if (!String.IsNullOrEmpty(word))
        {
            var qTemp = searchQuery.Parse(word);
            var q = searchQuery.Parse(qTemp.ToString().Substring(qTemp.ToString().LastIndexOf(":") + 1) + "*");
            query.Add(q, BooleanClause.Occur.MUST);
        }
    }

    int maxDocs = 1;
    if (reader.MaxDoc() > 0)
        maxDocs = reader.MaxDoc();

    var results = searcher.Search(query, filter, maxDocs);
    foreach (var scoreDoc in results.scoreDocs)
    {
        var document = searcher.Doc(scoreDoc.doc);
    }

    var jobs = new List<LucenceJobModel>();
    for (int i = 0; i < results.scoreDocs.Length; i++)
    {
        var document = searcher.Doc(results.scoreDocs[i].doc);
        if (i >= (pageInfo.CurrentPage - 1) * pageInfo.ItemsPerPage && i < pageInfo.CurrentPage * pageInfo.ItemsPerPage)
        {
            jobs.Add(LucenceJobModel.ConvertFromDoc(document));
        }

        itemsForGroup.Add(new ItemGroupFor
            {
                Company = document.GetField("Company").StringValue(),
                DatePosted = DateTools.StringToDate(document.GetField("DatePosted").StringValue()),
                JobType = document.GetField("JobType").StringValue(),
                Location = document.GetField("Location").StringValue(),
                Source = document.GetField("Source").StringValue(),
                Title = document.GetField("Title").StringValue()
            });
    }

    pageInfo.TotalItems = results.scoreDocs.Length;
    return jobs;
}

I want to be able to search for keywords such as “C#” or “.net” without deleting “#” or “.”.

Q2: I am searching in Location field. Here is code:

public List<string> GetLocations(string term)
{
    IndexReader reader = IndexReader.Open(SmartSearch.Instance.GetDirectory(), true);
    var searcher = new IndexSearcher(reader);

    var standardAnalyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
    QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Location", standardAnalyzer);
    string str = parser.Parse(term).ToString().Substring(parser.Parse(term).ToString().LastIndexOf(":") + 1);

    PrefixQuery q = new PrefixQuery(new Term("Location", string.Format("{0}", str)));

    TopDocs results = searcher.Search(q, 5000);

    return results
                .scoreDocs
                .Select(x => searcher.Doc(x.doc))
                .Select(x => x.GetField("Location").StringValue())
                .Distinct()
                .ToList();
}

I want to search for “New york”, “New York” and so on. But I know it searches only if case is right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:54:45+00:00Added an answer on May 28, 2026 at 7:54 am

    I’m not familiar with “SimpleLucene” but your code looks a lot more complex than it needs to be.

    A few things:

    Field names are case-sensitive, you store the job title as “jobtitle” but search for it using “JobTitle”. They need to match.

    You mentioned that you want to search the DatePosted and Location fields but they are “NOT_ANALYZED” in the code you posted. Change it to “ANALYZED” if you want to search those fields.

    Try the whitespace analyzer if you want to keep terms like “.net” and “C#”. Keep in mind that the whitespace analyzer does not use the lowercase filter, so a search for “.NET” wont match “.net”. You may have to write your own analyzer.

    A1: All of the built in Analyzers (except keyword and whitespace) strip the period from a term, so it shouldn’t matter if you search for: “net”, “.net”, “.net”, …net…”, etc.. If this isn’t the case, there’s another problem. Post some code and maybe we can help.

    If you need to match terms like “.net” and “C#” you will probably have better luck with the Whitespace Analyzer. If that doesn’t meet your needs you will probably have to write your own analyzer.

    A2: The Standard Analyzers automatically converts upper-case to lower case, so case is already ignored for you.

    This page has good examples of what the various Analyzers do to a phrase.

    From the page above:

    Analzying “The quick brown fox jumped over the lazy dogs”

    org.apache.lucene.analysis.WhitespaceAnalyzer:
        [The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dogs] 
    
    org.apache.lucene.analysis.SimpleAnalyzer:
        [the] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dogs] 
    
    org.apache.lucene.analysis.StopAnalyzer:
        [quick] [brown] [fox] [jumped] [over] [lazy] [dogs] 
    
    org.apache.lucene.analysis.standard.StandardAnalyzer:
        [quick] [brown] [fox] [jumped] [over] [lazy] [dogs] 
    
    org.apache.lucene.analysis.snowball.SnowballAnalyzer:
        [quick] [brown] [fox] [jump] [over] [lazi] [dog] 
    

    Analzying “XY&Z Corporation – xyz@example.com“

       org.apache.lucene.analysis.WhitespaceAnalyzer:
            [XY&Z] [Corporation] [-] [xyz@example.com] 
    
        org.apache.lucene.analysis.SimpleAnalyzer:
            [xy] [z] [corporation] [xyz] [example] [com] 
    
        org.apache.lucene.analysis.StopAnalyzer:
            [xy] [z] [corporation] [xyz] [example] [com] 
    
        org.apache.lucene.analysis.standard.StandardAnalyzer:
            [xy&z] [corporation] [xyz@example] [com] 
    
        org.apache.lucene.analysis.snowball.SnowballAnalyzer:
            [xy&z] [corpor] [xyz@exampl] [com] 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server 2000 and ASP.Net with c# for making a search
I am making search job site using Lucene, and coped with such problem. I
I'm making an Online Library Management System using ASP.NET (with C#). So far everything
I'm making a site in php and I'm using google custon search for my
So I'm using jqGrid with my mvc.net / Ling2Sql prototype site that I'm making
I am programming with Visual Studio 2008 and making a web application using .NET
I have been working on making a Search using Solrnet which is working the
I'm making an app on PhoneGap using Jquery Mobile. The app runs fine on
I am trying to setup a search engine using Solr (or Lucene) which could
I'm making a simple search form in rails. In my search view I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.