Finding document by numeric fields in Lucene - java

For example, I have some documents described by fields: id, date and price.
First document: id=1, date='from 10.01.2014 to 20.01.2014', price='120'
Second document: id=2, date='19.01.2014' and price='from 100 to 140'
My program receives key/value parameters and should find the most suitable documents. So, for example, with this parameters date=19.01.2014 and price='120' program should find both documents. With date=20.01.2014, price=120' only the first document. With date='19.01.2014, price=140' only the second one.
How can I do it with Lucene in Java? I saw examples where I'm typing query like 'give me docs where date is from .. to ..', and Lucene gives me docs in this range. Instead of this I want to specify range for my document and not for query.

You could index both opening and closing ranges for dates and prices, e.g.
Your document #1 would be indexed as:
id = 1
dateFrom = 10.01.2014
dateTo = 20.01.2014
priceFrom = 120
priceTo = 9999999999
And document #2 as
id=2
dateFrom = 19.01.2014
dateTo = 01.01.2099
priceFrom = 100
priceTo = 140
The query would look like this:
+dateFrom:[19.01.2014 TO *] +priceFrom:[120 TO *] +priceTo:[* TO 140]
This is not very effective but it should work.

Related

How to retrieve the list of data having second last dateCreated field

I didn't get any reference from anywhere I want to write Java code which can retrieve MongoDB documents that have the second last date.
For example:
_id
63be9dfe3288b22f6254604d
dateTimeCreated
"20230110_170103"
vinId
"JT4VD10A4P0008458"
country
"_US"
apiResponse
"{"error":false,"executionTimeMS":150,"copyright":"Copyright 2023 Autod…"
and second document
_id:63be9dff3288b22f6254604f
dateTimeCreated
"20230111_170103"
vinId
"4N2DN11W2RD808123"
country
"_US"
apiResponse
"{"error":false,"executionTimeMS":91,"copyright":"Copyright 2023 Autoda…"
Requirement is : the query should select the documents having second last date lets say it return us 10 documents and in those 10 documents return the document having specific vin id

ORMLite groupByRaw and groupBy issue on android SQLite db

I have a SQLite table content with following columns:
-----------------------------------------------
|id|book_name|chapter_nr|verse_nr|word_nr|word|
-----------------------------------------------
the sql query
select count(*) from content where book_name = 'John'
group by book_name, chapter_nr
in DB Browser returns 21 rows (which is the count of chapters)
the equivalent with ORMLite android:
long count = getHelper().getWordDao().queryBuilder()
.groupByRaw("book_name, chapter_nr")
.where()
.eq("book_name", book_name)
.countOf();
returns 828 rows (which is the count of verse numbers)
as far as I know the above code is translated to:
select count(*) from content
where book_name = 'John'
group by book_name, chapter_nr
result of this in DB Browser:
| count(*)
------------
1 | 828
2 | 430
3 | 653
...
21| 542
---------
21 Rows returned from: select count(*)...
so it seems to me that ORMLite returns the first row of the query as the result of countOf().
I've searched stackoverflow and google a lot. I found this question (and more interestingly the answer)
You can also count the number of rows in a custom query by calling the > countOf() method on the Where or QueryBuilder object.
// count the number of lines in this custom query
int numRows = dao.queryBuilder().where().eq("name", "Joe Smith").countOf();
this is (correct me if I'm wrong) exactly what I'm doing, but somehow I just get the wrong number of rows.
So... either I'm doing something wrong here or countOf() is not working the way it is supposed to.
Note: It's the same with groupBy instead of groupByRaw (according to ORMLite documentation joining groupBy's should work)
...
.groupBy("book_name")
.groupBy("chapter_nr")
.where(...)
.countOf()
EDIT: getWordDao returns from class Word:
#DatabaseTable(tableName = "content")
public class Word { ... }
returns 828 rows (which is the count of verse numbers)
This seems to be a limitation of the QueryBuilder.countOf() mechanism. It is expecting a single value and does not understand the addition of GROUP BY to the count query. You can tell that it doesn't because that method returns a single long.
If you want to extract the counts for each of the groups it looks like you will need to do a raw query check out the docs.

Lucene: Is there any way to know which subqueries have hit the document?

I have a MemoryIndex created like this.
```
Version version = Version.LUCENE_47;
Analyzer analyzer = new SimpleAnalyzer(version);
MemoryIndex index = new MemoryIndex();
index.addField("text", "Readings about Salmons and other select Alaska fishing Manuals", analyzer);
```
Then, I have a query containing a number of sub-query which is created from a set of concepts (including id, name, description). Right now I have to loop for every concept, generate a query, and finally check if it is matched => if it is, I append it to a string which is used to store matches
```
for (Concept concept : concepts) {
Query query = queryGenerator.getQueryForConcept(concept);
float score = query != null ? index.search(query) : 0.0f;
if (score > 0) {
matches.append(sep + concept.getId() + "|" + concept.getName());
sep = "|";
}
}```
The problem is: the number of concepts is growing larger and larger, which affects the performance. Is there anyway that I can create a one single query and compare to a document, and find out what concepts have been hit the document?
I tried using BooleanQuery as a whole, then add all subquery which derrived from concept into it. It matches but don't know which subquery hits, and even if we do, how do we put the details like "id", and "name" of a concept into it?
Much appreciate all answers

About solr query facet

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.

Lotus Notes Java program to access $Revisions columns

I am very new to lotus notes and java.
I am trying to get all documents which are modified by specific time.
I can not use getallmodifieddocuments because , notes version R5.
I am trying to get it as follows:
String query = Select Form = Protocol & ( last value from $revision ) > input datetime stamp
DocumentCollection dc = db.search ( query );
Then get all documents and process them.
Is it possible.
I can not get to $revision value to get print by getitemvaluestring ( $revision )
Is query even possible to implement?
I will appreciate if any other way !
The Notes formula language has a built in formula for accessing the last modified date of a document: #Modified
Or if you have a reference to the document from Java, the getLastModified() method should get you that information.
Your query could be:
String query = "Form = ""Protocol"" & #Modified > #TextToTime(""1/1/1970"") "

Categories

Resources