本文整理汇总了C#中SearchResult类的典型用法代码示例。如果您正苦于以下问题:C# SearchResult类的具体用法?C# SearchResult怎么用?C# SearchResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchResult类属于命名空间,在下文中一共展示了SearchResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public List<SearchResult> Search(string searchQuery)
{
string url = "http://www.imdb.com/find?q={0}&s=all".Fmt(searchQuery);
string html = new WebClient().DownloadString(url);
CQ dom = html;
var searchResults = new List<SearchResult>();
foreach (var fragment in dom.Select("table.findList tr.findResult"))
{
var searchResult = new SearchResult();
searchResult.ImageUrl = fragment.Cq().Find(".primary_photo > a > img").Attr("src");
searchResult.Text = fragment.Cq().Find(".result_text").Html();
searchResult.Text = StringEx.RemoveHtmlTags(searchResult.Text);
string filmUrl = fragment.Cq().Find(".result_text > a").Attr("href");
filmUrl = filmUrl.Replace("/title/", "");
searchResult.FilmId = filmUrl.Substring(0, filmUrl.IndexOf("/"));
searchResults.Add(searchResult);
}
return searchResults;
}
示例2: NetSuiteSearch
public NetSuiteSearch(SearchResult results)
{
this.Id = results.searchId;
this.LastPage = results.pageIndex;
this.records = this.getSearchResults(results);
this.needsMore = results.pageIndex != results.totalPages;
}
示例3: Caching_search_with_apikey_does_not_pass_auth_info_to_lucene
public void Caching_search_with_apikey_does_not_pass_auth_info_to_lucene() {
var searchMock = CreateMocks().Item1;
var responseXml = new XDoc("response");
var luceneXml = new XDoc("lucene");
var searchQuery = new SearchQuery("raw", "processed", new LuceneClauseBuilder(), null);
var searchResult = new SearchResult();
searchMock.Setup(x => x.BuildQuery("foo", "", SearchQueryParserType.BestGuess, true)).Returns(searchQuery).AtMostOnce().Verifiable();
searchMock.Setup(x => x.GetCachedQuery(searchQuery)).Returns((SearchResult)null).AtMostOnce().Verifiable();
XUri luceneUriCalled = null;
MockPlug.Register(Utils.Settings.LuceneMockUri, (p, v, u, req, res) => {
luceneUriCalled = u;
res.Return(DreamMessage.Ok(luceneXml));
});
searchMock.Setup(x => x.CacheQuery(It.Is<XDoc>(v => v == luceneXml), It.IsAny<SearchQuery>(), It.IsAny<TrackingInfo>()))
.Returns(searchResult);
searchMock.Setup(x => x.FormatResultSet(
searchResult,
It.IsAny<SetDiscriminator>(),
false,
It.IsAny<TrackingInfo>(),
It.IsAny<Result<XDoc>>()
))
.Returns(new Result<XDoc>().WithReturn(responseXml));
var response = _search
.With("q", "foo")
.With("apikey", Utils.Settings.ApiKey)
.Get(new Result<DreamMessage>()).Wait();
Assert.IsTrue(response.IsSuccessful, response.ToErrorString());
Assert.IsNotNull(luceneUriCalled, "lucene was not called");
Assert.AreEqual(Utils.Settings.LuceneMockUri.At("compact"), luceneUriCalled.WithoutQuery(), "lucene was called at wrong uri");
Assert.IsNull(luceneUriCalled.GetParam("apiuri"), "lucene request contained an apiuri parameter");
Assert.IsNull(luceneUriCalled.GetParam("userid"), "lucene request contained a userid parameter");
Assert.AreEqual(searchQuery.LuceneQuery, luceneUriCalled.GetParam("q"), "lucene request had incorrect q parameter");
}
示例4: BasicSearch_NonDefault_Parameters
public void BasicSearch_NonDefault_Parameters()
{
//arrange
var mockLogic = new Mock<IProjectLogic>();
var obj = new SearchResult<ProjectObj>
{
HasMore = false,
HasPrevious = true,
Results = new List<ProjectObj>()
{
new ProjectObj()
{
Id = 2
}
}
};
mockLogic.Setup(l => l.Search("query", 5, 10)).Returns(obj);
var controller = new ProjectController(mockLogic.Object);
//act
var actual = controller.BasicSearch("query", 5, 10) as ViewResult;
//assert
Assert.IsNotNull(actual);
var model = actual.Model as BasicSearchModel;
Assert.IsNotNull(model);
Assert.AreEqual(5, model.CurrentPage);
Assert.AreEqual(false, model.HasMoreResults);
Assert.AreEqual(true, model.HasPriorResults);
Assert.AreEqual("Project", model.ModelName);
Assert.AreEqual(10, model.PageSize);
Assert.AreEqual("query", model.Query);
Assert.AreEqual(1, model.Results.Count);
Assert.AreEqual(2, model.Results[0].Id);
}
示例5: Search
public async Task<SearchResult> Search(string key)
{
key = key.Trim();
var res = new SearchResult
{
Items = new List<IMusic>(),
Keyword = key,
SearchType = EnumSearchType.url,
Page = 1,
};
var url = string.Format(search_url, Uri.EscapeDataString(key));
var response = await NetAccess.DownloadStringAsync(url);
var json = response.ToDynamicObject();
if (json.song.Count > 0)
foreach (var obj in json.song)
{
var s = new Song
{
Id = "b" + MusicHelper.Get(obj, "songid"),
ArtistName = MusicHelper.Get(obj, "artistname"),
AlbumName = "",
Name = MusicHelper.Get(obj, "songname"),
WriteId3 = false,
};
res.Items.Add(s);
s.UrlMp3 =await getDownloadUrl(s.Id.Substring(1));
}
return res;
}
示例6: SetAcl
private static void SetAcl(string path, SearchResult user, FileSystemRights right)
{
var userId = user.Properties["userPrincipalName"][0].ToString();
var fullUserName = user.Properties["name"][0].ToString();
var fullPath = path + fullUserName;
var dir = new DirectoryInfo(fullPath);
var ds = new DirectorySecurity();
ds.SetAccessRuleProtection(true, false);
var uacl = new FileSystemAccessRule(userId,
right,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow);
ds.AddAccessRule(uacl);
var domainAdmins = new SecurityIdentifier(WellKnownSidType.AccountDomainAdminsSid, AppSettings.GeneralSettings.DomainSid);
var pacl = new FileSystemAccessRule(domainAdmins,
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow);
ds.AddAccessRule(pacl);
var system = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
var sacl = new FileSystemAccessRule(system,
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow);
ds.AddAccessRule(sacl);
dir.SetAccessControl(ds);
}
示例7: GetUsersAsync
public Task<SearchResult<UserListItem>> GetUsersAsync(string pagingToken = null)
{
var path = GetObjectPath() + "/items";
return Client.CallServiceMethod<SearchResult<IDictionary<string, object>>>("GET", path, new
{
token = pagingToken
}).WrapTask<BuddyResult<SearchResult<IDictionary<string,object>>>,SearchResult<UserListItem>>(t2 => {
var r = t2.Result;
var sr = new SearchResult<UserListItem>();
if (r.IsSuccess) {
sr.NextToken = r.Value.NextToken;
sr.PreviousToken = r.Value.PreviousToken;
sr.CurrentToken = r.Value.CurrentToken;
sr.PageResults = r.Value.PageResults.Select(i => new UserListItem(i));
}
else {
sr.Error = r.Error;
}
return sr;
});
}
示例8: Execute
public string Execute(TransitionContext context)
{
string retEvent = Events.Error;
try {
if (context.Request.Items[this.AccountItemNameIn] == null ||
!(context.Request.Items[this.AccountItemNameIn] is SearchResult<Account>) ||
context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items.Length != 1) {
throw new MissingFieldException("Could not retrieve an account or the more than one account was returned.");
}
Account account = context.Request.GetItem<SearchResult<Account>>(this.AccountItemNameIn).Items[0];
/* Hmm whats better... one line or 3...
context.Request.Items[this.AccountsItemNameIn] = new SearchResult<Account>( new[] { Deserialize.Populate(context.Request, accounts.Items[0]) });
*/
Account toReturn = Deserialize.Populate(context.Request, account);
SearchResult<Account> result = new SearchResult<Account>(new Account[] {toReturn});
context.Request.Items[this.AccountItemNameOut] = result;
retEvent = Events.Ok;
} catch (Exception ex) {
this.logger.Error("Error occured in Execute.", ex);
}
return retEvent;
}
示例9: Execute
public string Execute(TransitionContext context)
{
string retEvent = "error";
try {
//for now this just returns all the states
List<State> states = new List<State>(DaoFactory.GetDao<IStateDao>().Get(new State{
IsTerritory = false
}));
SearchResult<State> results = new SearchResult<State>(states.ToArray());
switch (results.Items.Length) {
case 0:
retEvent = "zero";
break;
case 1:
retEvent = "one";
break;
default:
retEvent = "multiple";
break;
}
context.Request.Items[(this.RequestItemName ?? ADDRESS_STATES)] = results;
} catch (Exception ex) {
LogManager.GetLogger(typeof (GetStatesAction)).Error(
errorMessage => errorMessage("GetPropertyAction: Execute", ex));
}
return retEvent;
}
示例10: SearchKey
public SearchResult SearchKey(string key)
{
var search = new SearchResult() { Key = key };
if (!string.IsNullOrWhiteSpace(key))
{
SearchKeywordManager.Search(key); //用于统计搜索关键字的方法
IList<Duty_c> list = new List<Duty_c>();
list = BLL.Search.SearchGoods(key);
if (list.Count == 0)
{
search.Error = true;
}
else if (list.Count == 1)
{
search.Duty = list[0];
//goods_type = "<li class='one'>您输入的物品属于: " + duty.type.overname + "--->" + duty.type.midname + "--->" + duty.type.name + "</li><br/>";
//name = "<li class='one'>您输入的物品相关的品名是: " + duty.name + "</li><br/>";
//relatedwords = "<li class='one'>该品目相关的关键词: " + duty.relatedwords.ToString() + "</li><br/>";
//price = "<li class='one'>完税价格是: " + duty.price.ToString() + "元/" + duty.unit + "</li><br/>";
//rate = "<li class='one'>税率是: " + duty.rate.ToString() + "</li><br/>";
//lister = goods_type + name + relatedwords + price + rate;
}
else if (list.Count > 1)
{
search.SearchTakes = list.Select(r => r.name).ToList();
//lister = "你搜索结果大于一条,请在下列项中选择: </br>";
//for (int i = 0; i < list.Count; i++)
//{
// lister += "<a href=default.aspx?KeyWord=" + list[i].name + ">" + list[i].name + "</a> ";
//}
}
}
return search;
}
示例11: TestToString
public void TestToString()
{
SearchResult result1 = new SearchResult() { Index = 0, Exists = true };
Assert.AreEqual("Exists = True, Index = 0", result1.ToString(), "The wrong string representation was returned."); // implicit conversion
SearchResult result2 = new SearchResult() { Index = 1, Exists = false };
Assert.AreEqual("Exists = False, Index = 1", result2.ToString(), "The wrong string representation was returned."); // implicit conversion
}
示例12: TestIntegerConversion
public void TestIntegerConversion()
{
SearchResult result1 = new SearchResult() { Index = 0 };
Assert.AreEqual<int>(result1.Index, result1, "The result converted to the wrong index."); // implicit conversion
SearchResult result2 = new SearchResult() { Index = 2 };
Assert.AreEqual<int>(result2.Index, result2, "The result converted to the wrong index."); // implicit conversion
}
示例13: TestBooleanConversion
public void TestBooleanConversion()
{
SearchResult result1 = new SearchResult() { Exists = true };
Assert.IsTrue(result1, "The value should have existed."); // implicit conversion
SearchResult result2 = new SearchResult() { Exists = false };
Assert.IsFalse(result2, "The value should not have existed."); // implicit conversion
}
示例14: SearchResultMultiLine_ToString_EqualsExpected
public void SearchResultMultiLine_ToString_EqualsExpected()
{
var settings = new SearchSettings();
var pattern = new Regex("Search");
var searchFile = new SearchFile(CsSearchPath, "Searcher.cs", FileType.Text);
var lineNum = 10;
var matchStartIndex = 15;
var matchEndIndex = 23;
var line = "\tpublic class Searcher";
var linesBefore = new List<string> { "namespace CsSearch", "{" };
var linesAfter = new List<string> {"\t{", "\t\tprivate readonly FileTypes _fileTypes;"};
var searchResult = new SearchResult(pattern, searchFile, lineNum,
matchStartIndex, matchEndIndex,
line, linesBefore, linesAfter);
var expectedPath = CsSearchPath + "/Searcher.cs";
var expectedOutput = string.Format(new string('=', 80) + "\n" +
"{0}: {1}: [{2}:{3}]\n" +
new string('-', 80) + "\n" +
" 8 | namespace CsSearch\n" +
" 9 | {{\n" +
"> 10 | public class Searcher\n" +
" 11 | {{\n" +
" 12 | private readonly FileTypes _fileTypes;\n",
expectedPath, lineNum, matchStartIndex, matchEndIndex);
Assert.AreEqual(searchResult.ToString(settings), expectedOutput);
}
示例15: Execute
public string Execute(TransitionContext context)
{
string retEvent = Events.Error;
try {
if (context.Request.Items[this.RoleItemNameIn] == null ||
!(context.Request.Items[this.RoleItemNameIn] is SearchResult<Role>) ||
context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items.Length != 1) {
throw new MissingFieldException("Could not retrieve an role or the more than one role was returned.");
}
Role role = context.Request.GetItem<SearchResult<Role>>(this.RoleItemNameIn).Items[0];
Role toReturn = Deserialize.Populate(context.Request, role);
SearchResult<Role> result = new SearchResult<Role>(new Role[] {toReturn});
context.Request.Items[this.RoleItemNameOut] = result;
retEvent = Events.Ok;
} catch (Exception ex) {
this.logger.Error("Error occured in Execute.", ex);
}
return retEvent;
}