modeshape binarycontent search - apache-tika

I am trying modeshape 4, want binary content search, I am able to search nodes other than node containing binary content. Need help with search binary content. Are there any examples?
Code to create node
static void addFile(byte[] filebytes, String filename) throws Exception{
Session session=openSession();
Node root = session.getRootNode();
if(!root.hasNode("files")){
Node n = root.addNode("files");
}
Node files=root.getNode("files");
Node newFileNode=files.addNode(String.valueOf(helper.rnd.nextInt()));
newFileNode.setProperty("fileName", filename);
newFileNode.setProperty("owner", "test");
newFileNode.setProperty("binaryContent", session.getValueFactory().createBinary(new ByteArrayInputStream(filebytes)));
session.save();
closeSession(session);
}
Search code
static void search()throws Exception{
javax.jcr.query.QueryManager queryManager = openSession().getWorkspace().getQueryManager();
javax.jcr.query.Query query = queryManager.createQuery("select * from [nt:base] as s where contains(s.binaryContent,'Finan') ",Query.JCR_SQL2);
javax.jcr.query.QueryResult result = query.execute();
javax.jcr.NodeIterator nodeIter = result.getNodes();
while ( nodeIter.hasNext() ) {
javax.jcr.Node node = nodeIter.nextNode();
System.out.println(node.getProperty("fileName")+" "+node.getProperty("owner"));
}
}
modeshape configuration
{
"name" : "Persisted-Repository",
"workspaces" : {
"predefined" : ["otherWorkspace"],
"default" : "default",
"allowCreation" : true
},
"security" : {
"anonymous" : {
"roles" : ["readonly","readwrite","admin"],
"useOnFailedLogin" : false
}
},
"storage" : {
"cacheConfiguration" : "infinispan-configuration-async-eviction.xml",
"cacheName" : "persisted_repository",
"binaryStorage" : {
"type" : "database",
"driverClass" : "oracle.jdbc.driver.OracleDriver",
"url" : "jdbc:oracle:thin:#xxx.xx.xx.xx:1521:sid",
"username" : "user",
"password" : "password"
}
},
"indexProviders": {
"lucene": {
"classname": "lucene",
"directory": "target/indexes"
}
},
"indexes": {
"textFromFiles": {
"kind": "text",
"provider": "lucene",
"nodeType": "nt:resource",
"columns": "jcr:data(BINARY)"
}
},
"textExtraction": {
"extractors" : {
"tikaExtractor":{
"name" : "Tika content-based extractor",
"classname" : "tika"
}
}
}
}
node structure
+---> -1731357696 /files/-1731357696
owner test
filename attachment-a.docx
binaryContent binary (14.39KB, SHA1=3941f73eab403accc1779af293afadd0c03e0c15)

Related

How to read an aggregated entity from Odata Service SAP ui5

