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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:32:53+00:00 2026-05-19T13:32:53+00:00

I have following piece of code: CompassQuery suggested = hits.getSuggestedQuery() String displayedSuggestion = suggested.toString();

  • 0

I have following piece of code:

CompassQuery suggested = hits.getSuggestedQuery()
String displayedSuggestion = suggested.toString();

If just do that I get nasty string with aliases and query operators: +(alias:item) field:keyword1 OR field:keyword2

How do I get simple sitring like this?:

keyword1 keyword2
  • 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-19T13:32:53+00:00Added an answer on May 19, 2026 at 1:32 pm

    I had this same problem myself recently. The only way I could make it work reliably was code like this:

    import static org.apache.commons.lang.StringUtils.*;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.lucene.index.Term;
    import org.apache.lucene.search.Query;
    import org.compass.core.CompassQuery;
    import org.compass.core.engine.SearchEngineException;
    import org.compass.core.engine.SearchEngineQuery;
    import org.compass.core.impl.DefaultCompassQuery;
    import org.compass.core.lucene.engine.LuceneSearchEngineQuery;
    import org.compass.core.lucene.engine.queryparser.QueryParserUtils;
    
    public class SearchTermExtractor {
    
    public String extract(CompassQuery compassQuery, final String fieldName) {
        SearchEngineQuery searchEngineQuery = ((DefaultCompassQuery)compassQuery).getSearchEngineQuery();
        Query luceneQuery = ((LuceneSearchEngineQuery)searchEngineQuery).getQuery();
    
        final List<String> suggestedTerms = new ArrayList<String>();
    
        // Use a visitor to extract the terms
        QueryParserUtils.visit(luceneQuery, new QueryParserUtils.QueryTermVisitor() {
            @Override
            public Term replaceTerm(Term term) throws SearchEngineException {
                if (fieldName.equals(term.field())) {
                    suggestedTerms.add(term.text());
                }
                // Just return the original term, we're not trying to modify the query itself
                return term;
            }
        });
    
        return join(suggestedTerms, ' '); // join is from Commons Lang StringUtils
    }
    
    }
    

    The fieldName parameter is the field used for the terms you want to extract (field in your example).

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

Sidebar

Related Questions

I have following piece of code : public Hashmap<String,String> tempmap = new HashMap<String,String>(); and
I have the following piece of code that takes in some words, stores them
I have the following piece of code that generate a jquerymobile-style button <a href=#
I have the following piece of code that pulls an image URL from a
I have the following piece of code that works well in Windows Server 2003.
I have the following piece of code, just wanted to check who will call
I have the following piece of code that is taken from a mock exam
I have the following piece of code (only relevant parts): xhttp=new XMLHttpRequest(); xhttp.open(GET,doc_name,false); xhttp.send();
I have this following piece of code: public TimestampedRowStorage GetTimestampedRowStorage(string startTime, string endTime, long
I have following piece of code: byte[] snapthotBytes, snapthotBytes2; string stringOutput, stringOutput2; IInvestigationDump investigationDump

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.