Package com.aelitis.azureus.core.metasearch

Examples of com.aelitis.azureus.core.metasearch.Engine


   
    Long   engine_id   = (Long)map.get( "engine_id" );
    String  search_term  = (String)map.get( "search_term" );
    Map    filters    = (Map)map.get( "filters" );

    Engine engine = manager.getEngine( subs, map, false );
   
    if ( engine == null ){
     
      throw( new SubscriptionException( "Download failed, search engine " + engine_id + " not found" ));
    }
   
    List  sps = new ArrayList();
   
    if ( search_term != null ){
     
      sps.add( new SearchParameter( "s", search_term ));
   
      log( "    Using search term '" + search_term + "' for engine " + engine.getString());
    }
   
    /*
    if ( mature != null ){
     
      sps.add( new SearchParameter( "m", mature.toString()));
    }
    */
   
    SearchParameter[] parameters = (SearchParameter[])sps.toArray(new SearchParameter[ sps.size()] );

   
    SubscriptionHistoryImpl history = (SubscriptionHistoryImpl)subs.getHistory();
   
    try
      Map  context = new HashMap();
     
      context.put( Engine.SC_SOURCE,   "subscription" );
     
      Result[] results = engine.search( parameters, context, -1, -1, null, null );
   
      log( "    Got " + results.length + " results" );
     
      SubscriptionResultFilter result_filter = new SubscriptionResultFilter(filters );

