lucene query - field range

178 views
Skip to first unread message

nop33

unread,
Aug 27, 2012, 4:40:38 AM8/27/12
to dot...@googlegroups.com
Hello people. I have the following issue:

I have an IP database stored as a structure in my content repository, with the fields IPnumberStart | IPnumberEnd | CountryCode | Country | Region | City .

I want to block some users that connect to my site according to their country (I am not a racist :P). So I created a Filter in which I read the IP from the request, convert it to IP number and I pull ALL records of the IP structure, to check the country this address belongs. But the records are millions! And I don't want to pull all of them, I just need one record.

I tried this query: "+structureName:BrDemoIp +text1:[* TO 16777474] +text1:[16777474 TO *] +(conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST) +languageId:1 +deleted:false +working:true",

in order to get the record I need, but it is not working.

However, this query:

+structureName:BrDemoIp +text1:[16777470 TO 16777474] +(conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST) +languageId:1 +deleted:false +working:true"

is working, but this is not what I need.

And the last thing is that insteed of the 16777474 in the first query, I want to place a String variable.

Any ideas?

Thank you.
Ilias

Maria Ahues Bouza

unread,
Aug 27, 2012, 2:11:34 PM8/27/12
to dot...@googlegroups.com
Ilias,

I don't think you can do this +text1:[* TO 16777474]

If you're trying to pull just one record, wouldn't you need to do this? +text1:16777474

I don't understand what you're trying to do with this query +text1:[* TO 16777474] +text1:[16777474 TO *]

You're trying to get anything with a number lower than 16777474 and also with a number higher than 16777474? Isn't that all the records?

-Maria


--
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/dotcms/-/Ob54XW0FmlwJ.
To post to this group, send email to dot...@googlegroups.com.
To unsubscribe from this group, send email to dotcms+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotcms?hl=en.



--
Community Manager

dotCMS
Main: 305.900.2001
Fax: 305.397.2579
www.dotcms.com
http://www.twitter.com/dotCMS
http://www.facebook.com/dotCMS
http://www.twitter.com/mabouza

Please consider the planet before printing this email.

Maria Ahues Bouza

unread,
Aug 27, 2012, 2:12:46 PM8/27/12
to dot...@googlegroups.com
Gynnad,

Here you're missing a + before date1

+structurename:bijzonderedagen +(conhost:64d17170-c24b-4812-a788-78283d989a64 conhost:system_host) +bijzonderedagen.vestigingnaam:*Amsterdam* +bijzonderedagen.iskoopzondag:*ja* +languageid:3 +deleted:false +working:true +date1:[01/01/2003 TO 01/01/2012] +working:true +((permissions:p654b0931-1027-41f7-ad4d-173115ed8ec1.1p*) )


-Maria

On Mon, Aug 27, 2012 at 2:14 AM, <gynna...@gmail.com> wrote:
I have quite the same issue:

What is wrong with my Lucene query? I can't understand why this is going wrong.

