Lucene query: exact match

2,474 views
Skip to first unread message

Xander Steinmann

unread,
Feb 6, 2014, 8:36:13 AM2/6/14
to dot...@googlegroups.com
Hi,

I want to execute a lucene query that gives me an exact match on the field that I'm looking for, not a "contains". For instance, I've created 2 pieces of generic content: one is called "hello", the other one "hello world". When I query on "hello" I get 2 pieces of content since the query automatically adds * to it. But even when replaced with "" it still returns 2 items. How can I get it to retrieve the exact match so my result has only 1 item?

I've already tried the following:
+structureName:webPageContent +(conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST) +webPageContent.title:"hello" +languageId:1* +deleted:false +working:true
+structureName:webPageContent +(conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST) +webPageContent.title:*hello* +languageId:1* +deleted:false +working:true

Kind regards,

Xander

Jason Tesser

unread,
Feb 6, 2014, 8:53:27 AM2/6/14
to dot...@googlegroups.com
FWIW you said this " I get 2 pieces of content since the query automatically adds * to it"

It isn't the * that makes this happen. THat is not how most FTS works  nor is it how dotcms works.  The analyzer is a White Space analyzer. So each word is a complete token. 

You can exclude the world with a - in the query and not a plus but that probably doesn't help moving forward. But things like that are the way. The complete token is hello in both cases cause it is a word and searching for an exact match on hello with a white space analyzer will match both hello and hello world 

Falzone, Chris

unread,
Feb 6, 2014, 9:41:43 AM2/6/14
to dot...@googlegroups.com
You cannot is the short answer.  You can't do exact searching in dotCMS.  It has to do with how the content is indexed.   So +field:"hello"  

Will match all of the following:

hello
Hello
Hello World
I want to say heLLO

But not the following:
Helloworld

What you can do is put a conditional on the loop to look for exact.  


On Thu, Feb 6, 2014 at 8:36 AM, Xander Steinmann <xan...@isaac.nl> wrote:

--
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To post to this group, send email to dot...@googlegroups.com.
Visit this group at http://groups.google.com/group/dotcms.
For more options, visit https://groups.google.com/groups/opt_out.



--

Christopher Falzone

Interactive Developer


A Q U E N T

Digital, Creative, and Marketing Talent


aquent.com

cfal...@aquent.com

Kivi Shapiro

unread,
Feb 6, 2014, 9:51:32 AM2/6/14
to dot...@googlegroups.com
A conditional on the loop is a good idea.  So that might look something like this:

#set($myTitle = "hello")
#foreach($con in $dotcontent.pull("+structureName:webPageContent +(conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST) +webPageContent.title:$myTitle +languageId:1* +deleted:false +working:true",10,"modDate desc"))
    #if($con.title==$myTitle) ## Lucene doesn't do exact matches so here's where we filter for just the contentlet we need
        ...
    #end
#end

Kivi Shapiro
Qualicom Innovations


On Thursday, 6 February 2014 09:41:43 UTC-5, Chris Falzone wrote:
You cannot is the short answer.  You can't do exact searching in dotCMS.  It has to do with how the content is indexed.   So +field:"hello"  

Will match all of the following:

hello
Hello
Hello World
I want to say heLLO

But not the following:
Helloworld

What you can do is put a conditional on the loop to look for exact.  

Xander Steinmann

unread,
Feb 6, 2014, 9:54:53 AM2/6/14
to dot...@googlegroups.com
I was already thinking about the workaround with a for-loop, but I hoped that there would be something that would allow for an exact search.
Thanks everybody for the input!

Xander

Jason Tesser

unread,
Feb 6, 2014, 9:52:37 AM2/6/14
to dot...@googlegroups.com
or create a viewtool to handle for you for sorting purposes. 


--
Reply all
Reply to author
Forward
0 new messages