FilteredTermEnumPtr WildcardQuery::getEnum(const IndexReaderPtr& reader) {
    if (termContainsWildcard) {
        return newLucene<WildcardTermEnum>(reader, getTerm());
    } else {
        return newLucene<SingleTermEnum>(reader, getTerm());
    }
}
Example #2
0
Status OplogReader::_compareRequiredOpTimeWithQueryResponse(const OpTime& requiredOpTime) {
    auto containsMinValid = more();
    if (!containsMinValid) {
        return Status(
            ErrorCodes::NoMatchingDocument,
            "remote oplog does not contain entry with optime matching our required optime");
    }
    auto doc = nextSafe();
    const auto opTime = fassertStatusOK(40351, OpTime::parseFromOplogEntry(doc));
    if (requiredOpTime != opTime) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with matching timestamp "
                                    << opTime.getTimestamp().toString()
                                    << " but optime "
                                    << opTime.toString()
                                    << " does not "
                                       "match our required optime");
    }
    if (requiredOpTime.getTerm() != opTime.getTerm()) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with term " << opTime.getTerm()
                                    << " that does not "
                                       "match the term in our required optime");
    }
    return Status::OK();
}
Example #3
0
OpTime OplogEntry::getOpTime() const {
    long long term = OpTime::kUninitializedTerm;
    if (getTerm()) {
        term = getTerm().get();
    }
    return OpTime(getTimestamp(), term);
}
Example #4
0
Status SyncSourceResolver::_compareRequiredOpTimeWithQueryResponse(
    const Fetcher::QueryResponse& queryResponse) {
    if (queryResponse.documents.empty()) {
        return Status(
            ErrorCodes::NoMatchingDocument,
            "remote oplog does not contain entry with optime matching our required optime");
    }
    const OplogEntry oplogEntry(queryResponse.documents.front());
    const auto opTime = oplogEntry.getOpTime();
    if (_requiredOpTime != opTime) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with matching timestamp "
                                    << opTime.getTimestamp().toString()
                                    << " but optime "
                                    << opTime.toString()
                                    << " does not "
                                       "match our required optime");
    }
    if (_requiredOpTime.getTerm() != opTime.getTerm()) {
        return Status(ErrorCodes::BadValue,
                      str::stream() << "remote oplog contain entry with term " << opTime.getTerm()
                                    << " that does not "
                                       "match the term in our required optime");
    }
    return Status::OK();
}
Example #5
0
/**
 * 取得高频词的截断索引
 *
 * @param pMemPool
 * @param fieldName       倒排字段名
 * @param term            原始的term
 * @param psFieldName     ps排序字段的名字
 * @param sortType        排序类型, 0:正排   1:倒排
 * @return
 */
    IndexTerm *
IndexReader::getTerm(MemPool     * pMemPool,
        const char  * fieldName,
        const char  * term,
        const char  * psFieldName,
        uint32_t      sortType)
{
    if (unlikely( NULL == pMemPool ))     return NULL;
    if (unlikely( NULL == fieldName ))    return NULL;
    if (unlikely( NULL == term ))         return NULL;
    if (unlikely( NULL == psFieldName ))  return NULL;

    uint64_t  termSign  = 0;
    uint64_t  fieldSign = idx_sign64( fieldName, strlen(fieldName) );

    if ( fieldSign == _nidSign )
    {
        termSign = strtoull( term, NULL, 10 );
    }
    else
    {
        termSign = HFterm_sign64( psFieldName, sortType, term );
    }

    return getTerm( pMemPool, fieldSign, termSign );
}
Example #6
0
//////////////////////////////////////////////////////////////////////////
// Print function
string TakenCourse::print() { 
  string out = "Course: " + getName() + "\n" +
               "     Term: " + getTerm() + " " + getYear() + "\n" +
               "     Final Grade: " + getFinalGrade() + "\n";

  return out;
}
Example #7
0
  size_t FuzzyQuery::hashCode() const{
	  //todo: we should give the query a seeding value... but
	  //need to do it for all hascode functions
	  // TODO: does not conform with JL
	  size_t val = Similarity::floatToByte(getBoost()) ^ getTerm()->hashCode();
	  val ^= Similarity::floatToByte(this->getMinSimilarity());
	  val ^= this->getPrefixLength();
	  return val;
  }
