Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account
List archives

Simulating SQL 'LIKE %' using Regular Expressions

NoSql summer
(12 lines)
How do I SUM(values in a field array) using Views
(53 lines)
Jun 1, 2010
Steven.Prentice
Steven.Prentice
Hi, so in my couchDB, what I want to happen is when you query a view in 
the design doc and providing ?key="C" at the end, bring up all shop names 
that start with C.
to do this I have made the following map function:

function(doc) 
{ 

  for (id in doc.Stores)
  {
 
  var strqry = doc.Stores[id]["name"].match(/^.*/);
 
    if (strqry)
    { 
      emit(strqry, doc.product_name + " qty: " + 
doc.Stores[id].item_count);
    }
  } 
}

When I run this from the temp view in Futon, I get a list of all stores 
and products (which made me think 'yay it worked, all it needs is a 
parameter') but when I use:
http://host:5984/db/design/name/_view/function?key="C" I get back: 
{"total_rows":30,"offset":0,"rows":[]}

my ultimate aim is to get it working similar to an SQL Like % so if for 
example I say ?key="C" it will return "Computer Store A" and so on..
I created my function based on this tutorial: 
http://books.couchdb.org/relax/refere...s-for-sql-jockeys




Reply
Tags: functionmap
Messages in this thread
Similar Threads
regular expressions in route starting point "from"
Hi,

are regular expressions supported in route starting point "from"?
I am dealing with ActiveMQ component, I found I can use only "*" and
">",
it would be useful to get more flexibility, do you know if it is possible?

Regards,

Massimo




Regular Expression Extraction
Hi,

I want to reuse data from a server response and therefore attached a 
regexp extractor to the sampler. Unfortunately, this doesnt seem to work 
since I always get the default value although the string is in the 
response data as can be seen in the results tree.

Maybe my expression is just wrong? I want to have a negative number and 
used the following expression: "(-\d*\.{0,1}\d+)"
Template is $1$ and Match No. 1

Am I missing something?

rgds
Karsten


If Controller after Regular Expression
Hello All,

we have a Regular Expression Extractor hat is supposed to find an ID out
of the loaded page. This works (unless there is no ID on the page) which is
the correct behaviour.

We then want to open the record pointed to by the ID we found iff we
actually found a record.

So in the regular expression extractor we put 
Reference Name:aktenzeichen
Regular expression:familie\.do\?id=(\d+)
Template:$1$
Match No.:0
Default value:NoAzFound

And in the If Controller we have the condition
${aktenzeichen} != 'NoAzFound'

I've tried with double quotes, single quotes, no quotes and always get
errors like this in the log:

2010/07/26 12:16:55 ERROR - jmeter.control.IfController: ReferenceError:
"NoAzFound" is not defined. (<cmd>#1)
org.mozilla.javascript.EcmaError: ReferenceError: "NoAzFound" is not
defined. (<cmd>#1)
        at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)
        at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)
        at
org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3292)
        at
org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1570)
        at org.mozilla.javascript.gen.c2._c0(<cmd>:1)
        at org.mozilla.javascript.gen.c2.call(<cmd>)
        at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
        at
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
        at org.mozilla.javascript.gen.c2.call(<cmd>)
        at org.mozilla.javascript.gen.c2.exec(<cmd>)
        at
org.mozilla.javascript.Context.evaluateString(Context.java:1132)
        at
org.apache.jmeter.control.IfController.evaluateCondition(IfController.java:105)
        at
org.apache.jmeter.control.IfController.next(IfController.java:162)
        at
org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:184)
        at
org.apache.jmeter.control.GenericController.next(GenericController.java:148)
        at
org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:184)
        at
org.apache.jmeter.control.GenericController.next(GenericController.java:148)
        at
org.apache.jmeter.control.LoopController.next(LoopController.java:108)
        at
org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:72)
        at
org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:242)
        at java.lang.Thread.run(Thread.java:619)

