Package org.thrudb.thrudex

Examples of org.thrudb.thrudex.ThrudexExceptionImpl


        deletedDocuments.add(term);
         
      hasWrite.set(true);
     
    }catch(IOException e){
      throw new ThrudexExceptionImpl(e.toString());
    }
  }
View Full Code Here


      if(diskFilter.hideTerm(term))
        deletedDocuments.add(term);
     
     
    }catch(IOException e){
      throw new ThrudexExceptionImpl(e.toString());
    }
  }
View Full Code Here

    }
  }

  public SearchResponse search(SearchQuery query) throws ThrudexException {
    if(!query.isSetQuery() || query.query.trim().equals(""))
      throw new ThrudexExceptionImpl("Empty Query");
   
    //Parse Query
    Query parsedQuery;
    SearchResponse response = new SearchResponse();
   
    //Construct the multiSearcher
    ParallelMultiSearcher multiSearcher = null;
    RealTimeDiskFilter    myFilter      = null;
    try{

      //This section needs to be thread safe
      synchronized(this){
           
        //Commit any prev writes
        if(hasWrite.getAndSet(false)){
          ramWriter.commit();
         
          //Reopen index reader
          IndexReader newReader = ramReader.reopen();
          if(ramReader != newReader){ 
            //ramReader.close();
            ramSearcher.close();
            ramReader   = newReader;     
            ramSearcher = new IndexSearcher(ramReader);
          }       
        }
       
       
        List<Searchable> searchersList = new ArrayList<Searchable>();
       
        if(ramSearcher.maxDoc() > 0)
          searchersList.add(ramSearcher);
       
        if(prevRamSearcher != null && prevRamSearcher.maxDoc() > 0)
          searchersList.add(prevRamSearcher);
       
        if(diskSearcher.maxDoc() > 0)
          searchersList.add(diskSearcher);
       
        //empty index
        if(searchersList.size() == 0)
          return response;
       
        Searchable[] searchers = new Searchable[]{};
        multiSearcher = new ParallelMultiSearcher(searchersList.toArray(searchers));
       
        myFilter      = diskFilter;
     
     
      }
     
      PerFieldAnalyzerWrapper qAnalyzer = new PerFieldAnalyzerWrapper(analyzer);
      QueryParser    queryParser = new QueryParser(DOCUMENT_KEY,qAnalyzer);
     
      //add any keyword fields
      if(query.isSetKeyword_fields()){     
        for(String field : query.keyword_fields)
          qAnalyzer.addAnalyzer(field, kwAnalyzer);
      }
     
      //parse query
      //TODO: Cache?
      try{
        parsedQuery = queryParser.parse(query.getQuery());
      }catch(org.apache.lucene.queryParser.ParseException e){
        throw new ThrudexExceptionImpl(e.toString());
      }
     
 
     
      //Set Sort
View Full Code Here

      writer.updateDocument(term, document);
   
      hasWrite.set(true);
     
    }catch(IOException e){
      throw new ThrudexExceptionImpl(e.toString());
    }
  }
View Full Code Here

    try{
      writer.deleteDocuments(term);
      hasWrite.set(true);
     
    }catch(IOException e){
      throw new ThrudexExceptionImpl(e.toString());
    }
  }
View Full Code Here

  }

  public SearchResponse search(SearchQuery query) throws ThrudexException {
   
    if(!query.isSetQuery() || query.query.trim().equals(""))
      throw new ThrudexExceptionImpl("Empty Query");
   
    //Parse Query
    Query parsedQuery;
   
    //MySearcher represents the searcher instance we'll use
    //for the duration of this function call, since other threads
    //may change searcher on us...
    IndexSearcher mySearcher;
    try{

      //This section needs to be thread safe
      synchronized(this){
           
        //Commit any prev writes
        if(hasWrite.getAndSet(false)){
          writer.commit();
     
          //Reopen index reader
          IndexReader newReader = reader.reopen();
          if(reader != newReader){ 
            //reader.close();
            searcher.close();
            reader   = newReader;     
            searcher = new IndexSearcher(reader);
          }       
        }
       
        mySearcher = searcher;
       
        try{
          parsedQuery = queryParser.parse(query.getQuery());
        }catch(org.apache.lucene.queryParser.ParseException e){
          throw new ThrudexExceptionImpl(e.toString());
        }
      }
   
      //Set Sort
      Sort    sortBy = new Sort();
View Full Code Here

   */
  public void put(Document d) throws ThrudexException, TException {
   
    //make sure index is valid
    if(!isValidIndex(d.index))
      throw new ThrudexExceptionImpl("No Index Found: "+d.index)
   
    //make sure document has a key
    if(!d.isSetKey() || d.key.trim().equals(""))
      throw new ThrudexExceptionImpl("No Document key found");
     
    //Start new lucene document
    org.apache.lucene.document.Document luceneDocument =
      new org.apache.lucene.document.Document();
   
    luceneDocument.add(
        new org.apache.lucene.document.Field(
            LuceneIndex.DOCUMENT_KEY,d.key,
            org.apache.lucene.document.Field.Store.YES,
            org.apache.lucene.document.Field.Index.NOT_ANALYZED
        )
    );
   
   
    //Add fields
    for(Field field : d.fields){
     
      if(!field.isSetKey())
        throw new ThrudexExceptionImpl("Field key not set");
     
      if(!field.isSetType())
        throw new ThrudexExceptionImpl("FieldType missing");
     
     
      //Convert FieldType to Lucene types
      org.apache.lucene.document.Field.Store fieldStoreType;
      org.apache.lucene.document.Field.Index fieldIndexType;
     
      switch(field.type){
      case FieldType.TEXT:
        fieldStoreType = org.apache.lucene.document.Field.Store.YES;
        fieldIndexType = org.apache.lucene.document.Field.Index.ANALYZED;
        break;
      case FieldType.UNSTORED:
        fieldStoreType = org.apache.lucene.document.Field.Store.NO;
        fieldIndexType = org.apache.lucene.document.Field.Index.ANALYZED;
        break;
      case FieldType.KEYWORD:
        fieldStoreType = org.apache.lucene.document.Field.Store.YES;
        fieldIndexType = org.apache.lucene.document.Field.Index.NOT_ANALYZED;
        break;
      default:
        throw new ThrudexExceptionImpl("Unknown FieldType: "+field.type);
      }
     
      //Create Lucene Field
      org.apache.lucene.document.Field luceneField =
        new org.apache.lucene.document.Field(field.key, field.value, fieldStoreType,fieldIndexType);
View Full Code Here

   */
  public void remove(Element el) throws ThrudexException, TException {
   
    //make sure index is valid
    if(!isValidIndex(el.index))
      throw new ThrudexExceptionImpl("No Index Found: "+el.index)
   
    //make sure document has a key
    if(!el.isSetKey() || el.key.trim().equals(""))
      throw new ThrudexExceptionImpl("No Document key found");
   
   
    indexMap.get(el.index).remove(el.key);
  }
View Full Code Here

  public SearchResponse search(SearchQuery s) throws ThrudexException,
      TException {
    //make sure index is valid
    if(!isValidIndex(s.index))
      throw new ThrudexExceptionImpl("No Index Found: "+s.index)
   
    return indexMap.get(s.index).search(s);
  }
View Full Code Here

TOP

Related Classes of org.thrudb.thrudex.ThrudexExceptionImpl

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.