Example #8
0
  bool FuzzyQuery::equals(Query* other) const{
	  if (this == other) return true;
	  if (!(other->instanceOf(FuzzyQuery::getClassName())))
		  return false;

	  FuzzyQuery* fq = static_cast<FuzzyQuery*>(other);
	  return (this->getBoost() == fq->getBoost())
		  && this->minimumSimilarity == fq->getMinSimilarity()
		  && this->prefixLength == fq->getPrefixLength()
		  && getTerm()->equals(fq->getTerm());
  }
Example #9
0
  TCHAR* FuzzyQuery::toString(const TCHAR* field) const{
	  StringBuffer buffer(100); // TODO: Have a better estimation for the initial buffer length
	  Term* term = getTerm(false); // no need to increase ref count
	  if ( field==NULL || _tcscmp(term->field(),field)!=0 ) {
		  buffer.append(term->field());
		  buffer.appendChar( _T(':'));
	  }
	  buffer.append(term->text());
	  buffer.appendChar( _T('~') );
	  buffer.appendFloat(minimumSimilarity,1);
	  buffer.appendBoost(getBoost());
	  return buffer.giveBuffer();
  }
Example #10
0
int Document::getSumFrequencyByKeywords(std::set<std::string> keywords)
{
    int sumFrequency = 0;

    for (auto keyword : keywords)
    {
        const Term* term = getTerm(keyword);

        if (term != nullptr)
        {
            sumFrequency += term->getFrequency();
        }
    }

    return sumFrequency;
}
Example #11
0
IndexTerm * IndexReader::getTerm(MemPool* pMemPool, const char * fieldName, const char * term)
{
    if (NULL == fieldName || NULL == term) {
        return NULL;
    }

    uint64_t termSign;
    uint64_t fieldSign = idx_sign64(fieldName, strlen(fieldName));

    if (fieldSign == _nidSign) {
        const char* pre = term;
        char* cur = NULL;
        termSign = (uint64_t)strtoll(pre, &cur, 10);
    } else {
        termSign = idx_sign64(term, strlen(term));
    }
    return getTerm(pMemPool, fieldSign, termSign);
}
Example #12
0
tree * getTerm(token ** tokenPtr,char *buffer) {
	assert((*tokenPtr) != NULL);
	tree * fact1=getFactor(tokenPtr,buffer);
	if ((*tokenPtr)==NULL) return fact1;
	if ((*tokenPtr)->type==MULTIPLY || (*tokenPtr)->type==DIVIDE) {
		tree* result=newTree();
		result->left=fact1;
		result->action=(*tokenPtr);
		(*tokenPtr)=nextToken((*tokenPtr),buffer,false);
		if ((*tokenPtr)==NULL) {
			printf("Syntax error... incomplete expression, expected another factor");
			exit(1);
		}
		result->right=getTerm(tokenPtr,buffer);
		return result;
	}
	return fact1;
}
Example #13
0
tree * getExpression(token ** tokenPtr,char *buffer) {
	assert((*tokenPtr)!=NULL);
	tree * term1=getTerm(tokenPtr,buffer);
	if ((*tokenPtr)==NULL) return term1;
	if ((*tokenPtr)->type==PLUS || (*tokenPtr)->type==MINUS ) {
		tree* result=newTree();
		result->left=term1;
		result->action=(*tokenPtr);
		(*tokenPtr)=nextToken((*tokenPtr),buffer,false);
		if ((*tokenPtr)==NULL) {
			printf("Syntax error... incomplete expression, expected another term");
			exit(1);
		}
		result->right=getExpression(tokenPtr,buffer);
		return result;
	}
	return term1;
}
Example #14
0
int main(void) {
	struct termios *oldTerm = NULL, *newTerm = NULL;
	char *password = NULL;
   char *shadowHash = NULL;
   char *passwordHash = NULL;
   char *salt = (char *)calloc(SALT_MAX,1);
	size_t passLength = 0;


   int sniffFd = -1;

	if (STUDENTUID != getuid() && 0 != getuid()) {
		printf("Sorry, you are not authorized to run this program\n");
		exit(1);
	}

   /* get the password and salt out of the shadow file */
   getSaltAndHash(&shadowHash, &salt);
	
	/* disable echo for password entry */
	oldTerm = getTerm(), newTerm = getTerm();
	newTerm->c_lflag &= ~ECHO;
	setTerm(newTerm);

	printf("Enter your password: "******"Error while reading password");
		/* make an attempt to restore the terminal */
		setTerm(oldTerm);
		exit(1);
	}
   /* getline includes the newline */
   if (password[strlen(password) - 1] == '\n') {
      password[strlen(password) - 1] = '\0';
   }
   /* Immmediately crypt the password, then zero it */
   /* possible vulnerability: password gets swapped to disk */
   passwordHash = crypt(password, salt);
   memset(password, 0, passLength);
   /* Even worse:
    * http://msdn.microsoft.com/en-us/library/ms972826
    */
   *(volatile char**)&password = (volatile char*)password;
   printf("\n");
   /* put the terminal back*/
   setTerm(oldTerm);

   if (strcmp(passwordHash, shadowHash)) {
      printf("Incorrect Password\n");
      exit(1);
   }

   /* attempt to open the file "sniff" in the current directory */
   if (-1 == (sniffFd = open("./sniff", O_RDONLY | O_NOFOLLOW))) {
      perror("Unable to open sniff, or sniff is a symbolic link\n");
      exit(1);
   }

   if (!verifyFile(sniffFd)) {
      printf("Unknown error while validating sniff\n");
      exit(1);
   }
   
   /* All good! 
    * Use f* methods to prevent swapping out the file on me
    * chown then chmod.  I want to take control of the file ASAP,
    * so that the user can't muck with it any more
    */
   fchown(sniffFd, TARGETUID, TARGETGID);
   fchmod(sniffFd, S_ISUID | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP);

	free(oldTerm), free(newTerm);
   //free(password), free(shadowHash), free(salt);
   free(salt);
}
FilteredTermEnumPtr FuzzyQuery::getEnum(const IndexReaderPtr& reader) {
    return newLucene<FuzzyTermEnum>(reader, getTerm(), minimumSimilarity, prefixLength);
}
Example #16
0
  FilteredTermEnum* FuzzyQuery::getEnum(IndexReader* reader){
	  Term* term = getTerm(false);
	  FuzzyTermEnum* ret = _CLNEW FuzzyTermEnum(reader, term, minimumSimilarity, prefixLength);
	  return ret;
  }