What am I doing wrong?




Mit freundlichen Grüßen
Jörg Godau

SCHÜTZE Consulting Informationssysteme GmbH Argentinische Allee 22b
14163 Berlin
Tel.: 030/ 802 49 44
Fax: 030/ 8090 39 95
www.schuetze-berlin.de

Geschäftsführer: Klaus-Dieter Schütze
Registergericht: Amtsgericht Charlottenburg
Registernummer: HRB 73618
Umsatzsteuer-Identifikationsnummer gemäß § 27a Umsatzsteuergesetz: DE
813181239




Map function with regular expression
Hi,

Ive got a document containing an array and want to perform a regex on an 
array item called name, it is located in the Stores field

what ive got at the moment is...

function(doc) 
{ 

  for (id in doc.Stores)
  {
    //regular expression to ensure a store name starts with "C" and ends 
with "k"
    var strqry = doc.Stores[id].name.match(/^C([a-z]*)k/);
 
    if (strqry)
    { 
      emit(doc.Stores[id].name, doc.product_name + " qty: " + 
doc.Stores[id].item_count);
    }
  } 
}

a javascript regex validator told me that that regex is correct, I think 
it may be something wrong with the way that I am pointing the regex to the

"stores[id].name"

Cheers :)

Need Help on Regular expression extractor
Hi,

I would like to extract 2 strings(marked in bold) from the following
string

"custo_download_file?file_name=<b
RRRR105231_C_83_002_4.TIF&file_handle_name=MTIObjectHandle-0002-1~R~kjocPHjCH-BadCORPDB--kkz~T2TIFF~CORPDB~~"
target="_self">HTCT105231_C_83_002_4.TIF </TD>

Please help.




Filter property value with regular expression
Hello,

I haven't been able to find a way to filter the value of a property with
regular expressions. Is there any way to do it with Ant 1.7?

I need something like this, but without using 3rd party dependencies:
http://ant-contrib.sourceforge.net/ta...ropertyregex.html

Basically, I just want to keep the alphanumeric characters in a
property, ignoring punctuation marks and other things.

Thanks in advance.





Can we filter a key or a column name using regular expression?
Hi,
I need to build a mode where I can retrieve an ordered list of objects
sharing the same prefix and contains a certain delimiter.

For example:  Get all the object names that start with 'root' and
contain '/' in it,
given the names:
ro### @abc/ddd
ro### @bbb/c
ro### @pppp

should return the first two names (roo### @abc/ddd  ro### @bbb/c)

I can build the model such that the a lot object name is a key or a column
name.
Can we  retrieve a key or a column name using such filter or other
regular expression-like filters?
Thanks and I will appreciate  you help,
Miriam


Help needed for regular expression extractor
Hi All,

Can anyone help me what would be the solution for following scenario?

Step1: There are two responses get generated (say x.aspx and y.aspx) upon
a 
request.

The value of the Location parameter in the header of x.aspx(POST Method) 
contains: y.aspx?ID=abcdf

y.aspx contains the send parameter as -> ID

Jmeter does not capture the value of the Location  parameter in the header
of 
x.aspx during the recording(I found the header details of x.aspx contains 
Location parameter using Fiddler).

How can I capture the value of variable ID using regular expression from
the 
header of x.aspx and assign it in the send parameters of y.aspx?


Any help to get the solution will be appreciated.

Thanks,
Prakash



JXPath Boolean Expressions
Hi,

I have the following snippet to evaluate a boolean expression from a map,

Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", false);
System.err.println(JXPathContext.newContext(map).getValue("foo = false"));

The above seems to be printing false instead of true.

Kind regards
Meeraj


Re: custom expressions / registering functions
Hi,
JEXL should be appropriate feature-wise; adding EL capabilities to a
framework is one of its intents.

JEXL 2.0 allows to invoke any method on an object accessible through the
evaluation context.
It also allows to register functions in namespaces achieved by mapping the
namespace name to an instance or a class - if all methods are static.

<code>
            public static MyMath {
                public double cos(double x) {
                    return Math.cos(x);
                }
            }
            Map<String, Object> funcs = new HashMap<String,
Object>();
            funcs.put("math", new MyMath());
            JexlEngine jexl = new JexlEngine();
            jexl.setFunctions(funcs);

            JexlContext jc = new MapContext();
            jc.set("pi", Math.PI);

            e = JEXL.createExpression("math:cos(pi)");
            o = e.evaluate(jc);
            assertEquals(Double.valueOf(-1),o);
</code>

Useful links on the topic:
http://commons.apache.org/jexl/index.html
http://commons.apache.org/jexl/reference/syntax.html  (method calls,
functions)
http://commons.apache.org/jexl/apidocs/index.html

