In my solr document, the document data is like:
{
"createTime":"2013-09-10",
"reason":"reason1",
"postId":"postId_1",
"_version_":1445959401549594624 },
{
"createTime":"2013-09-11",
"reason":"reason2",
"postId":"postId_1",
"_version_":1445959401549594624 },
{
"createTime":"2013-09-12",
"reason":"reason3",
"postId":"postId_1",
"_version_":1445959401549594624 },
{
"createTime":"2013-09-13",
"reason":"reason4",
"postId":"postId_2",
"_version_":1445959401549594624 },<script>alert("1")</script>
Now I need use solr facetQuery to select some data like this:
1. postId1, 3 records, the last createTime is "2013-09-12"
2. postId2, 1 record, the last createTime is "2013-09-13", reason is reason4
How can I do this using solr facetQuery?
You can use Field Collapsing feature, which can help you group the results.
If you group on post_id, you would be able to get the the results as per the post id.
You would get the count for each post id (numFound), which will give you the 3 records part.
You can order the results within the group by date desc and return single result (group.limit=1) which will give you the last date.
You can pick up the reason from the records.
Related
I'm trying to filter the data from my database using this code:
fdb.orderByChild("title").startAt(searchquery).endAt(searchquery+"\uf8ff").addValueEventListener(valuelistener2);
My database is like this:
"g12" : {
"Books" : {
"-Mi_He4vHXOuKHNL7yeU" : {
"title" : "Technical Sciences P1"
},
"-Mi_He50tUPTN9XDiVow" : {
"title" : "Life Sciences"
},
"-Mi_He51dhQfl3RAjysQ" : {
"title" : "Technical Sciences P2"
}}
While the code works, it only returns the first value that matches the query and doesn't fetch the rest of the data even though it matches.
If I put a "T" as my search query, I just get the first title "Technical Sciences P1 " and don't get the other one with P2
(Sorry for the vague and common question title, it's just I've been looking for a solution for so long)
While the codes works, it only returns the first value that matches the query
That's the expected behavior since Firebase Realtime Database does not support native indexing or search for text fields in database properties.
When you are using the following query:
fdb.orderByChild("title").startAt(searchquery).endAt(searchquery+"\uf8ff")
It means that you are trying to get all elements that start with searchquery. For example, if you have a title called "Don Quixote" and you search for "Don", your query will return the correct results. However, searching for "Quix" will yield no results.
You might consider downloading the entire node to search for fields client-side but this solution isn't practical at all. To enable full-text search of your Firebase Realtime Database data, I recommend you to use a third-party search service like Algolia or Elasticsearch.
If you consider at some point in time to try using Cloud Firestore, please see the following example:
Is it possible to use Algolia query in FirestoreRecyclerOptions?
To see how it works with Cloud Firestore but in the same way, you can use it with Firebase Realtime Database.
I am using an alias to index my documents in the elastic search cluster.Basically indexes under this alias are created each month and any document ingested using this alias will reside in the index corresponding to the month in which it was ingested. The documents are indexed using Id and routing Id.
Now there is a use case where I have the Id and routing Id of the document and I need to find the exact index under the alias where this document resides. How can I find that out?
For example the document with Id A and routing Id B could be indexed in the index 11-2020(November index of 2020) and this index is under Alias AliasIndex.
Get operation using id and routingId wouldn't work because it requires the specific indexed to be passed.
I am using Java RestHighLevelClient.
You can always issue a search request by searching by id
GET alias-index/_search?routing=B
{
"query": {
"term": {
"_id": "A"
}
}
}
In the response, you'll get the exact index of that document.
Is there a way to get records which matches a query partially in Solr.
For &q="java enterprise" in the below mentioned records,
{
"name":"java",
"case:"enterprise",
},
{
"name":"java enterprise"
"case": "enterprise"
}
I want to fetch only those records which have java and enterprise mentioned separately and not together, i.e only the below record should come into my result.
{
"name":"java",
"case:"enterprise",
}
Is there a way to search for only those records and eliminate the documents from the search which has exact match?
You don't need to use exact phrase match, instead, you can use boolean queries in that case
(name:"java" AND case:"enterprise" ) OR (name:"enterprise" AND case:"java" )
I'm new to couchbase. I'm using Java for this. I'm trying to remove a document from a bucket by looking up its ID with query parameters(assuming the ID is unknown).
Lets say I have a bucket called test-data. In that bucked I have a document with ID of 555 and Content of {"name":"bob","num":"10"}
I want to be able to remove that document by querying using 'name' and 'num'.
So far I have this (hardcoded):
String statement = "SELECT META(`test-data`).id from `test-data` WHERE name = \"bob\" and num = \"10\"";
N1qlQuery query = N1qlQuery.simple(statement);
N1qlQueryResult result = bucket.query(query);
List<N1qlQueryRow> row = result.allRows();
N1qlQueryRow res1 = row.get(0);
System.out.println(res1);
//output: {"id":"555"}
So I'm getting a json that has the document's ID in it. What would be the best way to extract that ID so that I can then remove the queryed document from the bucket using its ID? Am I doing to many steps? Is there a better way to extract the document's ID?
bucket.remove(docID)
Ideally I'd like to use something like a N1q1QueryResult to get this going but I'm not sure how to set that up.
N1qlQueryResult result = bucket.query(select("META.id").fromCurrentBucket().where((x("num").eq("\""+num+"\"")).and(x("name").eq("\""+name+"\""))));
But that isn't working at the moment.
Any help or direction would be appreciated. Thanks.
There might be a better way which is running this kind of query:
delete from `test-data` use keys '00000874a09e749ab6f199c0622c5cb0' returning raw META(`test-data`).id
or if your fields has index:
delete from `test-data` where name='bob' and num='10' returning raw META(`test-data`).id
This query deletes the specified document with given document key (which is meta.id) and returns document id of deleted document if it deletes any document. Returns empty if no documents deleted.
You can implement this query with couchbase sdk as follows:
Statement statement = deleteFrom("test-data")
.where(x("name").eq(s("bob")).and(x("num").eq(s("10"))))
.returningRaw(meta(i("test-data")).get("id"));
You can make this statement parameterized or just execute like that.
I am trying to get comment of a fanpage since a given time. But it seems like the since parameter is ignored.
try {
$attachments = array('access_token' => $profile['access_token'], 'since' => strtotime('2013-03-07T18:13:57+0000'));
$comments = $facebook->api("$id/comments", 'GET', $attachments);
print_r($comments);
} catch (FacebookApiException $e) {
error_log($e);
}
IsnĀ“t that possible?
No, since doesn't work with every table. A solution is to use FQL:
SELECT id, time, text
FROM comment
WHERE object_id = POST_ID
AND time > UNIX_TIME
LIMIT 50
OFFSET 0
(replace POST_ID and UNIX_TIME)
You can loop on this query while incrementing the OFFSET by 50.
The first group will give the 50 most recent comments, the second the 50 previous and so on. But each group contains comments ordered in chronological order.
You can stop looping once a query sends less than 50 results.