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&lt;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&lt;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/

Reply via email to