1
votes

I have a relationship index named dates, which indexes on 2 fields - "year-numeric" and "type". I intend to use range queries on year-numeric and so have indexed it as numeric

 dates.add(role1, "year-numeric", new ValueContext(2000).indexNumeric());

where role1 is a relationship between 2 nodes.

In my graph, I have 2 types of relationship which is captured by the 2nd field "type".

While I am able to query it individually:

IndexHits<Relationship> hits = dates.query(QueryContext.numericRange("year-numeric", 1990, 2004),null,null);

and

hits = dates.query("type:occurs");

I would be obliged, if someone can help me in combining together these two conditions.

I have checked here: queryContext - filtering with numbers neo4j/lucene but I am unable to understand the solution.

Thanks!

1
how about dates.query("year-numeric:[1990 to 2004] and type:occurs") ? (have not tried myself - just a shoot from the hip). Don't forget to add the type to the index as well dates.add(role1, "type", role1.getType().name())Stefan Armbruster
Hi, thanks for the reply. It does not work: I am getting the following error: Exception in thread "main" java.lang.RuntimeException: org.apache.lucene.queryParser.ParseException: Cannot parse 'year-numeric:[1990 to 2004] and type:occurs': Encountered " <RANGEIN_GOOP> "2004 "" at line 1, column 22. Was expecting: "]"graphEnthusiast
You probably have to use a query object instance that is a BooleanQuery or an AndQuery or something like that.Michael Hunger
Thanks! The booleanQuery was a good hint.graphEnthusiast

1 Answers

1
votes

Based on the inputs in comments, I did some more digging in lucene and came up with the following solution. Not sure whether it is the most optimal one though:

BooleanQuery booleanQuery = new BooleanQuery();
TermQuery query1 = new TermQuery(new Term("type","occurs"));
NumericRangeQuery<Integer> pageQueryRange = NumericRangeQuery.newIntRange("year-numeric", 1990, 2005, true, true);
booleanQuery.add(query1, BooleanClause.Occur.MUST);
booleanQuery.add(pageQueryRange, BooleanClause.Occur.MUST);   
IndexHits<Relationship> hits = dates.query(booleanQuery);