You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by raja24 <nt...@tiaa.org> on 2019/07/23 18:38:54 UTC

Cache Query Filter Logic

Hi,

I'm new to Apache Ignite and doing a POC with Cache Query filter and didn't
work.
My code is as below and sure I'm missing the logic. Please help.

Config:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
					<property name="name" value="service-cache"/>
					<property name="backups" value="1"/>
					<property name="cacheMode" value="PARTITIONED"/>
					<property name="atomicityMode" value="ATOMIC"/>
					<property name="expiryPolicyFactory">
						<bean parent="expiryPolicy"/> 
					</property>
					<property name="indexedTypes">
                        <list>
                            <value>java.lang.Integer</value>
                            <value>org.apache.Fund</value>
                        </list>
                    </property> 
				</bean>

Java Code:
// get or create cache
		IgniteCache <Integer, Fund> cache =
ignite.getOrCreateCache("service-cache"); // put some cache elements
				
	    final int keyCnt = 10;

	    // Create batch.
	    Map<Integer, Fund> batch = new HashMap<>();
	    for (int i = 0; i < keyCnt; i++){
	    	Fund fund = new Fund();
	    	fund.setName("test"+i);
	        batch.put(i, fund);
	    }

	    // Bulk-store entries in cache.
	    cache.putAll(batch);
	    // Query for all people with "Master Degree" in their resumes.
		 TextQuery txt = new TextQuery(Fund.class, "name:test1");
		 
		 try (QueryCursor<Entry&lt;Integer, Fund>> masters = cache.query(txt)) {
		   for (Entry<Integer, Fund> e : masters)
		     System.out.println(e.getValue().getName());
		 }


Fund Class:
public class Fund implements Serializable{
	private static final long serialVersionUID = 1L;
		private String name;
	
	
	
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
}


Thanks,
Raja.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Cache Query Filter Logic

Posted by raja24 <nt...@tiaa.org>.
Igor,

I have tries as per your suggestion still didn't work.

import org.apache.ignite.cache.query.annotations.QueryTextField;

public class Fund implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private int reportingSeq;
	
	@QueryTextField
	private String name;
	
	
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	
	public int getReportingSeq() {
		return reportingSeq;
	}
	public void setReportingSeq(int reportingSeq) {
		this.reportingSeq = reportingSeq;
	}

Thanks,
Raja.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Cache Query Filter Logic

Posted by Игорь Беляков <ig...@gmail.com>.
Hi Raja,

To use TextQuery you should apply @QueryTextField annotation for "name"
field in your "Fund" model.

Regards,
Igor

On Tue, Jul 23, 2019 at 9:39 PM raja24 <nt...@tiaa.org> wrote:

> Hi,
>
> I'm new to Apache Ignite and doing a POC with Cache Query filter and didn't
> work.
> My code is as below and sure I'm missing the logic. Please help.
>
> Config:
> <bean class="org.apache.ignite.configuration.CacheConfiguration">
>                                         <property name="name"
> value="service-cache"/>
>                                         <property name="backups"
> value="1"/>
>                                         <property name="cacheMode"
> value="PARTITIONED"/>
>                                         <property name="atomicityMode"
> value="ATOMIC"/>
>                                         <property
> name="expiryPolicyFactory">
>                                                 <bean
> parent="expiryPolicy"/>
>                                         </property>
>                                         <property name="indexedTypes">
>                         <list>
>                             <value>java.lang.Integer</value>
>                             <value>org.apache.Fund</value>
>                         </list>
>                     </property>
>                                 </bean>
>
> Java Code:
> // get or create cache
>                 IgniteCache <Integer, Fund> cache =
> ignite.getOrCreateCache("service-cache"); // put some cache elements
>
>             final int keyCnt = 10;
>
>             // Create batch.
>             Map<Integer, Fund> batch = new HashMap<>();
>             for (int i = 0; i < keyCnt; i++){
>                 Fund fund = new Fund();
>                 fund.setName("test"+i);
>                 batch.put(i, fund);
>             }
>
>             // Bulk-store entries in cache.
>             cache.putAll(batch);
>             // Query for all people with "Master Degree" in their resumes.
>                  TextQuery txt = new TextQuery(Fund.class, "name:test1");
>
>                  try (QueryCursor<Entry&lt;Integer, Fund>> masters =
> cache.query(txt)) {
>                    for (Entry<Integer, Fund> e : masters)
>                      System.out.println(e.getValue().getName());
>                  }
>
>
> Fund Class:
> public class Fund implements Serializable{
>         private static final long serialVersionUID = 1L;
>                 private String name;
>
>
>
>         public void setName(String name) {
>                 this.name = name;
>         }
>         public String getName() {
>                 return name;
>         }
> }
>
>
> Thanks,
> Raja.
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Cache Query Filter Logic

Posted by raja24 <nt...@tiaa.org>.
The problem is I didn't put updated jar in the server.


Thanks,
Raja.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: Cache Query Filter Logic

Posted by Denis Magda <dm...@apache.org>.
Could you please share the root cause and a solution with everyone? It
might be the case that someone else stumbles upon the same issue.

-
Denis


On Tue, Jul 30, 2019 at 1:09 PM raja24 <nt...@tiaa.org> wrote:

> I have fixed it and working fine.
>
>
> Thanks,
> Raja.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>

Re: Cache Query Filter Logic

Posted by raja24 <nt...@tiaa.org>.
I have fixed it and working fine.


Thanks,
Raja.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/