almogtavor opened a new issue, #12406:
URL: https://github.com/apache/lucene/issues/12406
### Description
I use Lucene Monitor with regular `Document` objects and it works just fine.
The thing is that I'd like to match with Solr queries that I use in a nested
collection, but I've couldn't get this work. I'm openning this ticket as a
request because I'm not sure if there is any official support for nested
queries in `lucene-monitor`.
I've tries to match documents with nested queries that needs to match both
fields of the parent doc and both fields from the child doc. To acheive this
I've tried to use `Monitor#match` and give it `Document[]`, but from what I
understand Lucene Monitor doesn't enable queries with "context" of other
documents.
I'd like to know if it can work in any way right now, and if not I'd like to
know what's needed to be done to contribute such feature.
<details>
<summary>The code I've tried it with is here</summary>
```java
@Override
public void run(ApplicationArguments args) throws Exception {
MonitorConfiguration monitorConfig = new MonitorConfiguration();
Monitor monitor = new Monitor(new StandardAnalyzer(), new
TermFilteredPresearcher(), monitorConfig);
registerQueries(monitor);
// Creating a parent document with child documents
Document parentDoc = new Document();
parentDoc.add(new StringField("id", "g1", Field.Store.YES));
parentDoc.add(new StringField("color", "green", Field.Store.YES));
parentDoc.add(new StringField("title", "Grass", Field.Store.YES));
parentDoc.add(new StoredField("isParent", "true"));
// Creating child document
Document childDoc1 = new Document();
childDoc1.add(new TextField("childField1", "childValue1",
Field.Store.YES));
childDoc1.add(new StringField("isParent", "false", Field.Store.YES));
Document childDoc2 = new Document();
childDoc2.add(new TextField("childField2", "childValue2",
Field.Store.YES));
childDoc2.add(new StringField("isParent", "false", Field.Store.YES));
Document[] documents = {parentDoc,childDoc1};
MultiMatchingQueries<HighlightsMatch> hm = monitor.match(documents,
HighlightsMatch.MATCHER);
log.info("Got " + hm.getMatchCount(0) + " matches");
hm.getMatches(0).forEach(m -> {
log.info("Match: " + m.getQueryId() + " with " +
m.getHitCount());
m.getHits("childField1").forEach(h -> {
log.info(" hit: " + h.toString() + " - " +
childDoc1.get("childField1").substring(h.startOffset, h.endOffset));
});
});
}
private void registerQueries(Monitor monitor) throws IOException,
ParseException {
MonitorQuery monitorQuery = newMonitorQuery("ChildQuery1",
"childField1:childValue1", Collections.singletonMap("customer", "123"));
monitor.register(monitorQuery);
monitor.register(newMonitorQuery("ChildQuery2",
"childField2:childValue2", Collections.singletonMap("customer", "124")));
}
private MonitorQuery newMonitorQuery(String id, String queryString,
Map<String, String> metadata) throws ParseException {
QueryParser qp = new QueryParser("childField1", new
StandardAnalyzer());
Query childQuery = qp.parse(queryString);
// Construct ToParentBlockJoinQuery from child query
BitSetProducer parentFilter = new QueryBitSetProducer(new
TermQuery(new Term("isParent", "true")));
ToParentBlockJoinQuery parentJoinQuery = new
ToParentBlockJoinQuery(childQuery, parentFilter, ScoreMode.None);
log.info("Registered monitor query " + id);
return new MonitorQuery(id, parentJoinQuery, queryString, metadata);
}
```
</details>
[This is the repo for
it](https://github.com/almogtavor/nested-lucene-monitor/blob/main/src/main/java/io/github/almogtavor/service/NestedLuceneMonitorService.java).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]