예제 #1
0
            private static string ParseXesamField(XPathNavigator nav)
            {
                string field = nav.GetAttribute("name", String.Empty);

                // FIXME: Using just the first field is NOT correct
                field = Ontologies.XesamToBeagleField(field)[0];

                if (field.Contains(":"))
                {
                    field = "property:" + field;
                }

                return(field);
            }
예제 #2
0
            public Hit(uint id, Beagle.Hit hit, string[] fields, Query query)
            {
                this.id  = id;
                bHit     = hit;
                hitValue = new object[fields.Length];
                int i = 0;

                uri = hit.Uri;

                foreach (string field in fields)
                {
                    // We add String.Empty to attributes because they may be null and we cannot
                    // return null objects over DBus
                    string[] bfields = Ontologies.XesamToBeagleField(field);

                    switch (bfields [0])
                    {
                    case "uri":
                        hitValue [i++] = hit.Uri.ToString();
                        break;

                    case "mimetype":
                        hitValue [i++] = hit.MimeType + String.Empty;
                        break;

                    case "date":
                        hitValue [i++] = hit.Timestamp.ToString("s");
                        break;

                    case "snippet":
                        SnippetRequest  sreq  = new SnippetRequest(query, hit);
                        SnippetResponse sresp = (SnippetResponse)sreq.Send();
                        hitValue [i++] = sresp.Snippet != null ? sresp.Snippet : String.Empty;
                        break;

                    default:
                        // FIXME: This *will* break since we don't know what the expected
                        // type here is, and we're always using strings

                        List <string> values = new List <string> ();

                        foreach (string bfield in bfields)
                        {
                            string[] prop = hit.GetProperties(bfield);

                            if (prop != null)
                            {
                                values.AddRange(prop);
                            }
                        }

                        if (values.Count == 0)
                        {
                            // No values found
                            hitValue [i++] = String.Empty;
                        }
                        else if (values.Count == 1)
                        {
                            // Only one value -- return as string
                            hitValue [i++] = values [0];
                        }
                        else
                        {
                            // Multiple values -- returns as string[]
                            hitValue [i++] = values.ToArray();
                        }

                        break;
                    }
                }
            }