Why does TextQuery failed to find result

classic Classic list List threaded Threaded
10 messages Options
siva siva
Reply | Threaded
Open this post in threaded view
|

Why does TextQuery failed to find result

This post was updated on .
Hi All,
I have .Net ClientServerIgnitePersistenceApp v2.7.6 to create Ignite caches and data loading using DataStreamer.And for TextQuery i am using thick client here is the cache configuration and Model class details.
Model class:Person model class contains both fields marked as QuerySqlField and QueryTextField.
public class Person: ICustomCacheStore
    {
        [QueryTextField]
        public string Payload { get; set; }
	[QuerySqlField]
	public string UUID {get;set;}
	[QuerySqlField]
	public string Name {get;set;}
    }
Cache configuration:

struct QueryEntityIndexFields
{
	public string[] PrimaryKeys;
	public Type ModelType;        
}
	
QueryEntityIndexFields[] queryEntityIndexFieldsList = new[] {            
    new QueryEntityIndexFields(){PrimaryKeys=new []{ "UUID" }, ModelType=  typeof(Person) }            
 };

 
List<QueryEntity> queryList = new List<QueryEntity>();
foreach (var modelObject in queryEntityIndexFieldsList)
{
	var query = new QueryEntity(typeof(string), modelObject.ModelType)
	{
		Indexes = new List<QueryIndex>(modelObject.PrimaryKeys.Count() + 1)
			{
				new QueryIndex(true,0,modelObject.PrimaryKeys)
			}
	};
	queryList.Add(query);
}
            
cacheName = cacheName.ToUpper();
var templateName = cacheName.Remove(cacheName.Length - 1, 1) + "*";

var cacheCfg = new CacheConfiguration(templateName)
{
	Name = cacheName,
	CacheStoreFactory = new TenantCacheStoreFactory(_logger, connectionString),
	KeepBinaryInStore = false,  // Cache store works with deserialized data.
	ReadThrough = true,
	WriteThrough = true,
	WriteBehindEnabled = true,
	QueryEntities = queryList,
	WriteBehindFlushThreadCount = 2,
	CacheMode = CacheMode.Partitioned,
	Backups = 0,
	DataRegionName = "IgniteDataRegion",
	EvictionPolicy = new LruEvictionPolicy
	{
		MaxSize = 100000
	}
};

TextQuery search sample code:
var textquery = new TextQuery(typeof(Person), "daily");
var cursor = cache.Query(textquery);

foreach (var cacheEntry in cursor)
{
	Console.WriteLine(cacheEntry.Value);
}

Search Text:
Person Model class Payload property contains json string.
{
  "comments": "Enter a description of the daily activities",
  "authorname": "cp r",
  "project": "MR",
  "count": "4",
  "userid": "0a2802ca-4970-477b-b4be-0cb74a67dcbc"
}

Not getting what am i doing wrong and no error on consle.
It's doesn't returning result.How to get search text result from cache?
Please any further details needed let me know.
Thanks.

ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hello!

This answer seems relevant: https://stackoverflow.com/a/65069605/36498

Regards,
--
Ilya Kasnacheev


вт, 1 дек. 2020 г. в 20:23, siva <[hidden email]>:
Hi All,
I have .Net ClientServerIgnitePersistenceApp v2.7.6 to create Ignite caches
and data loading using DataStreamer.And for TextQuery i am using thick
client here is the cache configuration and Model class details.
*Model class:*Person model class contains both fields marked as
QuerySqlField and QueryTextField.




*TextQuery search sample code:*


*Search Text:*
Person Model class Payload property contains json string.


It's doesn't returning result.How to get search text result from cache?
Please any further details needed let me know.
Thanks.





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
siva siva
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hi,
Thanks for the reply.
I am already using Thick client.But not able to get result from Cache
Query.And it's returning empty result.

Quite i didn't understand wrap TextQuery call in a Service or Compute Task
from the above refrence.

can you please provide little bit more context on this.

Thanks.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hello!

Please show your code.

Regards,
--
Ilya Kasnacheev


