/** * Initialize a DocumentIndex with all documents stored in the DocumentStore * @param DocumentIndex $index Search index to initialize * @return DocumentIndex initialized with documents form the DocumentStore */ public function buildIndex(DocumentIndex $index) { foreach ($this->documents as $document) { $index->addDocument($document); } return $index; }
/** * Initialize a DocumentIndex with all documents stored in the DocumentStore * @param DocumentIndex $index Search index to initialize * @return DocumentIndex initialized with documents form the DocumentStore */ public function buildIndex(DocumentIndex $index) { $cursor = $this->documents->find(); foreach ($cursor as $result) { $document = new Document($result['title'], $result['content']); $document->id = $result['id']; $document->tokens = $result['tokens']; $index->addDocument($document); } return $index; }
/** * Initialize a DocumentIndex with all documents stored in the DocumentStore * @param DocumentIndex $index Search index to initialize * @return DocumentIndex initialized with documents form the DocumentStore */ public function buildIndex(DocumentIndex $index) { $query = "SELECT id, title, content FROM " . $this->table; $statement = $this->database->prepare($query); $statement->execute(); $data = $statement->fetchAll(); foreach ($data as $result) { $document = $this->buildDocument($result['id'], $result['title'], $result['content']); $index->addDocument($document); } $statement->closeCursor(); return $index; }
public function build() { if (is_null($this->index)) { throw new \Exception("Search Index not defined"); } if (is_null($this->store)) { throw new \Exception("Document Store not defined"); } if (is_null($this->tokenizer)) { throw new \Exception("Document Tokenizer not defined"); } if (is_null($this->ranker)) { throw new \Exception("Document Ranker not defined"); } $this->tokenizer->setStopWords($this->stopWords); // Init index from store data if ($this->index->size() === 0 && $this->store->size() > 0) { $this->index = $this->store->buildIndex($this->index); } return new Config($this); }