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

  • Home
  • SEARCH
  • 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 6596743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:06:56+00:00 2026-05-25T18:06:56+00:00

I am looking for a way to find the terms that matched in the

  • 0

I am looking for a way to find the terms that matched in the document using waldcard search in Lucene. I used the explainer to try and find the terms but this failed. A portion of the relevant code is below.

ScoreDoc[] myHits = myTopDocs.scoreDocs;
int hitsCount = myHits.Length;
for (int myCounter = 0; myCounter < hitsCount; myCounter++)
{
    Document doc = searcher.Doc(myHits[myCounter].doc);
    Explanation explanation = searcher.Explain(myQuery, myCounter);
    string myExplanation = explanation.ToString();
    ...

When I do a search on say micro*, documents are found and it enter the loop but myExplanation contains NON-MATCH and no other information.

How do I get the term that was found in this document ?

Any help would be most appreciated.

Regards

  • 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-25T18:06:57+00:00Added an answer on May 25, 2026 at 6:06 pm
        class TVM : TermVectorMapper
        {
            public List<string> FoundTerms = new List<string>();
            HashSet<string> _termTexts = new HashSet<string>();
    
            public TVM(Query q, IndexReader r) : base()
            {
                List<Term> allTerms = new List<Term>();
                q.Rewrite(r).ExtractTerms(allTerms);
                foreach (Term t in allTerms) _termTexts.Add(t.Text());
            }
    
            public override void SetExpectations(string field, int numTerms, bool storeOffsets, bool storePositions)
            {
            }
    
            public override void Map(string term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
            {
                if (_termTexts.Contains(term)) FoundTerms.Add(term);
            }
        }
    
        void TermVectorMapperTest()
        {
            RAMDirectory dir = new RAMDirectory();
            IndexWriter writer = new IndexWriter(dir, new Lucene.Net.Analysis.Standard.StandardAnalyzer(), true);
            Document d = null;
    
            d = new Document();
            d.Add(new Field("text", "microscope aaa", Field.Store.YES, Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS));
            writer.AddDocument(d);
    
            d = new Document();
            d.Add(new Field("text", "microsoft bbb", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
            writer.AddDocument(d);
    
            writer.Close();
    
            IndexReader reader = IndexReader.Open(dir);
            IndexSearcher searcher = new IndexSearcher(reader);
    
            QueryParser queryParser = new QueryParser("text", new Lucene.Net.Analysis.Standard.StandardAnalyzer());
            queryParser.SetMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE); 
            Query query = queryParser.Parse("micro*");
    
            TopDocs results = searcher.Search(query, 5);
            System.Diagnostics.Debug.Assert(results.TotalHits == 2);
    
            TVM tvm = new TVM(query, reader);
            for (int i = 0; i < results.ScoreDocs.Length; i++)
            {
                Console.Write("DOCID:" + results.ScoreDocs[i].Doc + " > ");
                reader.GetTermFreqVector(results.ScoreDocs[i].Doc, "text", tvm);
                foreach (string term in tvm.FoundTerms) Console.Write(term + " ");
                tvm.FoundTerms.Clear();
                Console.WriteLine();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a way to find a Guid within a string that
I'm looking for an existing semi-decent software that can highlight multiple search terms simultaneously,
I am using Lucene's Highlighter class to highlight fragments of matched search results and
we are looking for a way to find out (not modify, just find out)
I'm looking for a way to find/replace links to images (within user-generated content) without
I'm looking for a way to find the number of hours of difference between
I'm coming to Postgres from Oracle and looking for a way to find the
Trouble! I'm looking for a way to find the countries within a given range
I'm looking for an easy way to find the process tree (as shown by
I am looking to find a way to programatically (C++) control/secure access to the

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.