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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:32:59+00:00 2026-06-14T07:32:59+00:00

I am trying to index into a document a field with one term that

  • 0

I am trying to index into a document a field with one term that has a payload.
Since the only constructor of Field that can work for me takes a TokenStream, I decided to inherit from this class and give the most basic implementation for what I need:

public class MyTokenStream : TokenStream
{
    TermAttribute termAtt;
    PayloadAttribute payloadAtt;
    bool moreTokens = true;
    public MyTokenStream()
    {
        termAtt = (TermAttribute)GetAttribute(typeof(TermAttribute));
        payloadAtt = (PayloadAttribute)GetAttribute(typeof(PayloadAttribute));
    }
    public override bool IncrementToken()
    {
        if (moreTokens)
        {
            termAtt.SetTermBuffer("my_val");
            payloadAtt.SetPayload(new Payload(/*bye[] data*/));
            moreTokens = false;
        }

        return false;
    }     
}

The code which was used while indexing:

        IndexWriter writer = //init tndex writer...

        Document d = new Document();
        d.Add(new Field("field_name", new MyTokenStream()));
        writer.AddDocument(d);
        writer.Commit();

And the code that was used during the search:

        IndexSearcher searcher = //init index searcher
        Query query = new TermQuery(new Term("field_name", "my_val"));
        TopDocs result = searcher.Search(query, null, 10);

I used the debugger to verify that call to IncrementToken() actually sets the TermBuffer.
My problem is that the returned TopDocs instance returns no documents, and I cant understand why… Actually I started from TermPositions (which gives me approach to the Payload…), but it also gave me no results.
Can someone explain to me what am I doing wrong?
I am currently using Lucene .NET 2.9.2

  • 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-14T07:33:00+00:00Added an answer on June 14, 2026 at 7:33 am

    After you set the TermBuffer you need to return true from IncrementToken, you return false when you have nothing to feed the TermBuffer with anymore

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

Sidebar

Related Questions

I am trying to integrate iTextSharp into an existing Document Imaging application that allows
I'm trying to extract the text for a document to index it for search.
I'm trying to index a very small (6 rows) table into solr, and it
I am trying to implement fancybox and jqueryui's accordion into my site, I can
This is what I am trying to accomplish: location.replace('http://localhost:8888/test/index.php?site=' + document.URL); So I need
I have several document collections that occasionally need to be pulled together into a
I am trying to index a table for full text search in a SQL
I am getting the following errors when i am trying to index the SVN
I'm having the following error returned when trying to index the product prices... 2012-03-16T17:05:57+00:00
I am trying to get index of each items in a listbox Here is

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.