本文整理汇总了Java中io.searchbox.core.SearchResult.getSourceAsObjectList方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getSourceAsObjectList方法的具体用法?Java SearchResult.getSourceAsObjectList怎么用?Java SearchResult.getSourceAsObjectList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.searchbox.core.SearchResult
的用法示例。
在下文中一共展示了SearchResult.getSourceAsObjectList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<HabitEvent> doInBackground(String... eids) {
verifySettings();
ArrayList<HabitEvent> habitEvents = new ArrayList<HabitEvent>();
String query = "{\"query\": {\"match\" : { \"eid\" : \"" + eids[0] + "\" }}}";
Search search = new Search.Builder(query).addIndex(db).addType(habitEventType).build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<HabitEvent> foundHabitEvent = result.getSourceAsObjectList(HabitEvent.class);
habitEvents.addAll(foundHabitEvent);
} else {
Log.i("Error2", "Something went wrong when we tried to communicate with the elasticsearch server");
}
}
catch (Exception e) {
Log.i("Error1", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return habitEvents;
}
示例2: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Profile> doInBackground(String... search_parameters){
verifySettings();
ArrayList<Profile> profiles = new ArrayList<Profile>();
String query = "{\n"
+ " \"query\" : {\n"
+ " \"term\" : { \"username\" : \""+search_parameters[0]+"\"}\n"
+ " }\n"
+ "}";
Search search = new Search.Builder(query).addIndex(appESIndex).addType("profile").build();
try{
SearchResult result = client.execute(search);
if (result.isSucceeded()){
List<Profile> foundProfiles = result.getSourceAsObjectList(Profile.class);
profiles.addAll(foundProfiles);
}else{
Log.i("Error","ElasticSearch search query failed");
}
}catch (Exception e){
Log.i("Error","ElasticSearch filed to find profiles");
}
return profiles;
}
示例3: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Book> doInBackground(String... userNames) {
verifyClient();
String search_string = "{\"query\":{" +
" \"match\":{" +
" \"owner.userName\":\"" + userNames[0] + "\"" +
" }" +
"}}";
Search search = new Search.Builder(search_string).addIndex(teamdir).addType(booktype).build();
try {
SearchResult execute = client.execute(search);
if (execute.isSucceeded()) {
List<Book> bookList = execute.getSourceAsObjectList(Book.class);
myBookList.addAll(bookList);
ac.setMyBookArray(myBookList);
} else {
return null;
}
} catch (IOException e) {
return null;
}
return null;
}
示例4: getGamesByField
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
* Get a list of things that match a set of keywords from the database.
* @param field object field to match over
* @param keywords list of keywords to match.
* @return A list of things that have matching words in their description.
*/
public List<Thing> getGamesByField(String field, String keywords) {
ArrayList<Thing> games = new ArrayList<Thing>();
String search_string = String.format("{\"query\":{\"match\":{\"%s\":{\"query\":\"%s\",\"fuzziness\":\"AUTO\"}}}}", field, keywords);
io.searchbox.core.Search search = new io.searchbox.core.Search.Builder(search_string)
.addIndex(ELASTIC_INDEX).addType(ELASTIC_GAME_TYPE).build();
try {
SearchResult execute = jestClient.execute(search);
if (execute.isSucceeded())
{
List<Thing> foundGames = execute.getSourceAsObjectList(Thing.class);
games.addAll(foundGames);
} else {
Log.i("TODO", "Search was unsuccessful");
}
} catch (IOException e) {
e.printStackTrace();
}
return games;
}
示例5: getOffers
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
* Sub-task: grab the offers for a request and then populate a request with them.
* @see #populate(Request, List)
*/
private static void getOffers(RequestList foundRequests) {
for( Request request : foundRequests ) {
// TODO filter requests that will not have offering drivers?
String query =
"{ \"from\":0, \"size\":1000,\n" +
" \"query\": { \"match\": { \"requestID\" : \"" + request.getId() + "\" } }\n" +
"}";
Search search = new Search.Builder(query)
.addIndex("cmput301f16t01")
.addType("offer")
.build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Offer> offers = result.getSourceAsObjectList(Offer.class);
populate( request, offers );
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例6: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Review> doInBackground(Void... params) {
verifySettings();
String query = "{\n" +
" \"query\": {\n" +
" \"match\" : {\n" +
" \"userID\" : \"" + userID + "\"\n" +
" }\n" +
" }\n" +
"}";
Search search = new Search.Builder(query)
.addIndex(INDEX)
.addType("review")
.build();
List<Review> reviews = new ArrayList<Review>();
try {
SearchResult result = client.execute(search);
reviews = result.getSourceAsObjectList(Review.class);
}
catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return (ArrayList<Review>) reviews;
}
示例7: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<User> doInBackground(String... search_parameters) {
verifySettings();
ArrayList<User> users = new ArrayList<User>();
String query = "{\"query\" : {\"term\" : { \"name\" : \"" + search_parameters[0] + "\" }}}";
// Build the query
Search search = new Search.Builder(query)
.addIndex("cmput301w17t8")
.addType("user")
.build();
try {
// gets result
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<User> foundUsers = result.getSourceAsObjectList(User.class);
users.addAll(foundUsers);
} else {
Log.i("Error", "The search query failed to find any user that matched.");
}
} catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return users;
}
示例8: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Mood> doInBackground(String... search_parameters) {
verifySettings();
String query;
ArrayList<Mood> moods = new ArrayList<Mood>();
// if (search_parameters.length == 2) {
// query = "{\"query\": {\"bool\": {\"must\": [{\"term\": {\"owner\": \""+ search_parameters[0] +"\"}}, {\"term\": {\"id\": \""+ search_parameters[1] +"\"}}]}}}";
// } else {
// query = "{\"query\" : {\"term\" : { \"owner\" : \"" + search_parameters[0] + "\" }}}";
// }
query = "{\"query\" : {\"term\" : { \"owner\" : \"" + search_parameters[0] + "\" }}}";
// Build the query
Search search = new Search.Builder(query)
.addIndex("cmput301w17t8")
.addType("mood")
.build();
try {
// gets result
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Mood> foundMoods = result.getSourceAsObjectList(Mood.class);
moods.addAll(foundMoods);
} else {
Log.i("Error", "The search query failed to find any mood that matched.");
}
} catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return moods;
}
示例9: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Account> doInBackground(String... search_parameters) {
verifySettings();
ArrayList<Account> users = new ArrayList<Account>();
// TODO Build the query
String query = "{\n" +
" \"query\" : {\n" +
" \"term\": { \"_id\": \"" + search_parameters[0] + "\"}\n" +
" }\n" +
"}";
Search search = new Search.Builder(query)
.addIndex(INDEX)
.addType(USER_TYPE)
.build();
try {
// TODO get the results of the query
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Account> foundUsers = result.getSourceAsObjectList(Account.class);
users.addAll(foundUsers);
} else {
Log.i("Error", "The search query failed to find any users that matched");
}
} catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return users;
}
示例10: testReturnItems
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
public ArrayList<WarItem> testReturnItems(){
verifyClient();
ArrayList<WarItem> items = new ArrayList<WarItem>();
String search_string="";
search_string = "{\"from\" : 0, \"size\" : 100}";
Search search = new Search.Builder(search_string)
.addIndex("Agile_Android_Abstracts")
.addType("items")
.build();
try {
SearchResult execute = client.execute(search);
if(execute.isSucceeded()) {
// Return our list of tweets
List<WarItem> returned_tweets = execute.getSourceAsObjectList(WarItem.class);
items.addAll(returned_tweets);
} else {
// TODO: Add an error message, because that other thing was puzzling.
// TODO: Right here it will trigger if the search fails
Log.i("TODO", "We actually failed here, searching for items");
}
} catch (IOException e) {
e.printStackTrace();
}
return items;
}
示例11: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<User> doInBackground(String... search_strings) {
verifyClient();
ArrayList<User> users = new ArrayList<User>();
String search_string;
search_string = "{\"from\" : 0, \"size\" : 100}";
Search search = new Search.Builder(search_string)
.addIndex("Agile_Android_Abstracts")
.addType("users")
.build();
try {
SearchResult execute = client.execute(search);
if(execute.isSucceeded()) {
// Return our list of tweets
List<User> returned_tweets = execute.getSourceAsObjectList(User.class);
users.addAll(returned_tweets);
} else {
// TODO: Add an error message, because that other thing was puzzling.
// TODO: Right here it will trigger if the search fails
Log.i("TODO", "We actually failed here, searching for users");
}
} catch (IOException e) {
e.printStackTrace();
}
return users;
}
示例12: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Notification> doInBackground(String... search_parameters) {
verifySettings();
String search_string = "{\"from\" : 0, \"size\" : 500, \"query\": {\"match\": {\"username\": \"" + search_parameters[0] + "\"}}}";
Search search = new Search.Builder(search_string)
.addIndex("cmput301f16t01")
.addType("notification")
.build();
ArrayList<Notification> foundNotifications = new ArrayList<>();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Notification> notificationList = result.getSourceAsObjectList(Notification.class);
foundNotifications.addAll( notificationList );
} else {
return foundNotifications;
}
} catch (IOException e) {
e.printStackTrace();
Log.i("Error", "Something went wrong when we tried to talk to elastic search");
}
// If we have a listener, it wants to know if there are unread notifications
// We will tell the listener in onPostExecute (in case it needs to update a view on UI thread).
Collections.sort( foundNotifications );
if (listener != null) {
for (Notification notification : foundNotifications) {
if (!notification.isRead()) {
unreadExists = true;
break;
}
}
}
return foundNotifications;
}
示例13: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Account> doInBackground(String... search_parameters) {
verifySettings();
ArrayList<Account> myAccount = new ArrayList<Account>();
String search_string = "{\"query\" : {\"term\" : {\"username\":\"" + search_parameters[0] + "\" }}}";
// assume that search_parameters[0] is the only search term we are interested in using
Search search = new Search.Builder(search_string)
.addIndex("f16t14")
.addType("Account")
.build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Account> foundAccount = result.getSourceAsObjectList(Account.class);
myAccount.addAll(foundAccount);
}
else {
Log.i("Error", "The search query failed to find any account that matched.");
}
}
catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return myAccount;
}
示例14: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<Request> doInBackground(Account... search_parameters) {
verifySettings();
ArrayList<Request> myRequests = new ArrayList<Request>();
String search_string = "{\"from\" : 0, \"size\" : 1000, \"query\" : {\"term\" : {\"keyword\":\"" + search_parameters[0] + "\" }}}";
// assume that search_parameters[0] is the only search term we are interested in using
Search search = new Search.Builder(search_string)
.addIndex("f16t14")
.addType("Request")
.build();
try {
SearchResult result = client.execute(search);
if (result.isSucceeded()) {
List<Request> foundRequests = result.getSourceAsObjectList(Request.class);
myRequests.addAll(foundRequests);
}
else {
Log.i("Error", "The search query failed to find any request that matched.");
}
}
catch (Exception e) {
Log.i("Error", "Something went wrong when we tried to communicate with the elasticsearch server!");
}
return myRequests;
}
示例15: doInBackground
import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
protected ArrayList<User> doInBackground(String... search_strings) {
verifyClient();
// Start our initial array list (empty)
ArrayList<User> users = new ArrayList<User>();
if(isOnline()==false){
return users;
}
// NOTE: I'm a making a huge assumption here, that only the first search term
// will be used.
String search_string;
if(search_strings[0] != "") {
//search_string = "{\"from\" : 0, \"size\" : 10000,\"query\":{\"match\":{\"message\":\"" + search_strings[0] + "\"}}}";
search_string = "{\"query\":{\"match\":{\"username\":\"" + search_strings[0] + "\"}}}";
} else {
search_string = "{\"from\" : 0, \"size\" : 100}";
}
Search search = new Search.Builder(search_string)
.addIndex("warondemand")
.addType("users")
.build();
try {
SearchResult execute = client.execute(search);
if(execute.isSucceeded()) {
// Return our list of tweets
List<User> returned_tweets = execute.getSourceAsObjectList(User.class);
users.addAll(returned_tweets);
} else {
// TODO: Add an error message, because that other thing was puzzling.
// TODO: Right here it will trigger if the search fails
Log.i("TODO", "We actually failed here, searching for users");
}
} catch (IOException e) {
e.printStackTrace();
}
return users;
}