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 8228219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:23:26+00:00 2026-06-07T16:23:26+00:00

I was looking for good code for searching index using lucene.net. i got one

  • 0

I was looking for good code for searching index using lucene.net. i got one look promising but i got some confusion. if possible anyone who is familiar with lucene.net then please have look at the code and tell me why the person construct that code in that way.

from where i got the code…url as follows
http://www.codeproject.com/Articles/320219/Lucene-Net-ultra-fast-search-for-MVC-or-WebForms

here is code

private static IEnumerable<SampleData> _search
(string searchQuery, string searchField = "") {
// validation
if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<SampleData>();

// set up lucene searcher
using (var searcher = new IndexSearcher(_directory, false)) {
    var hits_limit = 1000;
    var analyzer = new StandardAnalyzer(Version.LUCENE_29);

    // search by single field
    if (!string.IsNullOrEmpty(searchField)) {
        var parser = new QueryParser(Version.LUCENE_29, searchField, analyzer);
        var query = parseQuery(searchQuery, parser);
        var hits = searcher.Search(query, hits_limit).ScoreDocs;
        var results = _mapLuceneSearchResultsToDataList(hits, searcher);
        analyzer.Close();
        searcher.Close();
        searcher.Dispose();
        return results;
    }
    // search by multiple fields (ordered by RELEVANCE)
    else {
        var parser = new MultiFieldQueryParser
            (Version.LUCENE_29, new[] { "Id", "Name", "Description" }, analyzer);
        var query = parseQuery(searchQuery, parser);
        var hits = searcher.Search
        (query, null, hits_limit, Sort.RELEVANCE).ScoreDocs;
        var results = _mapLuceneSearchResultsToDataList(hits, searcher);
        analyzer.Close();
        searcher.Close(); 
        searcher.Dispose();
        return results;
    }
}
} 

i have couple of question here for the above routine

1) why the developer of this code replace all * & ? to empty string in search term
2) why search once with QueryParser and again by MultiFieldQueryParser
3) how developer detect that search term has one word or many words separated by space.
4) how wild card search can be done using this code....where to change in code for handling wild card.

5) how to handle search for similar word like if anyone search with helo then hello related result should come.

var hits = searcher.Search(query, 1000).ScoreDocs;

6) when my search result will return 5000 record and then if i limit like 1000 then how could i      show next 4000 in pagination fashion.what is the object for giving the limit...i think for    fastness but if i specify limit the how can i show other results....what would be the logic

i will be glad if someone discuss about all my points. thanks

  • 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-06-07T16:23:28+00:00Added an answer on June 7, 2026 at 4:23 pm

    1) why the developer of this code replace all * & ? to empty string in
    search term

    Because those are special characters for wildcard search. What the author does – he checks if a search query has something else along with wildcards. You don’t usually want to search for “*”, for example.

    2) why search once with QueryParser and again by
    MultiFieldQueryParser

    He doesn’t search with QueryParsers per se, but he’s parsing a search query (string) and making a bunch of objects out of it. Those objects are then consumed by a Searcher object, which performs actual search.

    3) how developer detect that search term has one
    word or many words separated by space.

    That’s something a Parser object should care about, not the developer.

    4) how wild card search can be
    done using this code….where to change in code for handling wild
    card.

    The wildcards are specified in a searchQuery parameter. Specifying “test*” will count as a wildcard, for example. Details are here.

    5) how to handle search for similar word like if anyone search with
    helo then hello related result should come.

    I think you want a fuzzy search.

    6) when my search result will return 5000 record and then if i limit
    like 1000 then how could i show next 4000 in pagination
    fashion.what is the object for giving the limit…i think for
    fastness but if i specify limit the how can i show other
    results….what would be the logic

    Here’s an article about that.

    UPD: About multiple fields. Logic is following:

    • If searchField is specified, than use simple parser, that will produce query like searchField: value1 seachField: value2... etc.
    • If, however that parameter isn’t there, then it assumes, that passed searchQuery will specify fields and values like "field1: value1 field2: value2". Example is on the same syntax page, as I previously mentioned.

    UPD2: Don’t hesitate to look for Java documentation and examples for Lucene, as this is initially a Java project (hence, there’s a lot of Java examples and tutorials). Lucene.NET is a ported project and both projects share a lot of functionality and classes.

    UPD3: About fuzzy search, you might also want to implement your own analyzer for synonyms search (we used that technique in one of commercial projects, which I worked on, to handle common typos along with synonyms).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone got to some good code to zoom into an image using javascript?
I'm looking for some good Lua code 'tester' online, where I could paste my
I've been looking to read some ruby code(specifically Rails) but I don't want to
I'm looking for some good sample code to toggle mirroring in AVCaptureVideoPreviewLayer. The original
I'm interested in speed, not good looking code, that is why I'm using array
Good evening. I am looking at developing some code that will collect EXIF data
How to make this subqueries to good-looking code? And I looking guides about SQL
I'm looking for good tutorial or really simple code to integrate mongokit and django
I'm looking for a good and useful code example that would be nice, short
I'm looking for a good T-SQL Pretty Printer so that all the code looks

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.