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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:22:41+00:00 2026-06-11T20:22:41+00:00

I have read some tutorials about highlighting search terms in Lucene, and came up

  • 0

I have read some tutorials about highlighting search terms in Lucene, and came up with a piece of code like this:

(...)
query = parser.parse(query_string)

for scoreDoc in  searcher.search(query, 50).scoreDocs:
    doc = searcher.doc(scoreDoc.doc)
    filename = doc.get("filename")
    print filename
    found_paraghaph = fetch_from_my_text_library(filename)

    stream = lucene.TokenSources.getTokenStream("contents", found_paraghaph, analyzer);
    scorer = lucene.Scorer(query, "contents", lucene.CachingTokenFilter(stream))
    highligter = lucene.Highligter(scorer)
    fragment = highligter.getBestFragment(analyzer, "contents", found_paraghaph)
    print '>>>' + fragment

But it all ends with an error:

Traceback (most recent call last):
  File "./search.py", line 76, in <module>
    scorer = lucene.Scorer(query, "contents", lucene.CachingTokenFilter(stream))
NotImplementedError: ('instantiating java class', <type 'Scorer'>)

So, I guess, that this part of Lucene insn’t iplemented yet in pyLucene. Is there any other way to do it?

  • 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-11T20:22:42+00:00Added an answer on June 11, 2026 at 8:22 pm

    I too got similar error. I think this class’s wrapper is not yet implemented for Pylucene v3.6.

    You might want to try the following:

    analyzer = StandardAnalyzer(Version.LUCENE_CURRENT)
    
    # Constructs a query parser.
    queryParser = QueryParser(Version.LUCENE_CURRENT, FIELD_CONTENTS, analyzer)
    
    # Create a query
    query = queryParser.parse(QUERY_STRING)
    
    topDocs = searcher.search(query, 50)
    
    # Get top hits
    scoreDocs = topDocs.scoreDocs
    print "%s total matching documents." % len(scoreDocs)
    
    HighlightFormatter = SimpleHTMLFormatter();
    highlighter = Highlighter(HighlightFormatter, QueryScorer (query))
    
    for scoreDoc in scoreDocs:
        doc = searcher.doc(scoreDoc.doc)
        text = doc.get(FIELD_CONTENTS)
        ts = analyzer.tokenStream(FIELD_CONTENTS, StringReader(text))
        print doc.get(FIELD_PATH)
        print highlighter.getBestFragments(ts, text, 3, "...")
        print ""
    

    Please note that we create token stream for each item in the search result.

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

Sidebar

Related Questions

I have just switched from svn to mercurial and have read some tutorials about
I have read through some tutorials about javascript prototypal inheritance patterns but I am
I have read some posts about this topic and the answers are comet, reverse
I read some tutorials here about properties ,but i still have some doubts to
Have read some great tutorials online about the new storyboarding feature of xcode 4.2.
I have read some of the basic Google Apps Script documentation/tutorials. I have not
I have read some different responses for this same question, so I dont know
I have read some posts on here about not mixing parameters when passing into
I have read some threads regarding this and I did already take steps to
I am new to XPath, and from what I have read in some tutorials

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.