/**
* AutoSearch.java
* Copyright 2015 by Burkhard Buelte
* First released 09.01.2015 at http://yacy.net
*
* This is a part of YaCy, a peer-to-peer based web search engine
*
* LICENSE
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see .
*/
package net.yacy.search;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import net.yacy.cora.document.feed.RSSFeed;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.document.id.MultiProtocolURL;
import static net.yacy.cora.federate.opensearch.SRURSSConnector.loadSRURSS;
import net.yacy.cora.federate.solr.connector.RemoteSolrConnector;
import net.yacy.cora.federate.solr.connector.SolrConnector;
import net.yacy.cora.federate.solr.instance.RemoteInstance;
import net.yacy.cora.federate.yacy.CacheStrategy;
import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.data.BookmarksDB.Bookmark;
import net.yacy.kelondro.workflow.AbstractBusyThread;
import net.yacy.peers.Seed;
import net.yacy.search.schema.CollectionSchema;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.CommonParams;
/**
* AutoSearch retrieves queries from Bookmarks or a property file (if existing)
* and loops to a list of connected peers and asks each for results which are
* added to the local index.
*/
public class AutoSearch extends AbstractBusyThread {
private Set querystack; // serach query
public String currentQuery = null; // current query
private Set currentTargets = null; // peer hashes
final Switchboard sb;
public int gotresults;
private long lastInitTime; // to recognize new data (Bookmarks) to import
public AutoSearch(Switchboard xsb) {
super(3000, 1000); // set lower limits of cycle delay
this.setIdleSleep(60000); // set actual cycle delays
this.setBusySleep(10000);
this.sb = xsb;
gotresults = 0;
querystack = new HashSet();
this.lastInitTime = System.currentTimeMillis() - 600000; // init to now - 10 min
if (!checkBookmarkDB()) {
try {
// check for old queries in temp property file
File pfile = new File(xsb.dataPath, "DATA/SETTINGS/autosearch.conf");
if (pfile.exists()) {
ConcurrentLog.info(AutoSearch.class.getName(), "read queries from file " + pfile.getAbsolutePath());
Properties prop = new Properties();
FileInputStream fileIn = new FileInputStream(pfile);
prop.load(fileIn);
if (prop.size() > 0) {
Set