View Full Code Here


              int  comp_type = comp.getType();
             
              if ( comp_type == VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE ){
               
                try{
                  Engine e =
                    getSingleton().importEngine(
                      comp.getContent(),
                      (expected_types & VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) == 0 );
                 
                  comp.setProcessed();
View Full Code Here

     
      List<Engine>  selected_engines = new ArrayList<Engine>();
     
      for ( long id: provider_ids ){
       
        Engine engine = meta_search.getEngine( id );
       
        if ( engine == null ){
         
          throw( new SearchException( "Unknown engine id - " + id ));
         
View Full Code Here

                      VuzeFileComponent comp = comps[j];
                     
                      if ( comp.getType() == VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE ){
                       
                        try{
                          Engine e =
                            getSingleton().importEngine( comp.getContent(), false );
                         
                          log( "    updated " + e.getName());
                         
                          e.setSelectionState( Engine.SEL_STATE_MANUAL_SELECTED );
                         
                        }catch( Throwable e ){
                         
                          Debug.printStackTrace(e);
                        }
                      }
                    }
                  }
                }finally{
                 
                  try{
                    is.close();
                   
                  }catch( Throwable e ){
                  }
                }
              }
            }finally{
             
              COConfigurationManager.setParameter( "metasearch.custom.name", cust.getName());
              COConfigurationManager.setParameter( "metasearch.custom.version", cust.getVersion());
            }
          }
        }
      }
     
      log( "Refreshing engines" );
         
        // featured templates are always shown - can't be deselected
        // popular ones are selected if in 'auto' mode
        // manually selected ones are, well, manually selected
     
      Map<Long,PlatformMetaSearchMessenger.templateInfo>    vuze_selected_ids     = new HashMap<Long, PlatformMetaSearchMessenger.templateInfo>();
      Map<Long,PlatformMetaSearchMessenger.templateInfo>    vuze_preload_ids     = new HashMap<Long,PlatformMetaSearchMessenger.templateInfo>();
     
      Set<Long>    featured_ids       = new HashSet<Long>();
      Set<Long>    popular_ids       = new HashSet<Long>();
      Set<Long>    manual_vuze_ids     = new HashSet<Long>();
     
      boolean    auto_mode = isAutoMode();
         
      Engine[]  engines = meta_search.getEngines( false, false );
 
      String  fud = meta_search.getFUD();
     
      try{
        PlatformMetaSearchMessenger.templateInfo[] featured = PlatformMetaSearchMessenger.listFeaturedTemplates( extension_key, fud );
       
        String featured_str = "";
       
        for (int i=0;i<featured.length;i++){
         
          PlatformMetaSearchMessenger.templateInfo template = featured[i];
         
          if ( !template.isVisible()){
           
            continue;
          }
         
          Long key = new Long( template.getId());
         
          vuze_selected_ids.put( key,  template );
         
          featured_ids.add( key );
         
          featured_str += (featured_str.length()==0?"":",") + key;
        }
         
        log( "Featured templates: " + featured_str );
       
        if ( auto_mode || first_run ){
         
          PlatformMetaSearchMessenger.templateInfo[] popular = PlatformMetaSearchMessenger.listTopPopularTemplates( extension_key, fud );
         
          String popular_str = "";
          String preload_str = "";
         
          for (int i=0;i<popular.length;i++){
           
            PlatformMetaSearchMessenger.templateInfo template = popular[i];
           
            if ( !template.isVisible()){
             
              continue;
            }
           
            Long  key = new Long( template.getId());
           
            if ( auto_mode ){
             
              if ( !vuze_selected_ids.containsKey( key )){
               
                vuze_selected_ids.put( key,  template );
               
                popular_ids.add( key );
               
                popular_str += (popular_str.length()==0?"":",") + key;
              }
            }else{
             
              if ( !vuze_preload_ids.containsKey( key )){
               
                vuze_preload_ids.put( key, template );
                               
                preload_str += (preload_str.length()==0?"":",") + key;
              }
            }
          }
         
          log( "Popular templates: " + popular_str );
         
          if ( preload_str.length() > 0 ){
           
            log( "Pre-load templates: " + popular_str );
          }
        }
           
          // pick up explicitly selected vuze ones
       
        String manual_str = "";
       
        for (int i=0;i<engines.length;i++){
         
          Engine  engine = engines[i];
         
          Long key = new Long( engine.getId());
         
          if (   engine.getSource() == Engine.ENGINE_SOURCE_VUZE &&
              engine.getSelectionState() == Engine.SEL_STATE_MANUAL_SELECTED &&
              !vuze_selected_ids.containsKey( key )){
           
            manual_vuze_ids.add( key );
          }
        }
       
        if ( manual_vuze_ids.size() > 0 ){
         
          long[]  manual_ids = new long[manual_vuze_ids.size()];
         
          Iterator<Long> it = manual_vuze_ids.iterator();
         
          int  pos = 0;
         
          while( it.hasNext()){
           
            manual_ids[pos++] = it.next().longValue();
          }
         
          PlatformMetaSearchMessenger.templateInfo[] manual = PlatformMetaSearchMessenger.getTemplateDetails( extension_key, manual_ids );
                   
          for (int i=0;i<manual.length;i++){
           
            PlatformMetaSearchMessenger.templateInfo template = manual[i];
           
            if ( !template.isVisible()){
             
              continue;
            }
           
            Long  key = new Long( template.getId());
                         
            vuze_selected_ids.put( key, template );
                           
            manual_str += (manual_str.length()==0?"":",") + key;
          }
        }
       
        log( "Manual templates: " + manual_str );
       
        Map<Long,Engine> existing_engine_map = new HashMap<Long,Engine>();
       
        String existing_str = "";
       
        for (int i=0;i<engines.length;i++){
         
          Engine  engine = engines[i];
         
          Long key = new Long( engine.getId());
 
          existing_engine_map.put( key, engine );
         
          existing_str += (existing_str.length()==0?"":",") + key +
                    "[source=" + Engine.ENGINE_SOURCE_STRS[engine.getSource()] +
                    ",type=" + engine.getType() +
                    ",selected=" + Engine.SEL_STATE_STRINGS[engine.getSelectionState()] + "]";
        }
       
        log( "Existing templates: " + existing_str );
       
          // we've compiled a list of the engines we should have and their latest dates
       
          // update any that are out of date
       
        Iterator<Map.Entry<Long,PlatformMetaSearchMessenger.templateInfo>> it = vuze_selected_ids.entrySet().iterator();
       
        while( it.hasNext()){
         
          Map.Entry<Long,PlatformMetaSearchMessenger.templateInfo> entry = it.next();
         
          vuze_preload_ids.remove( entry.getKey());
         
          long  id       = entry.getKey().longValue();
         
          PlatformMetaSearchMessenger.templateInfo template = entry.getValue();
         
          long  modified   = template.getModifiedDate();
                 
          Engine this_engine = (Engine)existing_engine_map.get( new Long(id));
         
          boolean  update = this_engine == null || this_engine.getLastUpdated() < modified;
 
          if ( update ){
           
            PlatformMetaSearchMessenger.templateDetails details = PlatformMetaSearchMessenger.getTemplate( extension_key, id );
 
            log( "Downloading definition of template " + id );
            log( details.getValue());
           
            if ( details.isVisible()){
             
              try{
                this_engine =
                  meta_search.importFromJSONString(
                    details.getType()==PlatformMetaSearchMessenger.templateDetails.ENGINE_TYPE_JSON?Engine.ENGINE_TYPE_JSON:Engine.ENGINE_TYPE_REGEX,
                    details.getId(),
                    details.getModifiedDate(),
                    details.getRankBias(),
                    details.getName(),
                    details.getValue());
               
                this_engine.setSource( Engine.ENGINE_SOURCE_VUZE );
                               
                meta_search.addEngine( this_engine );
               
              }catch( Throwable e ){
               
                log( "Failed to import engine '" + details.getValue() + "'", e );
              }
            } 
          }else if ( this_engine.getRankBias() != template.getRankBias()){
           
            this_engine.setRankBias( template.getRankBias());
           
            log( "Updating rank bias for " + this_engine.getString() + " to " + template.getRankBias());

          }else{
           
            log( "Not updating " + this_engine.getString() + " as unchanged" );
          }
         
          if ( this_engine != null ){
             
            int sel_state = this_engine.getSelectionState();
           
            if ( sel_state == Engine.SEL_STATE_DESELECTED ){
           
              log( "Auto-selecting " + this_engine.getString());
             
              this_engine.setSelectionState( Engine.SEL_STATE_AUTO_SELECTED );
             
            }else if ( auto_mode && sel_state == Engine.SEL_STATE_MANUAL_SELECTED ){
             
              log( "Switching Manual to Auto select for " + this_engine.getString());
             
              this_engine.setSelectionState( Engine.SEL_STATE_AUTO_SELECTED );
            }
          }
        }
       
          // do any pre-loads
       
        it = vuze_preload_ids.entrySet().iterator();
       
        while( it.hasNext()){
         
          Map.Entry<Long,PlatformMetaSearchMessenger.templateInfo> entry = it.next();
         
          long  id       = ((Long)entry.getKey()).longValue();
                 
          Engine this_engine = (Engine)existing_engine_map.get( new Long(id));
           
          if ( this_engine == null ){
           
            PlatformMetaSearchMessenger.templateDetails details = PlatformMetaSearchMessenger.getTemplate( extension_key, id );
 
            log( "Downloading pre-load definition of template " + id );
            log( details.getValue());
           
            if ( details.isVisible()){
             
              try{
                this_engine =
                  meta_search.importFromJSONString(
                    details.getType()==PlatformMetaSearchMessenger.templateDetails.ENGINE_TYPE_JSON?Engine.ENGINE_TYPE_JSON:Engine.ENGINE_TYPE_REGEX,
                    details.getId(),
                    details.getModifiedDate(),
                    details.getRankBias(),
                    details.getName(),
                    details.getValue());
               
                this_engine.setSource( Engine.ENGINE_SOURCE_VUZE );
               
                this_engine.setSelectionState( Engine.SEL_STATE_DESELECTED );
                               
                meta_search.addEngine( this_engine );
               
              }catch( Throwable e ){
               
                log( "Failed to import engine '" + details.getValue() + "'", e );
              }
            }     
          }
        }
       
          // deselect any not in use
       
        for (int i=0;i<engines.length;i++){
         
          Engine  engine = engines[i];
         
          if (   engine.getSource() == Engine.ENGINE_SOURCE_VUZE &&
              engine.getSelectionState() == Engine.SEL_STATE_AUTO_SELECTED &&
              !vuze_selected_ids.containsKey( new Long( engine.getId()))){
           
            log( "Deselecting " + engine.getString() + " as no longer visible on Vuze");
           
            engine.setSelectionState( Engine.SEL_STATE_DESELECTED );
          }
        }
       
          // finally pick up any unreported selection changes and re-affirm positive selections
       
        for (int i=0;i<engines.length;i++){
         
          Engine  engine = engines[i];
         
          if (   engine.getSource() == Engine.ENGINE_SOURCE_VUZE &&
              engine.getSelectionState() == Engine.SEL_STATE_MANUAL_SELECTED ){
           
            engine.recordSelectionState();
           
          }else{
           
            engine.checkSelectionStateRecorded();
          }
        }
       
        refresh_completed = true;
       
View Full Code Here

     
      for (int i=0;i<ids.length;i++){
       
        long   id = ids[i];
       
        Engine existing = (Engine)engine_map.get(new Long(id));
       
        if ( existing != null ){
         
          existing.setSelectionState( Engine.SEL_STATE_MANUAL_SELECTED );
         
          selected_engine_set.add( existing );
        }
      }
   
        // now refresh - this will pick up latest state of things
     
      syncRefresh();
     
      engines = meta_search.getEngines( false, false );

        // next add in any missing engines
     
      for (int i=0;i<ids.length;i++){
       
        long   id = ids[i];
       
        Engine existing = (Engine)engine_map.get(new Long(id));
       
        if ( existing == null ){
                           
          PlatformMetaSearchMessenger.templateDetails details = PlatformMetaSearchMessenger.getTemplate( extension_key, id );
 
          log( "Downloading definition of template " + id );
          log( details.getValue());
         
          Engine new_engine =
            meta_search.importFromJSONString(
              details.getType()==PlatformMetaSearchMessenger.templateDetails.ENGINE_TYPE_JSON?Engine.ENGINE_TYPE_JSON:Engine.ENGINE_TYPE_REGEX,
              details.getId(),
              details.getModifiedDate(),
              details.getRankBias(),
              details.getName(),
              details.getValue());
             
          new_engine.setSelectionState( Engine.SEL_STATE_MANUAL_SELECTED );
                   
          new_engine.setSource( Engine.ENGINE_SOURCE_VUZE );
           
          meta_search.addEngine( new_engine );
         
          selected_engine_set.add( new_engine );
        }
      }
     
        // deselect any existing manually selected ones that are no longer selected
     
      for( int i=0;i<engines.length;i++){

        Engine e = engines[i];
       
        if ( e.getSelectionState() == Engine.SEL_STATE_MANUAL_SELECTED ){
         
          if ( !selected_engine_set.contains( e )){
       
            e.setSelectionState( Engine.SEL_STATE_DESELECTED  );
          }
        }
      }
    }catch( Throwable e ){
     
      e.printStackTrace();
     
      if ( e instanceof MetaSearchException ){
       
        throw((MetaSearchException)e);
      }
View Full Code Here

     
      id = getLocalTemplateID();
    }
   
    try{
      Engine engine =
        meta_search.importFromJSONString(
          type, id, SystemTime.getCurrentTime(), 1, name, json_value );
     
      engine.setSource( Engine.ENGINE_SOURCE_LOCAL );
     
      engine.setSelectionState( Engine.SEL_STATE_MANUAL_SELECTED );
     
      meta_search.addEngine( engine );
     
      return( engine );
     
View Full Code Here

        try{
          EngineImpl engine = (EngineImpl)meta_search.importFromBEncodedMap( comp.getContent());
         
          long  id = engine.getId();
         
          Engine existing = meta_search.getEngine( id );
         
          if ( existing != null ){
           
            if ( !existing.sameLogicAs( engine )){
             
              return( true );
            }
          }else{
            try{           
View Full Code Here

    try{
      EngineImpl engine = (EngineImpl)meta_search.importFromBEncodedMap(map);
     
      long  id = engine.getId();
     
      Engine existing = meta_search.getEngine( id );
     
      if ( existing != null ){
       
        if ( existing.sameLogicAs( engine )){
         
          if ( warn_user ){
           
            UIManager ui_manager = StaticUtilities.getUIManager( 120*1000 );
           
View Full Code Here

        Map map = JSONUtils.decodeJSON( getJSON());
       
        String  search_term  = (String)map.get( "search_term" );
        Map    filters    = (Map)map.get( "filters" );
 
        Engine engine = manager.getEngine( this, map, true );

        String  engine_name = engine.getNameEx();
       
        if ( name.startsWith( engine_name )){
         
          name_ex = name;
         
        }else if ( engine_name.startsWith( name )){
         
          name_ex = engine_name;
         
        }else{
         
          name_ex = name + ": " + engine.getNameEx();
        }
       
        if ( search_term != null && search_term.length() > 0 ){
         
          name_ex += ", query=" + search_term;
View Full Code Here

    String  json_out  = json_in;
   
    if ( engine_id >= Integer.MAX_VALUE || engine_id < 0 ){
     
      Engine engine = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngine( engine_id );

      if ( engine == null ){
       
        log( "Private search template with id '" + engine_id + "' not found!!!!" );
       
      }else{
       
        try{               
          embedEngines( map, engine );
         
          json_out = JSONUtils.encodeToJSON( map );
         

          log( "Embedded private search template '" + engine.getName() + "'" );
         
        }catch( Throwable e ){
         
          log( "Failed to embed private search template", e );
        }
View Full Code Here

TOP

Related Classes of com.aelitis.azureus.core.metasearch.Engine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.