Does not working less than operator in solr query - java

I'm using solr4.7 with CoreContainer to create core and EmbeddedSolrServer to connect and ModifiableSolrParams to fetch the data..
I have configured "solrconfig.xml" with requestHelper "import" to import the data and other configuration file for data config as under....
<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/koupon"
user="root"
password="root" />
<document>
<entity name="koupon"
query="SELECT k.kouponid as kid, k.name, k.image,k.description,k.discount as discount,
k.startdate,k.enddate,k.actualamount,
k.discountamount,k.discountamount, c.name as category
FROM koupon.koupon k
INNER JOIN koupon.category c on c.categoryid = k.categoryid
where
k.startDate <= NOW() and endDate >= NOW()
AND c.isActive=true AND c.isDeleted=false AND k.isActive =true AND lower(k.status)=lower('approved')
order by k.kouponid">
<field column="kid" name="kid"/>
<field column="name" name="name"/>
<field column="image" name="image"/>
<field column="description" name="description"/>
<field column="startdate" name="startdate"/>
<field column="enddate" name="enddate"/>
<field column="actualamount" name="actualamount"/>
<field column="discountamount" name="discountamount"/>
<field column="discount" name="discount"/>
<field column="category" name="category"/>
</entity>
</document>
</dataConfig>
In this code use "k.startDate <= NOW() and endDate >= NOW()" for fetching in between record but solr query not providing this.
I have one solution that's start "To" End but that's not exact solution..
I am very tired for this Issue any know about this? How to solve this ?

You can try to use this mysql query for indexing:
WHERE (NOW() BETWEEN k.startDate and k.endDate)
instead of:
k.startDate <= NOW() and endDate >= NOW()
to prevent the error
The value of attribute "query" associated with an element type
"entity" must not contain the '<' character
For your Solr query
startdate:[* to NOW]
to work, make sure your startdate field conforms to the Solr dateField type. For more info on this, check this link

Related

Hibernate Named query not know error

I dont know why but when I import this project to Eclipse. This work well.
So, I think this is problem of eclipse project when import to InteliJ IDEA
This not easy such my imagine.
I have class Setting and Setting.hbm.xml for mapping hibernate.
In this class:
<hibernate-mapping>
<class name="Setting" table="setting" lazy="false">
<id name="id" column="id" type="integer">
<generator class="increment" />
</id>
.....
</class>
<query name="select.setting">
from Setting as s where s.id = ? order by s.name
</query>
Now, when I call function
this.getHibernateTemplate().findByNamedQuery("select.setting", params);
This return error
org.springframework.orm.hibernate4.HibernateSystemException: Named query not known: select.setting; nested exception is org.hibernate.MappingException: Named query not known: select.setting
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:218) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:343) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.orm.hibernate4.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:933) ~[spring-orm-4.1.6.RELEASE.jar:4.1.6.RELEASE]
Please give advice about it.
You can give a try with this.
<query name="select.setting">
<![CDATA[from Setting as s where s.id = ? order by s.name]]>
</query>
The XML parser gets confused of you are not using CDATA tag.
CDATA is way of telling the framework that its a data which should not be interpreted as a markup.
Hence as #Lovababu mentioned, include the query inside CDATA tags:
<query name="select.setting">
<![CDATA[from Setting as s where s.id = ? order by s.name]]>

Solr: Using the Block Join Children Query Parser

