You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by zbyszek <zb...@yahoo.com> on 2017/11/28 17:40:40 UTC
Lucene query syntaxt support in TextQuery ?
Hello All,
I wonder if anybody could help with the following:
I am trying to get Lucene syntax working in my code below.
According to this post -
http://apache-ignite-users.70518.x6.nabble.com/Can-TextQuery-specify-only-one-field-of-the-class-td2300.html
fielded data should be supported (like TextQuery(Person.class,
"resume:Master");), but cannot get it running for some reason.
Could you advise?
Thank you in advance,
zbyszek
private static void test() {
// start ignite
IgniteConfiguration iCfg = new IgniteConfiguration();
String workDirectory = System.getProperty("user.home") +
File.separator + "ignite";
iCfg.setWorkDirectory(workDirectory);
System.out.println(String.format(">>> Starting cache. Working
directory %s ...", workDirectory));
Ignite ignite = Ignition.start(iCfg);
System.out.println(">>> Cache started successfully");
// configure cache
CacheConfiguration<Long, BinaryObject> cCfg = new
CacheConfiguration<>();
cCfg.setName("MyCache");
cCfg.setStoreKeepBinary(true);
cCfg.setCacheMode(CacheMode.LOCAL);
cCfg.setCopyOnRead(false);
cCfg.setBackups(0);
cCfg.setWriteBehindEnabled(false);
cCfg.setReadThrough(false);
cCfg.setWriteThrough(false);
// define query
QueryEntity qe = new
QueryEntity(Long.class.getTypeName(),"MyValue");
qe.addQueryField("text1", String.class.getTypeName(), "text1");
qe.addQueryField("text2", String.class.getTypeName(), "text2");
LinkedHashMap<String, Boolean> f1 = new LinkedHashMap<>();
f1.put("text1", false);
QueryIndex idx1 = new QueryIndex(f1, QueryIndexType.FULLTEXT);
idx1.setName("idx1");
LinkedHashMap<String, Boolean> f2 = new LinkedHashMap<>();
f2.put("text2", false);
QueryIndex idx2 = new QueryIndex(f2, QueryIndexType.FULLTEXT);
idx2.setName("idx2");
qe.setIndexes(Arrays.asList(idx1, idx2));
cCfg.setQueryEntities(Collections.singletonList(qe));
IgniteCache<Long, BinaryObject> cache =
ignite.createCache(cCfg).withKeepBinary();
// insert data
IgniteBinary binary = ignite.binary();
BinaryObjectBuilder builder = binary.builder("MyValue");
builder.setField("id", 0L);
builder.setField("text1", "Apache");
builder.setField("text2", "Ignite");
cache.put(0L, builder.build());
builder.setField("id", 1L);
builder.setField("text1", "Ignite");
builder.setField("text2", "Apache");
cache.put(1L, builder.build());
builder.setField("id", 2L);
builder.setField("text1", "Apache");
builder.setField("text2", "Spark");
cache.put(2L, builder.build());
// working query
TextQuery<Long, BinaryObject> goodQuery = new TextQuery<>("MyValue",
"S*");
QueryCursor<Cache.Entry<Long, BinaryObject>> results1 =
cache.query(goodQuery);
results1.forEach(entry -> {
System.out.println(">>> (1) " + entry.getValue());
});
// failing query
TextQuery<Long, BinaryObject> badQuery = new TextQuery<>("MyValue",
"text1:Apache");
QueryCursor<Cache.Entry<Long, BinaryObject>> results2 =
cache.query(badQuery);
results2.forEach(entry -> {
System.out.println(">>> (2) " + entry.getValue());
});
// cleanup
cache.destroy();
ignite.close();
}
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Lucene query syntaxt support in TextQuery ?
Posted by zbyszek <zb...@yahoo.com>.
Hi Andrew,
Indeed, this is related to field names:
1. In ver. 2.3 the solution is to use uppercase names for query to work,
although my all fields are lowercase (as you can see in attached example). I
would still consider this as a bug though....
2. In ver. 2.0 it works as expected - it works for the casing used to name
the fields (lowercase in that case)
reagrds,
zbyszek
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Lucene query syntaxt support in TextQuery ?
Posted by Andrey Mashenkov <an...@gmail.com>.
Hi,
Have you tries to use lowercase or uppercase for field name,
AFAIK field name character's case may be a reason.
Would you please, let us know if it help you or not?
On Wed, Nov 29, 2017 at 3:24 PM, zbyszek <zb...@yahoo.com> wrote:
> Val, thank you for confirmation.
>
> zbyszek
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
--
Best regards,
Andrey V. Mashenkov
Re: Lucene query syntaxt support in TextQuery ?
Posted by zbyszek <zb...@yahoo.com>.
Val, thank you for confirmation.
zbyszek
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Lucene query syntaxt support in TextQuery ?
Posted by vkulichenko <va...@gmail.com>.
Looks like a regression bug, created a ticket:
https://issues.apache.org/jira/browse/IGNITE-7055
-Val
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/