Hi, Ilya.

Could you please provide a reproducer of wrong behavior? Looks like I'm
missing smth in your idea. There is my code [1] with String class as value,
and TextQuery works correctly without the annotation QueryTextField. And I
expect this behavior.

> case of plane strings as cache values (instead of pojo class from my
example) lucene index would be created no matter if we ask for it or not
It's not correct. If you create cache CacheConfiguration<Integer, String>
it will not create LuceneIndex, as there is no table with String as value
class. You can check it with my code just replace Long and String
classes in cache definition.

[1] https://gist.github.com/timoninmaxim/e477ddfcbe56ec9892c7ba6ad44bfadb

On Thu, Jun 3, 2021 at 10:56 AM Ilya Korol <llivezk...@gmail.com> wrote:

> Thanks for feedback Maksim, but let me disagree with you.
>
> As far as i understand
>
> CacheConfiguration.setIndexedTypes(Long.class, String.class);
>
> Is just the hint for Ignite about data that should be indexed, but what
> kind of index should be created depends on our configuration. For example:
>
> public class StringValue implements Serializable {
>
>      @QuerySqlField(index = true)
>      private final long id;
>
>      @QueryTextField
>      private final String name;
>
> }
>
> In this case i explicitly define that i need text/lucene index for name
> field via marking it with @QueryTextField annotation. Doing so i'm able
> to perform text queries:
>
> cache.query(new TextQuery(StringValue.class, "value"))
>              .getAll()
>              .forEach(e -> System.out.println(e.toString()));
>
> Without @QueryTextField annotation query will return nothing.
>
> So setIndexedTypes(..) is just not enough for proper lucene index
> initiation. But in case of plane strings as cache values (instead pf
> pojo class from my example) lucene index would be created no matter if
> we ask for it or not:
>
> // IgniteH2Indexing#queryLocalText(..)
>
> if (tbl != null && tbl.luceneIndex() != null) {
>      Long qryId = runningQueryManager().register(qry, TEXT, schemaName,
> true, null);
>
>      try {
>          // We will reach this line if we use String as cache values or
> if we used @QueryTextField annotation
>          return tbl.luceneIndex().query(qry.toUpperCase(), filters, limit);
>
>      } finally {
>          runningQueryManager().unregister(qryId, null);
>      }
> }
>
>
>
> 02.06.2021 23:40, Maksim Timonin пишет:
> > Hi, Ilya! AFAIK, to create LuceneIndex it's required to do this:
> >
> > CacheConfiguration.setIndexedTypes(Long.class, String.class);
> >
> > It's pretty straightforward, a user wants the value class to be indexed.
> If
> > you just create a simple cache (without entities, indexed types) with
> > String.class as value it won't be indexed, as indexes created per table,
> > not per cache.
> >
> > Do I miss something?
> >
> > On Wed, Jun 2, 2021 at 12:56 PM Ilya Korol <llivezk...@gmail.com> wrote:
> >
> >> Hi, All.
> >>
> >> According to https://issues.apache.org/jira/browse/IGNITE-14805 there
> is
> >> default index creation for caches with String values:
> >>
> >>
> >> if (type().valueClass() == String.class) {
> >>       try {
> >>           luceneIdx = new GridLuceneIndex(idx.kernalContext(),
> >> tbl.cacheName(), type);
> >>       }
> >>       catch (IgniteCheckedException e1) {
> >>           throw new IgniteException(e1);
> >>       }
> >> }
> >>
> >>
> >> Does this really necessary?  What about disabling this feature by
> >> default and enabling it only by demand (to reduce unnecessary
> >> performance hit even if its not very huge)? I guess additional option
> >> could be introduced to do so.
> >>
> >> Any ideas?
> >>
> >>
>

Reply via email to