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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:28:09+00:00 2026-06-10T18:28:09+00:00

I am doing project using Lucen library in here I need to build query

  • 0

I am doing project using Lucen library in here I need to build query dynamically using Json object. so in here I use jettison library. as an example my json like this

{"OR":{"OR": {"fildKey1": "value1","fildKey2": "value2","fildKeyabc": "valueabc"},"AND": {"AND": {"fildKey3": "value3","OR": {"fildKey4": "value4","fildKey5": "value5"}},"fildKeyw": "valuew"}}}

using above json I need to create following query

(( fildKey1 : value1 OR fildKey2 : value2 OR fildKeyabc : valueabc )OR(( fildKey3 : value3 AND( fildKey4 : value4 OR fildKey5 : value5 ))AND fildKeyw : valuew ))

but I can’t get the above query.my result is like this

(( fildKey1 : value1 OR fildKey2 : value2 OR fildKeyabc : valueabc )OR(( fildKey3 : value3 AND( fildKey4 : value4 OR fildKey5 : value5 )AND)AND fildKeyw : valuew )OR)

I need to remove above extra 2 operators this is my code

public class JettisionCls {
   static Stack s = new Stack();
   String operater = null;
   static String res = "";
   int bracket_counter = 0;   


public void getKeyAndValue(JSONObject json_obj) throws JSONException{
    Iterator<String> iter = json_obj.keys();

    while (iter.hasNext()) {
        String obj = iter.next();
        if(obj.toLowerCase().equals("and") || obj.toLowerCase().equals("or")){
            //System.out.print(obj);
            operater = obj;              
        }

        JSONObject temp = null;
        try {
            temp = new JSONObject(json_obj.get(obj).toString());
        } catch (JSONException e) {
            e.getStackTrace();
        }

        if (temp != null) {
            //System.out.print("(");
            res = res +"(";
            bracket_counter=bracket_counter+1;
            s.push(operater);

            getKeyAndValue(temp);

            //System.out.print(")");
            res = res +")";
            bracket_counter=bracket_counter-1;                          
            if((s.size()) != 0 && bracket_counter != 0){
                //System.out.print(s.peek());
                s.pop();
                res = res +s.peek(); 
            }
            else{
                s.pop();
            }
        }            
        else{
            if(iter.hasNext()){
                res = res+" "+obj + " : " + json_obj.get(obj) + " " + operater;                                    }
            else{
                res = res+" "+obj + " : " + json_obj.get(obj)+" ";
            }
        }
    }
}

my main method look like this

String multiLevelQuery = "{\"OR\":{\"OR\": {\"fildKey1\": \"value1\",\"fildKey2\": \"value2\",\"fildKeyabc\": \"valueabc\"},\"AND\": {\"AND\": {\"fildKey3\": \"value3\",\"OR\": {\"fildKey4\": \"value4\",\"fildKey5\": \"value5\"}},\"fildKeyw\": \"valuew\"}}}";

JSONObject jobj = new JSONObject(multiLevelQuery);
JettisionCls obj = new JettisionCls();
obj.getKeyAndValue(jobj);
System.out.println(JettisionCls.res);

if anyone can please help me.

  • 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-10T18:28:11+00:00Added an answer on June 10, 2026 at 6:28 pm

    I think you can do this using string replacement.

    public void createQry(String s){
        String temp = s;
    
        if(temp.contains(")OR)")){
            temp = temp.replace(")OR)", "))");
        }
        if(s.contains(")AND)")){
            temp = temp.replace(")AND)", "))");
        }
        System.out.println(temp);        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing project on object detection using javacv in that I went through couple
I'm using WCF Services for a project I'm doing, where the Service will query
I'm doing a project using FLARManager augmented reality and the Papervision3D library. Unfortunately, Papervision
I am doing a small project using JPA. I need to insert the employee
I am doing project in vb.net using ms access database I used one query
I was doing a project using bing maps and need to draw something on
I am doing my first project using Ruby on Rails and need to display
I am doing project using Java and in that I need to reload whole
I'm doing i18n for a php project using gettext. I'd like to use the
I am doing project on heart disease prediction system. here am using Cleveland Heart

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.