public function testSimpleCollectionIndex()
 {
     $docs = array(new TokensDocument(array("marquette", "michigan", "hiking", "hiking", "hiking", "camping", "swimming")), new TokensDocument(array("ironwood", "michigan", "hiking", "biking", "camping", "swimming", "marquette")), new TokensDocument(array("no", "tokens", "michigan")));
     $collection = new DocumentArrayCollection($docs);
     $builder = new CollectionInvertedIndexBuilder($collection);
     $index = $builder->getIndex();
     $this->assertEquals($index['michigan'], array('freq' => 3, 'postings' => array(0, 1, 2)));
 }
 public function testSingleTermSearchTermDoesNotExists()
 {
     $docs = array(new TokensDocument(array("no", "tokens")));
     $collection = new DocumentArrayCollection($docs);
     $builder = new CollectionInvertedIndexBuilder($collection);
     $adapter = new ArrayDataReaderAdapter($builder->getIndex());
     $invertedIndex = new InvertedIndex($adapter);
     $this->assertEquals(array(), $invertedIndex->query("none"));
     $this->assertEquals(array(), $invertedIndex->query("php"));
 }
示例#3
0
 /**
  * 
  * @return InvertedIndex
  */
 public function getInvertedIndex()
 {
     if (!$this->invertedIndex) {
         $docs = [new TokensDocument(["marquette", "michigan", "hiking", "hiking", "hiking", "camping", "swimming"]), new TokensDocument(["ironwood", "michigan", "hiking", "biking", "camping", "swimming", "marquette"]), new TokensDocument(["no", "tokens", "michigan"])];
         $collection = new DocumentArrayCollection($docs);
         $builder = new CollectionInvertedIndexBuilder($collection);
         $dataReader = new ArrayDataReaderAdapter($builder->getIndex());
         $this->invertedIndex = new InvertedIndex($dataReader);
     }
     return $this->invertedIndex;
 }