Currently I evaluate the Block Join Children Query Parser as described here.
Therefore I have created the following collection:
curl "http://localhost:8983/solr/admin/collections?action=CREATE&name=nestedPerson&numShards=6"`
Then I have inserted these two documents:
curl http://localhost:8983/solr/nestedPerson/update?commitWithin=3000 -d '<add>
<doc>
<field name="id">p1</field>
<field name="deceased">false</field>
<doc>
<field name="id">c1</field>
<field name="firstName">Bob</field>
</doc>
</doc>
<doc>
<field name="id">p2</field>
<field name="deceased">true</field>
<doc>
<field name="id">c2</field>
<field name="firstName">Max</field>
</doc>
</doc>
</add>'
Now I issue this query:
{!child of="id:p1"}firstName:Bob
Unfortunately this results in this error:
"msg": "Parent query yields document which is not matched by parents filter, docID=0",
How can the parent query (I guess that the part id:p1 is meant) yield a document that is not matched by the filter?
Take a look at the Solr Wiki that you refer to again here. Note the following:
The syntax for this parser is: q={!child of=<allParents>}<someParents>. The parameter allParents is a filter that matches only parent documents
In your example, the query is {!child of="id:p1"}firstName:Bob. The field id as used in<allParents>, but id is contained in both parent and child documents.
You need to introduce a field that only parent documents have, such as <field name="content_type">parentDocument</field> from the wiki. Once all parent documents (and only parent documents) have this field, you could submit the query as:
q={!parent which="content_type:parentDocument"}firstName:Bob
This would match child documents for firstName:Bob and return their parents. In a similar fashion, use q={!child of=<allParents>}<someParents> to match parent documents and return their children.

How to properly outline an Apache Solr document?

What is the difference between delta import and full import in ApacheSolr?
What are all the naming conventions to be followed while writing deltaImportQuery and deltaQuery ( ID, TXT_ID etc), any references or tutorial explaining in detail about differences/relations between deltaImportQuery and deltaQuery, Like what it is and what it does etc, How to write deltaImportQuery and deltaQuery ?
How to configure multiple entities in one document, Suppose if there are three tables in database like T1, T2, T3, Then in schema.xml how to configure this, issue with only one <uniquekey>somename</uniquekey> been considered for each schema.xml file?
How to parse BLOB type input from mysql, following convert ( column_name using utf8 ) as alias_name solves this but what is the right convention ,some other methods are also available like using TikaEntityProcessor/ writing custom BLOBTRANSFORMERS etc ?
Just like ORM any concepts explaining how to denormalize and outline an Apache Solr document , Any showcase project including all use cases and features ?
How to configure entities like this in data-config.xml?
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/solrdemo" user="root" password="123" batchSize='1' />
<document name="user">
<entity name ="user1" query = "SELECT * FROM user1">
<field column='id' name='id1' />
</entity>
<entity name ="user2" query = "SELECT * FROM user2">
<field column='id' name='id2' />
</entity>
<entity name ="user3" query = "SELECT * FROM user3">
<field column='id' name='id3' />
</entity>
</document>
</dataConfig>
When the above kind of configuration is done then in schema.xml which id should be configured into <uniquekey></uniquekey> ?
The result of above configuration is
Indexing completed. Added/Updated: 2,866 documents. Deleted 0 documents. (Duration: 03s)
Indexing is successfully completed but 0 documents added / updated , How to resolve this issue ?
Overall any references available for proper conventions and configurations to work with Apache Solr?

How to set column name using setString() hibernate

<sql-query name="sql">
select :COLUMN_NAME from table.
</sql-query>
I want to set COLUMN_NAME using
this.sessionFactory.getCurrentSession().getNamedQuery("sql")
.setString("COLUMN_NAME", "id");
I got a wrong result when I use this code (I know where I fail). Is there any way to set COLUMN_NAME using getNamedQuery() and setString().
Have you tried setParameter method?
this.sessionFactory.getCurrentSession().getNamedQuery("sql")
.setParameter("COLUMN_NAME", "id");
Further info
You must add <return-scalar column="name_first" type="string" /> to get specific column. like
<sql-query name="sql">
<return-scalar column="COLUMN_NAME" type="java.lang.String" />
select :COLUMN_NAME from table.
</sql-query>
Or you can use setResultTransformer method if you had created a bean class for that table.

Retrieving attribute values depending on the value of another attribute using xpath

I have the following xml doc:
<database>
<order>
<data>
<field name="time" value="10:10:10" />
</data>
<data>
<field name="product" value="product_type_1">
<field name="attributeA" value="Foo" />
<field name="attributeB" value="Bar" />
</field>
<field name="attributeC" value="Jeam" />
<field name="attributeD" value="Beam" />
<field name="attributeE" value="Deam" />
</data>
</order>
<order>
<data>
<field name="time" value="10:10:11" />
</data>
<data>
<field name="product" value="product_type_2">
<field name="attributeF" value="Bravo" />
<field name="attributeG" value="Echo" />
</field>
<field name="attributeC" value="Jeam2" />
<field name="attributeD" value="Beam2" />
<field name="attributeJ" value="Charlie" />
<field name="attributeK" value="Tango" />
<field name="attributeL" value="Zulu" />
</data>
</order>
It is a set of "order" elements but the "field" (both on quantity and type) depend on the value of the element whose name is "product". I am interested in extracting info depending on the value of the product. More specifically, I would end up with something like this table:
Time Product AttributeA AttributeB AttributeC AttributeD
10:10:10 product_type_1 Foo Bar Jeam Beam
10:10:11 product_type_2 Jeam2 Beam2
In other words I am trying to "cut" unesessary info depending on the value of child element of "order". I am trying to achive this by using xpath (in java) but I am stuck. It is impossible for me to emulate the "if" condition described above.
I am thinking of using and xpath query to retrieve one order element at a time, then query for the product type and then choose the apropriate xpath to retieve the coresponding attributes, but that sounds really inneficient and slow.
Is it possible to do it more efficiently? Is xpath not the right answer here?
Thanks in advance.
P.S: The alignment and organization of the data you see above doesn't really matter as long as I retrieve the correct data then I am sure I'll be able to print them somehow.
If you want to use XPath, you will need at least XPath 3.0 or XQuery (this code is valid in both of them). Have a look at XQuery engines if you want to use this in Java, for example Saxon, BaseX, eXist DB, ...
for $order in /database/order
return string-join((
$order//field[#name='time']/#value,
$order//field[#name='product']/#value,
($order//field[#name='attributeA']/#value, '')[1],
($order//field[#name='attributeB']/#value, '')[1],
($order//field[#name='attributeC']/#value, '')[1],
($order//field[#name='attributeD']/#value, '')[1]),
' ')
The pattern used for the attributes makes sure that empty values do not break the table layout (so for the second product type, attributes C and D do not get attributes A and B). is the tab character.
If you want to use Java for further processing the output, I'd go with this: Fetch all orders (/database/order) and loop over them. Then, for each order, use DOM (or XPath again) to fetch the nodes you need. Yet it seems that the question you asked is not your actual problem, it might be that using XQuery could lead to a cleaner solution.

Categories