Indexing a binary and searching with contains, cannot find results

I would like to ask for your help in understanding where I go wrong in building a working example where I populate a repository with binary data, index it, and run a contains query.

I have logs to TRACE and I see the indexing working, upon executing the query however I always get 0 results.

Repository is MemoryNodeStore and I create it in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>LuceneIndexProvider provider = new LuceneIndexProvider();
Oak oak = new Oak(ns) // ns is a NodeStore MemoryNodeStore
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider());
repository = new Jcr(oak).createRepository();
</code>
<code>LuceneIndexProvider provider = new LuceneIndexProvider(); Oak oak = new Oak(ns) // ns is a NodeStore MemoryNodeStore .with((QueryIndexProvider) provider) .with((Observer) provider) .with(new LuceneIndexEditorProvider()); repository = new Jcr(oak).createRepository(); </code>
LuceneIndexProvider provider = new LuceneIndexProvider();
Oak oak = new Oak(ns) // ns is a NodeStore MemoryNodeStore
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider());
repository = new Jcr(oak).createRepository();

Then I populate it in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Node node = rootNode.addNode("node" + i, "nt:unstructured");
byte[] data = ("testo" + i).getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(data);
Binary binary = session.getValueFactory().createBinary(bais);
try {
node.setProperty("binaryData", binary);
} finally {
binary.dispose();
}
node.setProperty("jcr:mimeType", "text/plain");
</code>
<code>Node node = rootNode.addNode("node" + i, "nt:unstructured"); byte[] data = ("testo" + i).getBytes(); ByteArrayInputStream bais = new ByteArrayInputStream(data); Binary binary = session.getValueFactory().createBinary(bais); try { node.setProperty("binaryData", binary); } finally { binary.dispose(); } node.setProperty("jcr:mimeType", "text/plain"); </code>
Node node = rootNode.addNode("node" + i, "nt:unstructured");
byte[] data = ("testo" + i).getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(data);
Binary binary = session.getValueFactory().createBinary(bais);
try {
    node.setProperty("binaryData", binary);

} finally {
    binary.dispose();
}
node.setProperty("jcr:mimeType", "text/plain");