Follow-up if things aren't clear enough;
Regards
Henrib




Re: custom expressions / registering functions
Adrian Herscu wrote:

 Hi all,
 
 I am looking for an expression language to using in a testing
framework
 that I am designing.
 
 The requirement is that the users of the framework are allowed to
define
 their own functions. I could not find it possible to add a function
to a
 JEXL context. Is there any other mechanism?

Why don't you simply use the JavaScript engine (JSR 223)? It comes out of 
the box with Java 6 (including Rhino) and for earlier JDKs you can use 
Apache BSF (http://jakarta.apache.org/bsf/) that implements also JSR 223
and 
provides therefore a smooth upgrade path. With the embedded JavaScript of 
Rhino you can access easily also all Java stuff.

- Jörg



Re: custom expressions / registering functions
Le 25-mai-10 à 06:40, Adrian Herscu a écrit :
 On 24/05/2010 22:52, Paul Libbrecht wrote:
> Jexl containers allow you to add objects.

 Can you, please, send a link for more info?

> At least jelly does.

Jelly is at... commons-jelly:
	http://commons.apache.org/jelly/
some other projects use jexl, especially newer version of it,  
including scxml.

paul



Re: custom expressions / registering functions

On 24/05/2010 22:52, Paul Libbrecht wrote:
 Jexl containers allow you to add objects.

Can you, please, send a link for more info?

 At least jelly does.

 And invoking methods on these functions sounds like an easy thing.

 paul


 Le 23-mai-10 à 15:39, Adrian Herscu a écrit :

> Hi all,
>
> I am looking for an expression language to using in a testing
> framework that I am designing.
>
> The requirement is that the users of the framework are allowed to
> define their own functions. I could not find it possible to add a
> function to a JEXL context. Is there any other mechanism?
>
> Please help,
> Adrian.
>
>
> 
Created: (CAMEL-2823) Cron expressions as option in 'from' URIs.
Cron expressions as option in 'from' URIs.

Created: (DERBY-4720) Allow boolean-valued expressions in select lists
Allow boolean-valued expressions in select lists

Created: (CAMEL-2759) Add support for Camel expressions in <xpath> in Spring DSL
Add support for Camel expressions in <xpath> in Spring DSL

Using Regular Expression Extractor to extract the "id"
Hi

I'm using Jmeter since one month...In learning process.... the scenario is
like this..... I login as Org admin and create an user......As soon i
create
an User in return value it creates an User ID which i'll be using it for
further HTTP requests.... The problem am facing is i'm unable to fetch the
"syntax" to be used in the regular expression extractor....

-----
http://172.18.10.1:3128/Web/performAc...ageUser&id=30
&_tabId_orgUserGrid=orgUserGrid_Users&showOrgUserMode=addMode
-----

The above url is the path which is coming while i create the user..... The
"id=30" is the Org id......... Now in order to extract the id i use a
regular expression extractor. I make the following settings.....
                            Response Field to check : URL
                            Regular Expression         : (\d+)

Its not working..... Can anyone tell me a possible solution please ??

Regards