In OData Model V2, I'm struggling by reading the odata of my mocked server:
I want to get access to the child entity which is associated with a Parent entity.
From Open_Station I can navigate to_Order_Header:
[{
"results": [
{
"__metadata": {
"id": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
"type": "cds_zui_check_dialog.Open_StationType"
},
"Station": "CHE1",
"Task": "5246",
"to_Order_Header": {
"__deferred": {
"uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"
}
}
}
]
}
]
And from to_Order_Header, I can navigate to Order_Item or Stock:
[{
"__metadata" : {
"id" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
"type" : "cds_zui_check_dialog.Order_HeaderType"
},
"OrderNumber" : "00000000100000000853",
"Station" : "CHE1",
"OrderIndicator" : "",
"to_Order_Items" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Order_Items"
}
},
"to_Stock" : {
"__deferred" : {
"uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Stock"
}
}
]
In my controller, I have a metho ReadOdata read data like this:
ReadOdata: function()
{
var oModel = new sap.ui.model.odata.v2.ODataModel("http://WebService");
return new Promise(function(resolve, reject)
{
oModel.read("Open_Station(Station='CHE1',Task='5246')/to_Order_Header", {
success : function (data) {
resolve(data);
},
error: function (oError) {
reject(oError);
}
});
});
},
I always get a failure like this:
Request failed with status code 404: GET Open_Station(Station='CHE1',Task='5246')/to_Order_Header
- [{"code":404,"message":"Resource not found","persistent":false,"targets":["/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"],"type":"Error"}]
sap.ui.model.odata.ODataMessageParser
I think the way I want to read the associated entity is wrong. Please help me.
I found a solution. It was a failure in the annotation of the Path:
Instead of writing:
oModel.read("**to_Open_Station**(Station='CHE1',Task='5246')/to_Order_Header", {
I was writing:
oModel.read("*Open_Station*(Station='CHE1',Task='5246')/to_Order_Header", {
In the MetaData, the NavigationProperty was called to_Open_Station.

How do I compare two nested documents using mongo_dart

Here is my database entry structure, it has a nested document called friends, I want to compare two different _id's friends list in dart using mongo_dart
{
"_id" : ObjectId("60ae06074e162995281b4666"),
"email" : "one#one.com",
"emailverified" : false,
"username" : "one#one.com",
"displayName" : "complete n00b",
"phonenumber" : "",
"dob" : "",
"points" : 0,
"friends" : [
{
"username" : "three#one.com",
"sent" : ISODate("2021-05-26T10:01:30.616Z")
},
{
"username" : "six#one.com",
"sent" : ISODate("2021-05-26T10:43:16.822Z")
}
]
}
Here is my code, but I am not getting any returns
Future<Map> commonFriends(store, myObjectId, theirObjectId) async {
var commonList = await store.aggregate([
{
'\$project': {
'friends': 1,
'commonToBoth': {
'\$setIntersection': [
{'_id': myObjectId, 'friends': '\$username'},
{'_id': theirObjectId, 'friends': '\$username'}
]
},
}
}
]);
return commonList;
}
I am getting an error from db.dart which is apart of mongo_dart package. The error is "Exception has occurred.
Map (4 items)"

Ignoring Firebase child

How could I query this data in this way:
I would like to ignore the CurrentSubAdministrativeArea child and iterate every each sub child and find the right userKey
Actually I'm using this code, that isnt working:
self.ref.child("Ads").child("CurrentSubAdministrativeArea")
/*HERE I would like to ignore the childs*/
.queryOrdered(byChild: "userKey").queryEqual(toValue: uid).observeSingleEvent(of:.value, with: { (snapshot) in
--
{
"Ads" : {
"CurrentSubAdministrativeArea" : {
"Mantova" : {
"-L7ymBmmbHkNfhBRte9F" : {
"cost" : 200,
"date" : 1527256922000,
"info" : "Test",
"maxLimit" : 100,
"minLimit" : 10,
"personBadType" : [ "abitudinaria", "antipatica" ],
"personGoodType" : [ "simpatica", "felice" ],
"subAdministrativeArea" : "Mantova",
"title" : "Mantova Test",
"url" : "https://firebasestorage.googleapis.com/v0/b/team-34540.appspot.com/o/Mantova%20Test?alt=media&token=3a81ed1c-ecd6-4dc0-bd7c-45e093ce8188",
"userKey" : "OsJRc98sqxPx70iqxFtoqerMzHH2",
"via" : "viale dei test"
}
},
"Milano" : {
"-L6qywMC6nxi0fJNMHba" : {
"cost" : 454,
"date" : 1528298580000,
"info" : "Di pollo",
"maxLimit" : 100,
"minLimit" : 10,
"personBadType" : [ "abitudinaria", "antipatica" ],
"personGoodType" : [ "simpatica", "felice" ],
"subAdministrativeArea" : "Milano",
"title" : "Pollo 2",
"url" : "https://firebasestorage.googleapis.com/v0/b/team-34540.appspot.com/o/Pollo?alt=media&token=fc6a3ec8-5f9a-4347-bdad-2d9715af784d",
"userKey" : "OsJRc98sqxPx70iqxFtoqerMzHH2",
"via" : "viale test"
}
}
}
}
}
You could denormalize your data in such a way your query is easy to build and execute.
Together with the data structure you already have you would have another node (ie. another data structure) like
{
"AdsByUsers" : {
"OsJRc98sqxPx70iqxFtoqerMzHH2": {
"Mantova",
"Milano",
...
},
"abcde88qxPx70iqxFtoqerMzKh5": {
"Firenze",
...
}
With NoSQL database you should not hesitate to duplicate data in such a way your queries are easy and fast to execute.

How to boost the closest created_at field in Elasticsearch?

I want to sort my query results following some boost rules and in the same time i want them to be sorted as possible by creation date, if i add a created_at sort, it changes everything and my results are not relevant anymore. So i guess the only way to do that is to boost created_at field (the newest has the biggest bonus in calculating score for that boost) but i dont know how to implement it. This is my query:
query = {
"query" : {
"bool" : {
"must" : [
{
"range" : {
"deadline" : {
"gte" : "2016-05-30T11:39:10+02:00"
}
}
},
{
"terms" : {
"state" : [
"open"
]
}
},
{
"query_string" : {
"query" : "chant",
"default_operator" : "AND",
"analyzer" : "search_francais",
"fields" : [
"title^6",
"description",
"brand",
"category_name"
]
}
}
]
}
},
"filter" : {
"and" : [
{
"geo_distance" : {
"distance" : "40km",
"location" : {
"lat" : 48.855736,
"lon" : 2.32927300000006
}
}
}
]
},
"sort" : [
{
"_score" : "desc"
},
#{
# "created_at" : "desc" ==> i tried this but it doesnt change results
#}
]
}
Try adding your condition in should block.
i)If the created date should be closer to come value in the search query or you have any idea on how close the date should be, give a range query.
ii) If you are not sure of all those values, decay function can be used. In this case, query shall be changed to function query.
{
"query" : {
"bool" : {
"must" : [
{
"range" : {
"deadline" : {
"gte" : "2016-05-30T11:39:10+02:00"
}
}
},
{
"terms" : {
"state" : [
"open"
]
}
},
{
"query_string" : {
"query" : "chant",
"default_operator" : "AND",
"analyzer" : "search_francais",
"fields" : [
"title^6",
"description",
"brand",
"category_name"
]
}
}
],
"should": [
{"created_at" : "condition here .. "}
]
}
},
"filter" : {
"and" : [
{
"geo_distance" : {
"distance" : "40km",
"location" : {
"lat" : 48.855736,
"lon" : 2.32927300000006
}
}
}
]
}
}

SwiftyJSON array empty

I want to retrieve data from a JSON file with SwiftyJSON and Alamofire. This is the JSON data:
json: {
"data" : {
"monitors" : [
{
"lines" : [
{
"towards" : "LEOPOLDAU",
"realtimeSupported" : true,
"departures" : {
"departure" : [
{
"departureTime" : {
"countdown" : 2,
"timePlanned" : "2015-09-09T18:47:03.000+0200",
"timeReal" : "2015-09-09T18:47:03.000+0200"
}
},
{
"departureTime" : {
"countdown" : 6,
"timePlanned" : "2015-09-09T18:51:03.000+0200",
"timeReal" : "2015-09-09T18:51:03.000+0200"
}
}
]
},
"lineId" : 301,
"platform" : "1",
"trafficjam" : false,
"richtungsId" : "1",
"direction" : "H",
"type" : "ptMetro",
"name" : "U1",
"barrierFree" : true
}
],
"attributes" : {
},
"locationStop" : {
"type" : "Feature",
"geometry" : {
"type" : "Point",
"coordinates" : [
16.4330680046932,
48.2430825589716
]
},
"properties" : {
"municipality" : "Wien",
"title" : "Kagran",
"coordName" : "WGS84",
"municipalityId" : 90000,
"type" : "stop",
"gate" : "1",
"name" : "60200627",
"attributes" : {
"rbl" : 4127
}
}
}
}
]
}
,
"message" : {
"value" : "OK",
"serverTime" : "2015-09-09T18:45:08.998+0200",
"messageCode" : 1
}
}
What I want to do now is get the data of lines into an array. I tried several combinations for that, e.g.
let departureArray = jsonData["data"]["monitors"][0]["lines"][0].array
or
let departureArray = jsonData["data"]["monitors"]["lines"].array
but my array is always empty. Does anyone has an idea how to do this properly?
Your expected array departureArray is in fact a dictionary
let departureDictionary = jsonData["data"]["monitors"][0]["lines"][0].dictionary

Resources