Then the index is in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Node root = session.getRootNode();
Node oakIndex = root.getNode("oak:index");
Node index = oakIndex.addNode("contentTextIndex", "oak:QueryIndexDefinition");
index.setProperty("type", "lucene");
index.setProperty("async", (String[]) null);
Node indexRules = index.addNode("indexRules", "nt:unstructured");
Node ntBase = indexRules.addNode("nt:base", "nt:unstructured");
Node properties = ntBase.addNode("properties", "nt:unstructured");
Node binaryDataProperty = properties.addNode("binaryData", "nt:unstructured");
binaryDataProperty.setProperty("name", "binaryData";
binaryDataProperty.setProperty("propertyIndex", true);
binaryDataProperty.setProperty("analyzed", true);
Node jcrMimeTypeProperty = properties.addNode("jcr:mimeType");
jcrMimeTypeProperty.setProperty("name", "jcr:mimeType");
jcrMimeTypeProperty.setProperty("propertyIndex", true);
jcrMimeTypeProperty.setProperty("analyzed", true);
</code>
<code>Node root = session.getRootNode(); Node oakIndex = root.getNode("oak:index"); Node index = oakIndex.addNode("contentTextIndex", "oak:QueryIndexDefinition"); index.setProperty("type", "lucene"); index.setProperty("async", (String[]) null); Node indexRules = index.addNode("indexRules", "nt:unstructured"); Node ntBase = indexRules.addNode("nt:base", "nt:unstructured"); Node properties = ntBase.addNode("properties", "nt:unstructured"); Node binaryDataProperty = properties.addNode("binaryData", "nt:unstructured"); binaryDataProperty.setProperty("name", "binaryData"; binaryDataProperty.setProperty("propertyIndex", true); binaryDataProperty.setProperty("analyzed", true); Node jcrMimeTypeProperty = properties.addNode("jcr:mimeType"); jcrMimeTypeProperty.setProperty("name", "jcr:mimeType"); jcrMimeTypeProperty.setProperty("propertyIndex", true); jcrMimeTypeProperty.setProperty("analyzed", true); </code>
Node root = session.getRootNode();
Node oakIndex = root.getNode("oak:index");
Node index = oakIndex.addNode("contentTextIndex", "oak:QueryIndexDefinition");
index.setProperty("type", "lucene");
index.setProperty("async", (String[]) null);
Node indexRules = index.addNode("indexRules", "nt:unstructured");
Node ntBase = indexRules.addNode("nt:base", "nt:unstructured");
Node properties = ntBase.addNode("properties", "nt:unstructured");
Node binaryDataProperty = properties.addNode("binaryData", "nt:unstructured");
binaryDataProperty.setProperty("name", "binaryData";
binaryDataProperty.setProperty("propertyIndex", true);
binaryDataProperty.setProperty("analyzed", true);
Node jcrMimeTypeProperty = properties.addNode("jcr:mimeType");
jcrMimeTypeProperty.setProperty("name", "jcr:mimeType");
jcrMimeTypeProperty.setProperty("propertyIndex", true);
jcrMimeTypeProperty.setProperty("analyzed", true);

Then I search in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>String sql2QueryString = "SELECT * FROM [nt:base] WHERE CONTAINS([binaryData], 'testo')";
Query sql2Query = queryManager.createQuery(sql2QueryString, Query.JCR_SQL2);
QueryResult result = sql2Query.execute();
</code>
<code>String sql2QueryString = "SELECT * FROM [nt:base] WHERE CONTAINS([binaryData], 'testo')"; Query sql2Query = queryManager.createQuery(sql2QueryString, Query.JCR_SQL2); QueryResult result = sql2Query.execute(); </code>
String sql2QueryString = "SELECT * FROM [nt:base] WHERE CONTAINS([binaryData], 'testo')";
Query sql2Query = queryManager.createQuery(sql2QueryString, Query.JCR_SQL2);
QueryResult result = sql2Query.execute();

and I read the results in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>NodeIterator nodes = result.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
log.info("Path: " + node.getPath());
counter++;
}
log.info("Found {} results", counter);
</code>
<code>NodeIterator nodes = result.getNodes(); while (nodes.hasNext()) { Node node = nodes.nextNode(); log.info("Path: " + node.getPath()); counter++; } log.info("Found {} results", counter); </code>
NodeIterator nodes = result.getNodes();
while (nodes.hasNext()) {
    Node node = nodes.nextNode();
    log.info("Path: " + node.getPath());
    counter++;
}
log.info("Found {} results", counter);

I’m using oak 1.68.0 with tika-core and tika-parsers-standard-package 2.9.2.

In logs I see the indexing and the text extraction correctly, if you want I can attach a full log.

Really thank you for your help, best regards

6

I found that the documentation was misleading. I tried to fix it.

  • If the aggregation rules are set, for binary data, you do not need to include it separately. When using aggregation, binary properties are automatically added to the fulltext index (but only there), if the mime type is set, and if the node is part of the index.
  • If aggregation rules are not used, then you need to set nodeScopeIndex to true for the property (see example).
  • You need to query the fulltext index using eg. SELECT * FROM [nt:base] WHERE CONTAINS(*, 'testo1')
  • You have added "testo" + i so you also need to query for that, e.g. testo1 (see above), not testo.
  • Setting analyzed and propertyIndex for binary properties has no effect. They will not be added added to a property index or fulltext index for this property; they will only be added to the fulltext index for this node (document).
  • You do not need to index the jcr:mimeType property if you do not have queries for it. A query on the this property would have a condition with jcr:mimeType.

Example index definition:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> "/oak:index/contentTextIndex": {
"compatVersion": 2,
"type": "lucene",
"tags": ["text"],
"async": ["async"],
"queryPaths": ["/tmp"],
"includedPaths": ["/tmp"],
"jcr:primaryType": "oak:QueryIndexDefinition",
"indexRules": {
"jcr:primaryType": "nam:nt:unstructured",
"nt:base": {
"jcr:primaryType": "nt:unstructured",
"properties": {
"jcr:primaryType": "nt:unstructured",
"binaryData": {
"nodeScopeIndex": true,
"propertyType": "Binary",
"name": "jcr:data",
"jcr:primaryType": "nt:unstructured"
}
}
}
}
}
</code>
<code> "/oak:index/contentTextIndex": { "compatVersion": 2, "type": "lucene", "tags": ["text"], "async": ["async"], "queryPaths": ["/tmp"], "includedPaths": ["/tmp"], "jcr:primaryType": "oak:QueryIndexDefinition", "indexRules": { "jcr:primaryType": "nam:nt:unstructured", "nt:base": { "jcr:primaryType": "nt:unstructured", "properties": { "jcr:primaryType": "nt:unstructured", "binaryData": { "nodeScopeIndex": true, "propertyType": "Binary", "name": "jcr:data", "jcr:primaryType": "nt:unstructured" } } } } } </code>
  "/oak:index/contentTextIndex": {
    "compatVersion": 2,
    "type": "lucene",
    "tags": ["text"],
    "async": ["async"],
    "queryPaths": ["/tmp"],
    "includedPaths": ["/tmp"],
    "jcr:primaryType": "oak:QueryIndexDefinition",
    "indexRules": {
      "jcr:primaryType": "nam:nt:unstructured",
      "nt:base": {
        "jcr:primaryType": "nt:unstructured",
        "properties": {
          "jcr:primaryType": "nt:unstructured",
          "binaryData": {
            "nodeScopeIndex": true,
            "propertyType": "Binary",
            "name": "jcr:data",
            "jcr:primaryType": "nt:unstructured"
          }
        }
      }
    }
  }

Example query:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>select * from [nt:base] where
isdescendantnode('/tmp')
and contains(*, 'properties')
option(index tag [text])
</code>
<code>select * from [nt:base] where isdescendantnode('/tmp') and contains(*, 'properties') option(index tag [text]) </code>
select * from [nt:base] where 
isdescendantnode('/tmp')
and contains(*, 'properties')
option(index tag [text])

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật