Exemplo n.º 1
0
        public static async Task <List <HitomiMetadata> > Search3(HitomiDataQuery query)
        {
            int number = Environment.ProcessorCount;
            int term   = HitomiData.Instance.metadata_collection.Count / number;

            List <Task <List <HitomiMetadata> > > arr_task = new List <Task <List <HitomiMetadata> > >();

            for (int i = 0; i < number; i++)
            {
                int k = i;
                if (k != number - 1)
                {
                    arr_task.Add(new Task <List <HitomiMetadata> >(() => search_internal(query, k * term, k * term + term)));
                }
                else
                {
                    arr_task.Add(new Task <List <HitomiMetadata> >(() => search_internal(query, k * term, HitomiData.Instance.metadata_collection.Count)));
                }
            }

            Parallel.ForEach(arr_task, task => task.Start());
            await Task.WhenAll(arr_task);

            List <HitomiMetadata> result = new List <HitomiMetadata>();

            for (int i = 0; i < number; i++)
            {
                result.AddRange(arr_task[i].Result);
            }
            result.Sort((a, b) => b.ID - a.ID);

            return(result);
        }
Exemplo n.º 2
0
        public static async Task <List <HitomiMetadata> > SearchAsync(string search)
        {
            HitomiDataQuery query          = new HitomiDataQuery();
            List <string>   positive_data  = new List <string>();
            List <string>   negative_data  = new List <string>();
            List <string>   request_number = new List <string>();
            int             start_element  = 0;
            int             count_element  = 0;
            bool            recent         = false;
            int             recent_count   = 0;
            int             recent_start   = 0;

            search.Trim().Split(' ').ToList().ForEach((a) => { if (a.StartsWith("/"))
                                                               {
                                                                   start_element = Convert.ToInt32(a.Substring(1));
                                                               }
                                                      });
            search.Trim().Split(' ').ToList().ForEach((a) => { if (a.StartsWith("?"))
                                                               {
                                                                   count_element = Convert.ToInt32(a.Substring(1));
                                                               }
                                                      });
            search.Trim().Split(' ').ToList().ForEach((a) => { if (!a.Contains(":") && !a.StartsWith("/") && !a.StartsWith("?"))
                                                               {
                                                                   positive_data.Add(a.Trim());
                                                               }
                                                      });
            query.Common = positive_data;
            query.Common.Add("");
            query.TagExclude = Settings.Instance.Hitomi.ExclusiveTag.ToList();
            foreach (var elem in from elem in search.Trim().Split(' ') where elem.Contains(":") where !elem.StartsWith("/") where !elem.StartsWith("?") select elem)
            {
                if (elem.StartsWith("tag:"))
                {
                    if (query.TagInclude == null)
                    {
                        query.TagInclude = new List <string>()
                        {
                            elem.Substring("tag:".Length)
                        }
                    }
                }
                ;
Exemplo n.º 3
0
        private static List <HitomiMetadata> search_internal(HitomiDataQuery query, int starts, int ends)
        {
            List <HitomiMetadata> result = new List <HitomiMetadata>();

            for (int i = starts; i < ends; i++)
            {
                var v = HitomiData.Instance.metadata_collection[i];
                if (query.Common.Contains(v.ID.ToString()))
                {
                    result.Add(v);
                    continue;
                }
                string lang = v.Language;
                if (v.Language == null)
                {
                    lang = "n/a";
                }
                if (Settings.Instance.Hitomi.Language != "all" &&
                    Settings.Instance.Hitomi.Language != lang)
                {
                    continue;
                }
                if (query.Language != null &&
                    query.Language != lang)
                {
                    continue;
                }
                if (query.TagExclude != null)
                {
                    if (v.Tags != null)
                    {
                        int intersec_count = 0;
                        foreach (var tag in query.TagExclude)
                        {
                            if (v.Tags.Any(vtag => vtag.ToLower().Replace(' ', '_') == tag.ToLower()))
                            {
                                intersec_count++;
                            }

                            if (intersec_count > 0)
                            {
                                break;
                            }
                        }
                        if (intersec_count > 0)
                        {
                            continue;
                        }
                    }
                }
                bool[] check = new bool[query.Common.Count];
                if (query.Common.Count > 0)
                {
                    IntersectCountSplit(v.Name.Split(' '), query.Common, ref check);
                    IntersectCountSplit(v.Tags, query.Common, ref check);
                    IntersectCountSplit(v.Artists, query.Common, ref check);
                    IntersectCountSplit(v.Groups, query.Common, ref check);
                    IntersectCountSplit(v.Parodies, query.Common, ref check);
                    IntersectCountSplit(v.Characters, query.Common, ref check);
                }
                bool connect = false;
                if (check.Length == 0)
                {
                    check = new bool[1]; check[0] = true;
                }
                if (check[0] && v.Artists != null && query.Artists != null)
                {
                    check[0] = IsIntersect(v.Artists, query.Artists); connect = true;
                }
                else if (query.Artists != null)
                {
                    check[0] = false;
                }
                if (check[0] && v.Tags != null && query.TagInclude != null)
                {
                    check[0] = IsIntersect(v.Tags, query.TagInclude); connect = true;
                }
                else if (query.TagInclude != null)
                {
                    check[0] = false;
                }
                if (check[0] && v.Groups != null && query.Groups != null)
                {
                    check[0] = IsIntersect(v.Groups, query.Groups); connect = true;
                }
                else if (query.Groups != null)
                {
                    check[0] = false;
                }
                if (check[0] && v.Parodies != null && query.Series != null)
                {
                    check[0] = IsIntersect(v.Parodies, query.Series); connect = true;
                }
                else if (query.Series != null)
                {
                    check[0] = false;
                }
                if (check[0] && v.Characters != null && query.Characters != null)
                {
                    check[0] = IsIntersect(v.Characters, query.Characters); connect = true;
                }
                else if (query.Characters != null)
                {
                    check[0] = false;
                }
                if (check[0] && v.Type != null && query.Type != null)
                {
                    check[0] = query.Type.Any(x => x == v.Type); connect = true;
                }
                else if (query.Type != null)
                {
                    check[0] = false;
                }
                if (check.All((x => x)) && ((query.Common.Count == 0 && connect) || query.Common.Count > 0))
                {
                    result.Add(v);
                }
            }

            // required
            result.Sort((a, b) => b.ID - a.ID);
            return(result);
        }