[英]Retrieve more than 1000 results Google App Engine Search API
I need to be able to retrieve all records available in the index. 我需要能够检索索引中所有可用的记录。 Seems like 1000 is the limit.
似乎限制为1000。 Is there something else I can do?
还有什么我可以做的吗?
I was also facing some similar issue in one of my projects so researched over internet and got one idea that instead of using the Search API, I created a workaround scenario. 在我的一个项目中,我也遇到了类似的问题,因此在Internet上进行了研究,发现一个想法,而不是使用Search API,而是创建了一种变通方案。 What I did is I have only one attribute in my table which needs to have a pattern based search.
我所做的是我的表中只有一个属性,该属性需要基于模式的搜索。 I am sharing my code as well here.
我也在这里分享我的代码。
Objectify Entity Class 对象实体类
@Entity
public class NewsFeed {
@Id
@Index
private Long feedID;
private String title;
private Set<String> titleKeywords;
// getters and setter
}
Logic for storing the keyword in the same table. 将关键字存储在同一表中的逻辑。 I have split all the title words for my entity into keywords, and stored them in a Set Object.
我已将实体的所有标题词拆分为关键字,并将它们存储在Set Object中。
NewsFeed newsFeed = new NewsFeed();
newsFeed.setTitle(title);
newsFeed.setTitleKeywords(getKeywordsSet(newsTitle));
// save entity here
Method for extracting keywords from title(field to be searched) 从标题中提取关键词的方法(待搜索字段)
public Set<String> getKeywordsSet(String title) {
Set<String> keywords = new HashSet<String>();
String titleNews = title.toLowerCase();
String[] array = titleNews.split(" ");
for (int i = 0; i < array.length; i++) {
// replacing all special characters here
String word = array[i].replaceAll("\\W", "");
keywords.add(word);
}
return keywords;
}
Listing all the feeds from our DB, and finally matching the parameter to be searched, by the logic below. 列出来自数据库的所有提要,并最终通过以下逻辑匹配要搜索的参数。
public List<NewsFeed> getFilterJsonArray(String param){
// Listing all the objects of entity
List<NewsFeed> list = newsFeedDao.listOrderedFeeds();
List<NewsFeed> matchedObject = new ArrayList<NewsFeed>();
for (NewsFeed newsFeed : list) {
/**
* main logic for pattern matched keywords
**/
if (isAnElementInSet(newsFeed.getTitleKeywords(), param.toLowerCase())) {
matchedObject.add(newsFeed);
}
}
return matchedObject;
}
public boolean isAnElementInSet(Set<String> keywords, String param) {
String []params = param.split(" ");
if (keywords.size() > 0) {
for(String splittedParam : params){
if (keywords.contains(splittedParam)) {
return true;
} else{
for (String keyword : keywords) {
if(keyword.contains(splittedParam)){
return true;
}
}
return false;
}
}
return true;
}else{
return false;
}
}
I know this cannot be the best solution for searching things but this solution worked very fine for me. 我知道这可能不是搜索事物的最佳解决方案,但是此解决方案对我来说效果很好。 I just shared it here so as to get improvements in this logic as well.
我只是在这里分享了它,以便也可以改进此逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.