queryContext - filtering with numbers neo4j/lucene

2019-08-29 07:43发布

I'm trying to filter a wildcard query in neo/lucene using numeric range. I want to search for all nodes (documents) having key "actor" starting with "rob" and age > 20:

WildcardQuery luceneQuery  = new WildcardQuery( new Term("actor", "rob*" ));
QueryContext qx = new QueryContext(luceneQuery)
            .numericRange("age", 20, null)
                .sortNumeric("age", true);      
IndexHits<Node> hits = lucene.query(qx);

Once I add numeric range the wildCard query does not works, it only orders by numeric range. Is it possible to combine both wildcard and numeric?

Thanks, Daniele

1条回答
可以哭但决不认输i
2楼-- · 2019-08-29 08:32

I suspect you want to use a BooleanQuery to combine the WildcardQuery with the numeric range query. (I normally use QueryParser, myself, rather than building the queries by hand.)

For your example query, the QueryParser syntax would look like:

+actor:rob* +age:{20 TO 123}

where +age:{20 TO 123} asks for age > 20 AND age < 123 (the oldest well-documented person lived to 122). The "+" operators force both of those terms to occur in the document.

查看更多
登录 后发表回答