[27/08/12 10:28:38:447 CEST] ERROR lucene.LuceneUtils: Error ocurred trying to search results in the current index.
org.apache.lucene.queryParser.ParseException: Cannot parse '+structurename:bijzonderedagen +(conhost:64d17170-c24b-4812-a788-78283d989a64 conhost:system_host) +bijzonderedagen.vestigingnaam:*Amsterdam* +bijzonderedagen.iskoopzondag:*ja* +languageid:3 +deleted:false +working:true date1:[01/01/2003 TO 01/01/2012] +working:true +((permissions:p654b0931-1027-41f7-ad4d-173115ed8ec1.1p*) )': Encountered " <RANGEIN_GOOP> "01/01/2012 "" at line 1, column 245.
Was expecting:
    "]" ...
   
    at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:187)
    at com.dotmarketing.util.lucene.LuceneUtils.prepareQuery(LuceneUtils.java:1195)
    at com.dotmarketing.util.lucene.LuceneUtils.searchInCurrentIndex(LuceneUtils.java:507)
    at com.dotmarketing.portlets.contentlet.business.ContentletFactoryDBImpl.indexSearch(ContentletFactoryDBImpl.java:388)
    at com.dotmarketing.portlets.contentlet.business.ContentletAPIImpl.searchIndex(ContentletAPIImpl.java:548)
    at com.dotmarketing.portlets.contentlet.business.ContentletAPIImpl.search(ContentletAPIImpl.java:453)
    at com.dotmarketing.portlets.contentlet.business.ContentletAPIImpl.search(ContentletAPIImpl.java:445)
    at com.dotmarketing.portlets.contentlet.business.ContentletAPIInterceptor.search(ContentletAPIInterceptor.java:1491)
    at com.dotmarketing.servlets.JSONContentServlet.service(JSONContentServlet.java:172)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.dotmarketing.filters.CMSFilter.doFilter(CMSFilter.java:484)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.dotmarketing.filters.AutoLoginFilter.doFilter(AutoLoginFilter.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.dotmarketing.cms.urlmap.filters.URLMapFilter.doFilter(URLMapFilter.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.dotmarketing.filters.CharsetEncodingFilter.doFilter(CharsetEncodingFilter.java:140)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.lucene.queryParser.ParseException: Encountered " <RANGEIN_GOOP> "01/01/2012 "" at line 1, column 245.
Was expecting:
    "]" ...
   
    at org.apache.lucene.queryParser.QueryParser.generateParseException(QueryParser.java:1759)
    at org.apache.lucene.queryParser.QueryParser.jj_consume_token(QueryParser.java:1641)
    at org.apache.lucene.queryParser.QueryParser.Term(QueryParser.java:1399)
    at org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1250)
    at org.apache.lucene.queryParser.QueryParser.Query(QueryParser.java:1207)
    at org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java:1167)
    at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:182)
    ... 41 more


--
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/dotcms/-/7XLh8wufM-gJ.

To post to this group, send email to dot...@googlegroups.com.
To unsubscribe from this group, send email to dotcms+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotcms?hl=en.

nop33

unread,
Aug 27, 2012, 3:05:00 PM8/27/12
to dot...@googlegroups.com
No Maria, you got me wrong.

This is an example of the database:

IP start from | IP end to | Country
16776500 | 16776999 | INDIA
16777000 | 16777499 | CHINA 
16777500 | 16778000 | GREECE

So when a user with IP number 16777474 comes in, I want to redirect him somewhere else.

That's why I am looking in the database for records that the IP start is smaller than 16777474 and the IP end is bigger than 16777474 ( I misstyped the  +text1:[ 16777474  TO *] in the first post, it should be  +text2:[ 16777474  TO *] ), so I should get only the record 

16777000 | 16777499 | CHINA 

The point is that the "*" is not recognised. And as I said before, the other problem is that the IP number (in this case  16777474) is a variable, so I have to add a long variable in the query.

Thank you for your reply

Regards,
Ilias

Maria Ahues Bouza

unread,
Aug 27, 2012, 4:12:39 PM8/27/12
to dot...@googlegroups.com
I see. The syntax you're using is not going to work in lucene. I'm trying to think of how you can implement this. 

I'll test locally to see if i can give you an easy solution.

To view this discussion on the web visit https://groups.google.com/d/msg/dotcms/-/nzpIOkZ--CsJ.

To post to this group, send email to dot...@googlegroups.com.
To unsubscribe from this group, send email to dotcms+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotcms?hl=en.

nop33

unread,
Aug 28, 2012, 4:27:12 AM8/28/12
to dot...@googlegroups.com
Thank you for your efford.

 

nop33

unread,
Aug 30, 2012, 11:05:58 AM8/30/12
to dot...@googlegroups.com
I found a way to reduce the results of the query, but still not able to get only one record.

I noticed that each records of IPs contains some thousands of IP addresses. So I used +BrDemoIp.ipstart:1677* where the * is the rest 4 digits that could possibly be different.

Though, still cannot figure out how to put a variable into the query.

Maria Ahues Bouza

unread,
Aug 30, 2012, 6:11:52 PM8/30/12
to dot...@googlegroups.com
Sorry I haven't been able to send you a solution for this yet.

About the variable you can do this

#set($ipnumber=1677)
#set($query="+BrDemoIp.ipstart:${ipnumber}*")



--
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/dotcms/-/s_fwdpdM5q0J.

To post to this group, send email to dot...@googlegroups.com.
To unsubscribe from this group, send email to dotcms+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dotcms?hl=en.
Reply all
Reply to author
Forward
0 new messages