queryContext - filtering with numbers neo4j/lucene

試著忘記壹切 提交于 2019-12-11 23:16:59

问题


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 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.



来源:https://stackoverflow.com/questions/12155578/querycontext-filtering-with-numbers-neo4j-lucene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!