ср, 2 дек. 2020 г. в 15:14, siva <[hidden email]>:
Hi,
Thanks for the reply.
I am already using Thick client.But not able to get result from Cache
Query.And it's returning empty result.

Quite i didn't understand wrap TextQuery call in a Service or Compute Task
from the above refrence.

can you please provide little bit more context on this.

Thanks.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
siva siva
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hi,
Please find the given below details.



here is the complete code(CacheConfiguration,TexTquery method)  Github
<https://github.com/CP-Ram/IgniteTextQueryDotNetTestApp/blob/81c7db2287064aa6eb40ed885a68e197face7430/IngiteTextQueryTestApp/IgniteThickClientTextQueryService.cs#L58>
ThickClient TextQuery Test method.

Thanks.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hello!

I'm really suspicious of how you call GetOrCreateCache in GetIConstructionCacheStore(string cacheName)

I would expect that it will create a cache without any indexing (i.e. with no possibility of sql or text queries).

Make sure to always use GetOrCreateCache(cacheName, typeof(ValueType): https://apacheignite-net.readme.io/docs/sql-queries#configuring-sql-indexes-using-attributes

I just don't see how your GetOrCreateCache will work given that the cache will always be created, and that it's too late to add cache cfgs to client config once it's already started.

Regards,
--
Ilya Kasnacheev


пн, 14 дек. 2020 г. в 12:34, siva <[hidden email]>:
Hi,
Please find the given below details.



here is the complete code(CacheConfiguration,TexTquery method)  Github
<https://github.com/CP-Ram/IgniteTextQueryDotNetTestApp/blob/81c7db2287064aa6eb40ed885a68e197face7430/IngiteTextQueryTestApp/IgniteThickClientTextQueryService.cs#L58>
ThickClient TextQuery Test method.

Thanks.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
siva siva
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

This post was updated on .
Hi,
Actually I am creating Indexing and creating cache with typeof(interface) which is implemented by model class.

Can you please look into this Given class method cache configuration etc and give me suggestion what is the wrong. I am not getting result from textquery but sql  query working fine.

Full details:
IgniteClient,CacheConfiguration and QueryEntity and my start method
Task<string> SearchTextQueryTest(string cacheName,string searchText)

namespace ConstructionSearchApi.Ignite
{
    public class IgniteThickClientTextQueryService
    {
        private readonly IgniteClientConfiguration _igniteClientConfiguration;
        private readonly string _endPoint;
        private readonly string[] _endPoints;
        public static IIgnite _IGNITE_CLIENT;

        public IgniteThickClientTextQueryService(string endPoint)//localhost
        {
            var endpoints = new List<string>();
            if (endPoint.Contains(","))
            {
                endpoints = endPoint.Split(',').ToList();
            }
            else
            {
                endpoints.Add(endPoint);
            }
            _igniteClientConfiguration = new IgniteClientConfiguration
            {
                Endpoints = endpoints,
                SocketTimeout = TimeSpan.FromSeconds(20000)
            };
            this._endPoint = endPoint;
            this._endPoints = endpoints.ToArray();
        }

        public async Task<string> SearchTextQueryTest(string cacheName,string searchText)
        {
            try
            {
                    var cache = await GetStoreCache(cacheName);
                    var textquery = new TextQuery(typeof(CommonConstruction), "Metric");
                    var cursor = cache.Query(textquery).GetAll();
                    foreach (var cacheEntry in cursor)
                    {
                        Console.WriteLine(cacheEntry.Value);
                    }
                Console.WriteLine("End of query");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            string res = "";
            return await Task.FromResult(res);
        }

       
        private async Task<ICache<string, IConstructionCacheStore>> GetStoreCache(string cacheName)
        {
            try
            {
                if(_IGNITE_CLIENT==null)
                GetOrStartIgniteClient();

                var cacheConfig = await GetCacheConfiguration(cacheName);
                _IGNITE_CLIENT.AddCacheConfiguration(cacheConfig);
                var cache = _IGNITE_CLIENT.GetOrCreateCache<string, IConstructionCacheStore>(cacheName);
               return cache;
            }
            catch (CacheException ex)
            {
                //Per cache Per Node one time manual exception
                throw;
            }
            catch (Exception ex)
            {
                throw;
            }
        }

       
        public async Task<CacheConfiguration> GetCacheConfiguration(string cacheName)
        {
             EventLogger _logger = new EventLogger();

            var queryList = await GetQueryEntitiesListAsync(ConstructionCommonModels);

            cacheName = cacheName.ToUpper();
            var templateName = cacheName.Remove(cacheName.Length - 1, 1) + "*";
            var cacheCfg = new CacheConfiguration(templateName)
            {
                Name = cacheName,
                CacheStoreFactory = new ConstructionTenantCacheStoreFactory(_logger, string.Empty),
                KeepBinaryInStore = false,  // Cache store works with deserialized data.
                ReadThrough = true,
                WriteThrough = true,
                WriteBehindEnabled = true,
                QueryEntities = queryList,
                WriteBehindFlushThreadCount = 2,
                CacheMode = CacheMode.Partitioned,
                Backups = 0,
                DataRegionName = "IgniteDataRegion",
                EvictionPolicy = new LruEvictionPolicy
                {
                    MaxSize = 100000
                },
                GroupName= "F2DEDF6E-393E-42BC-9BB3-E835A1063B30_6EFB69B0-269F-4F92-98CF-24BC0D34BA98"
            };

            return cacheCfg;
        }

        private static readonly QueryEntityIndexFields[] ConstructionCommonModels = new[] {            //Common Construction
            new QueryEntityIndexFields(){PrimaryKeys=new[] { "UUID" }, ModelType=  typeof(CommonConstruction) }
        };
        private async Task<List<QueryEntity>> GetQueryEntitiesListAsync(QueryEntityIndexFields[] queryEntityIndexFieldsList)
        {
            List<QueryEntity> queryList = new List<QueryEntity>();
            foreach (var modelObject in queryEntityIndexFieldsList)
            {
                var query = new QueryEntity(typeof(string), modelObject.ModelType)
                {
                    Indexes = new List<QueryIndex>(modelObject.PrimaryKeys.Count() + 1)
                        {
                            new QueryIndex(true,0,modelObject.PrimaryKeys)
                        }
                };
                queryList.Add(query);
            }
            return queryList;
        }
      
        public IIgnite GetOrStartIgniteClient()
        {
            return StartIgniteClient();
        }       

        public IIgnite StartIgniteClient()
        {
            try
            {
                if (_IGNITE_CLIENT == null)
                {
                    Ignition.ClientMode = true;
                    // Connect to the cluster.
                    // _IGNITE_CLIENT = Ignition.Start("C:\\Users\bizruntime-86\\source\\client-config.xml");

                    _IGNITE_CLIENT = Ignition.TryGetIgnite("TextQueryTestNode");
                    if (_IGNITE_CLIENT == null)
                        _IGNITE_CLIENT = Ignition.Start(GetIgniteConfiguration());
                    //_IGNITE_CLIENT = Ignition.Start(Directory.GetCurrentDirectory()+ "\\client-config.xml");//GetIgniteConfiguration());
                }

            }
            catch (Exception ex)
            {
                throw;
            }

            return _IGNITE_CLIENT;
        }
        public IgniteConfiguration GetIgniteConfiguration()
        {
            IgniteConfiguration config = null;
            try
            {
                config = new IgniteConfiguration
                {

                    IgniteInstanceName = "TextQueryTestNode",

                    DiscoverySpi = new TcpDiscoverySpi
                    {
                        IpFinder = new TcpDiscoveryStaticIpFinder
                        {
                            Endpoints = _endPoints//new[] { "104.211.24.238" }//127.0.0.1 or ip
                        },
                        SocketTimeout = TimeSpan.FromSeconds(3000)
                    },
                    DataStorageConfiguration = new DataStorageConfiguration()
                    {
                        DefaultDataRegionConfiguration = new DataRegionConfiguration()
                        {
                            Name = "IgniteDataRegion",
                            PersistenceEnabled = true
                        },
                        StoragePath = "C:\\client\\storage",
                        WalPath = "C:\\client\\wal",
                        WalArchivePath = "C:\\client\\walArchive"
                    },
                    WorkDirectory = "C:\\client\\work",
                    // Explicitly configure TCP communication SPI by changing local port number for
                    // the nodes from the first cluster.
                    CommunicationSpi = new TcpCommunicationSpi()
                    {
                        LocalPort = 47100
                    },
                    PeerAssemblyLoadingMode = Apache.Ignite.Core.Deployment.PeerAssemblyLoadingMode.CurrentAppDomain

                };
            }
            catch (Exception ex)
            {
                throw;
            }
            return config;
        }
    }

    struct QueryEntityIndexFields
    {
        public string[] PrimaryKeys;
        public Type ModelType;
    }
}

Model class
public class CommonConstruction : IConstructionCacheStore
    {
        [QuerySqlField]
        public string ParentEntityId { get; set; }
        [QuerySqlField]
        public string Parent { get; set; }
        [QuerySqlField]
        public string UUID { get; set; }
        [QueryTextField]
        public string Payload { get; set; }
        [QuerySqlField]
        public string Type { get; set; }
        [QuerySqlField]
        public string TenantId { get; set; }
        [QuerySqlField]
        public string TenantName { get; set; }
        [QuerySqlField]
        public string CreatedBy { get; set; }
        [QuerySqlField]
        public string ModifiedBy { get; set; }
        [QuerySqlField]
        public string EntityTimeZone { get; set; }
        [QuerySqlField]
        public string IsDeleted { get; set; }
        [QuerySqlField]
        private DateTime _ModifiedDateTime;
        public DateTime ModifiedDateTime
        {
            get { return _ModifiedDateTime; }
            set
            {
                _ModifiedDateTime = DateTime.SpecifyKind(value != null ? value : DateTime.UtcNow, DateTimeKind.Utc);
            }
        }
        [QuerySqlField]
        private DateTime _CreatedDateTime;
        public DateTime CreatedDateTime
        {
            get { return _CreatedDateTime; }
            set
            {
                _CreatedDateTime = DateTime.SpecifyKind(value != null ? value : DateTime.UtcNow, DateTimeKind.Utc);
            }
        }
        [QuerySqlField]
        private DateTime _SyncDateTime;
        public DateTime SyncDateTime
        {
            get { return _SyncDateTime; }
            set
            {
                _SyncDateTime = DateTime.SpecifyKind(value != null ? value : DateTime.UtcNow, DateTimeKind.Utc);
            }
        }

        public CommonConstruction()
        {
            CreatedDateTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
            ModifiedDateTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
            SyncDateTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
        }
    }

Thanks
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hello!

Unfortunately I can't see any image here. Please provide a link or plain text.

Regards,
--
Ilya Kasnacheev


пн, 14 дек. 2020 г. в 17:55, siva <[hidden email]>:
Hi,
Actually I am creating Indexing and creating cache with typeof(interface)
which is implemented by model class.

Can you please look into this Given class methods cache configuration etc
and give me suggestion what is the wrong. I am not getting result from
textquery but sql  query working fine.

*Full details:*
IgniteClient,CacheConfiguration and QueryEntity and my start method





Thanks



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
siva siva
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hi,
Not sure why format code ,images are not receiving in email.
Please find
Here is the Nabble code  link
<http://apache-ignite-users.70518.x6.nabble.com/Why-does-TextQuery-failed-to-find-result-td34759.html#a34877>  




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ilya.kasnacheev ilya.kasnacheev
Reply | Threaded
Open this post in threaded view
|

Re: Why does TextQuery failed to find result

Hello!

Ok, I see. Seems I have answered in a different thread.

Regards,
--
Ilya Kasnacheev


пн, 14 дек. 2020 г. в 19:15, siva <[hidden email]>:
Hi,
Not sure why format code ,images are not receiving in email.
Please find
Here is the Nabble code  link
<http://apache-ignite-users.70518.x6.nabble.com/Why-does-TextQuery-failed-to-find-result-td34759.html#a34877




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