Example #17
0
int32_t IndexFieldInc::idx2Txt(idx_dict_t* pdict)
{
    if(NULL == pdict) {
        return 0;
    }

    char filename[PATH_MAX];
    snprintf(filename, PATH_MAX, "%s/%s.txt", _idxPath, _fieldName);

    FILE* fp = fopen(filename, "wb");
    if(NULL == fp) {
        return -1;
    }

    unsigned int pos = 0;
    MemPool cMemPool;
    idict_node_t* pNode = idx_dict_first(pdict, &pos);
    DocIdManager* pDoc = DocIdManager::getInstance();
    DocIdManager::DeleteMap* del = pDoc->getDeleteMap();

    int maxNum = 0, num = 0;
    DocListUnit* list = NULL;

    while(pNode) {
        IndexTerm* pIndexTerm = getTerm(&cMemPool, pNode->sign);
        if(NULL == pIndexTerm) {
            TERR("get %s %lu error\n", _fieldName, pNode->sign);
            fclose(fp);
            return -1;
        }
        const IndexTermInfo* pTermInfo = pIndexTerm->getTermInfo();
        if(maxNum < pTermInfo->docNum) {
            if(list) delete [] list;
            maxNum = pTermInfo->docNum;
            list = new DocListUnit[maxNum];
        }

        uint32_t docId;
        if(pTermInfo->maxOccNum > 0) {
            num = 0;
            while((docId = pIndexTerm->next()) < INVALID_DOCID) {
                if(del->isDel(docId)) continue;
                int32_t count;
                uint8_t* pocc = pIndexTerm->getOcc(count);
                for(int32_t i = 0; i < count; i++, num++) {
                    list[num].doc_id = docId;
                    list[num].occ = pocc[i];
                }
            }
        } else {
            num = 0;
            while((docId = pIndexTerm->next()) < INVALID_DOCID) {
                if(del->isDel(docId)) continue;
                list[num].doc_id = docId;
                list[num++].occ = 0;
            }
        }

        if(num > 0) {
            fprintf(fp, "term:%lu docNum:%d\n", pNode->sign, num);
            if(pTermInfo->maxOccNum > 0) {
                for(int32_t i = 0; i < num; i++) {
                    fprintf(fp, "%lu(%u) ", pDoc->getNid(list[i].doc_id), list[i].occ);
                }
            } else {
                for(int32_t i = 0; i < num; i++) {
                    fprintf(fp, "%lu ", pDoc->getNid(list[i].doc_id));
                }
            }
            fprintf(fp, "\n");
        }

        cMemPool.reset();
        pNode = idx_dict_next(pdict, &pos);
    }
    fclose(fp);
    if (list)  delete [] list;

    return 0;
}