in reply to Queries for elastic search using perl

If you want to parse bracketed boolean expressions, write a proper parser. For example, using Marpa::R2:
#! /usr/bin/perl use warnings; use strict; use Data::Dumper; use Marpa::R2; my $dsl = << '__DSL__'; :default ::= action => [values] lexeme default = latm => 1 Expression ::= ('(') Expression (')') action => ::first | Assignment action => ::first | Expression ' & ' Expression | Expression ' | ' Expression Assignment ::= key '=' value key ~ [\w]+ value ~ [\w]+ __DSL__ my $grammar = 'Marpa::R2::Scanless::G'->new({ source => \$dsl }); for my $condition ( '(column08=Submit & column10=Delivered & column09= +Something)', '((column08=Submit & column10=Delivered & column09 +=Something) | (column08=Delivered))', '((column08=Submit & column10=Delivered & column09 +=Something) | (column08=Delivered & column09=Something))', ) { print $condition, "\n"; my $parser = 'Marpa::R2::Scanless::R'->new({ grammar => $grammar +}); $parser->read(\$condition); print Dumper $parser->value; }

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Queries for elastic search using perl
by ravi45722 (Pilgrim) on Jun 29, 2016 at 05:04 UTC

    Its not a boolean expression its just an indication for what we have to do in elastic search.  (column08=Submit & column10=Delivered & column09=Something) If this is the condition I am passing to a function I need output as

    { 'bool'=> { 'must'=> [ { 'term'=> {'column08'=> 'Submit'}}, { 'term'=> {'column10' => 'Delivered'}}, { 'term'=> {'column09' => 'Something'} ] } }
     (column08=Submit | column10=Delivered | column09=Something)
    { 'bool'=> { 'should'=> [ { 'term'=> {'column08'=> 'Submit'}}, { 'term'=> {'column10' => 'Delivered'}}, { 'term'=> {'column09' => 'Something'} ] } }

    Can you help me in this how to do ???