--- a/.hgignore Thu Dec 08 18:43:14 2011 +0100
+++ b/.hgignore Fri Dec 09 02:21:17 2011 +0100
@@ -1,2 +1,3 @@
syntax: regexp
^\.settings$
+.*\.orig$
--- a/Command/QueryWikipediaCommand.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Command/QueryWikipediaCommand.php Fri Dec 09 02:21:17 2011 +0100
@@ -41,8 +41,9 @@
$this
->setName('wikitag:query-wikipedia')
->setDescription('Query wikipedia for tags.')
- ->addOption("force","f",InputOption::VALUE_NONE, "Force remove tags")
- ->addOption("all","a",InputOption::VALUE_NONE, "all")
+ ->addOption("force","f",InputOption::VALUE_NONE, "Force processing tags, will ask no confirmation")
+ ->addOption("all","a",InputOption::VALUE_NONE, "Search all tags")
+ ->addOption("null","n",InputOption::VALUE_NONE, "Treat only non processed tags")
->addOption("redirection",null,InputOption::VALUE_NONE, "Treat redirections")
->addOption("random","r",InputOption::VALUE_NONE, "randomize query on tags")
->addOption("site","S",InputOption::VALUE_OPTIONAL, "the url for the wikipedia site", "http://fr.wikipedia.org/w/api.php")
@@ -60,6 +61,7 @@
$site = $input->getOption('site');
$limit = intval($input->getOption('limit'));
$start = intval($input->getOption('start'));
+ $null = $input->getOption('null');
$doctrine = $this->getContainer()->get('doctrine');
$qb = $doctrine->getEntityManager()->createQueryBuilder();
@@ -72,8 +74,11 @@
if($redirection) {
$qb->where($qb->expr()->andx($qb->expr()->eq("t.urlStatus",Tag::$TAG_URL_STATUS_DICT['redirection']), $qb->expr()->isNull("t.alternativeLabel")));
}
+ elseif($null) {
+ $qb->where($qb->expr()->isNull("t.urlStatus"));
+ }
else {
- $qb->where($qb->expr()->isNull("t.urlStatus"));
+ $qb->where($qb->expr()->orx($qb->expr()->isNull("t.urlStatus"), $qb->expr()->eq("t.urlStatus", Tag::$TAG_URL_STATUS_DICT['null_result'])));
}
}
--- a/Command/SyncDocumentsCommand.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Command/SyncDocumentsCommand.php Fri Dec 09 02:21:17 2011 +0100
@@ -152,6 +152,7 @@
private function execute_docs(InputInterface $input, OutputInterface $output)
{
+ $class = $this->getContainer()->getParameter('wiki_tag.document_class');
$all = $input->getOption('all');
$doctrine = $this->getContainer()->get('doctrine');
$docrep = $doctrine->getRepository('WikiTagBundle:Document');
--- a/Controller/WikiTagController.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Controller/WikiTagController.php Fri Dec 09 02:21:17 2011 +0100
@@ -329,17 +329,21 @@
$id_doc = $this->getRequest()->request->get('wikitag_document_id');
$id_tag = $this->getRequest()->request->get('tag_id');
$tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->find($id_tag);
- //return new Response(var_dump(array($tag)));
- // We search if the unsemantized version of the tag already exist.
- $un_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('label'=>$tag->getLabel(), 'urlStatus'=>Tag::$TAG_URL_STATUS_DICT['null_result']));
+
$em = $this->getDoctrine()->getEntityManager();
- $un_tag_created = FALSE;
+ $query = $em->createQuery("SELECT t FROM WikiTagBundle:Tag t WHERE t.label = :label AND (t.urlStatus = :status_null OR t.urlStatus = :status_unsemantized)");
+ $query->setParameters(array("label"=>$tag->getLabel(),"status_null"=>Tag::$TAG_URL_STATUS_DICT['null_result'],"status_unsemantized"=>Tag::$TAG_URL_STATUS_DICT['unsemantized']));
+ $un_tag = null;
+ $un_tags = $query->getResult();
+ if(count($un_tags)>0) {
+ $un_tag = $un_tags[0];
+ }
+ $un_tag_created = false;
if(!$un_tag){
// Create another tag almost identical, without the W info
$un_tag = new Tag();
$un_tag->setLabel($tag->getLabel());
$un_tag->setOriginalLabel($tag->getOriginalLabel());
- $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']);
$un_tag->setWikipediaUrl(null);
$un_tag->setWikipediaPageId(null);
$un_tag->setAlternativeWikipediaUrl(null);
@@ -349,9 +353,18 @@
$un_tag->setCategory($tag->getCategory());
$un_tag->setAlias($tag->getAlias());
$un_tag->setPopularity($tag->getPopularity());
- $em->persist($un_tag);
+ $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
$un_tag_created = true;
+ $em->persist($un_tag);
}
+ elseif($un_tag->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['null_result'])
+ {
+ $un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['unsemantized']);
+ $un_tag_created = true;
+ $em->persist($un_tag);
+ }
+
+
if($id_doc && $id_doc!=""){
// We associate the unsemantized tag to the DocumentTag and save datas
@@ -362,7 +375,7 @@
}
else{
// Here we are in the context of tag list.
- if($un_tag_created==TRUE){
+ if($un_tag_created==true){
$em->flush();
$num_page = $this->getRequest()->request->get('num_page');
$nb_by_page = $this->getRequest()->request->get('nb_by_page');
@@ -548,7 +561,8 @@
$searched = $this->getRequest()->request->get('searched');
return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched);
}
-
+
+
/**
*
* Resemantize the tag with its original label. Kind of undo if we changed the tag's label.
--- a/Entity/DocumentRepository.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Entity/DocumentRepository.php Fri Dec 09 02:21:17 2011 +0100
@@ -365,5 +365,28 @@
return $res;
}
+
+ /**
+ * Copy the tahg lst from one document instance to another
+ * @param IRI\Bundle\WikitagBundle\Model\DocumentInterface $src_doc
+ * @param IRI\Bundle\WikitagBundle\Model\DocumentInterface $tgt_doc
+ */
+ public function copyTags($src_doc, $tgt_doc)
+ {
+ //remove the previous tags
+ foreach ($tgt_doc->getTags() as $doctag) {
+ $this->getEntityManager()->remove($doctag);
+ }
+
+ // add the new ones
+ foreach ($src_doc->getTags() as $doctag) {
+ $new_doctag = clone $doctag;
+ $new_doctag->setDocument($tgt_doc);
+ $this->getEntityManager()->persist($new_doctag);
+ }
+
+ $tgt_doc->setManualOrder(false);
+ $this->getEntityManager()->persist($tgt_doc);
+ }
}
\ No newline at end of file
--- a/Entity/DocumentTagRepository.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Entity/DocumentTagRepository.php Fri Dec 09 02:21:17 2011 +0100
@@ -95,5 +95,5 @@
return null;
}
}
-
+
}
\ No newline at end of file
--- a/Entity/TagRepository.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Entity/TagRepository.php Fri Dec 09 02:21:17 2011 +0100
@@ -58,9 +58,11 @@
$tags = $this->findBy(array('normalizedLabel' => $tag_label_normalized));
$tag = null;
foreach ($tags as $t) {
- if($tag==null || $t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
+ if($tag==null
+ || $tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['unsemantized']
+ || ($tag->getUrlStatus() === Tag::$TAG_URL_STATUS_DICT['null_result'] && $t->getUrlStatus() !== Tag::$TAG_URL_STATUS_DICT['unsemantized'])) {
$tag = $t;
- if($t->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
+ if($tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['unsemantized'] && $tag->getUrlStatus()!=Tag::$TAG_URL_STATUS_DICT['null_result']) {
break;
}
}
@@ -75,37 +77,10 @@
}
else {
$created = false;
- $match_exists = false;
- // Even if a tag with the normalised label exists, IF this tag is not wikipedia semantised,
- // we search if a wikipedia semantised version exists in the base
- foreach ($tags as $t) {
- if($t->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['match']) {
- $tag = $t;
- $match_exists = true;
- break;
- }
- }
- if($match_exists==false) {
- try {
- $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
- }
- catch (\Exception $e){
- throw new \Exception($e->getMessage());
- }
- $status = $wp_response['status'];
- if($status==Tag::$TAG_URL_STATUS_DICT['match']) {
- $tag = new Tag();
- $tag->setLabel($tag_label_normalized);
- $tag->setOriginalLabel($tag_label);
- $tag->setNormalizedLabel($tag_label_normalized);
- $created = true;
- $wp_request_done = true;
- }
- }
}
- // We request Wikipedia if the tag is created
- if($created==true) {
+ // We request Wikipedia if the tag is created or if this is a null result
+ if($created==true || $tag->getUrlStatus()===Tag::$TAG_URL_STATUS_DICT['null_result']) {
if($wp_request_done==false) {
try {
@@ -142,5 +117,4 @@
return array($tag, $wikipedia_revision_id, $created);//, $wpReponse);
}
-
-}
\ No newline at end of file
+}
--- a/Listener/DocumentListener.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Listener/DocumentListener.php Fri Dec 09 02:21:17 2011 +0100
@@ -117,7 +117,7 @@
$class = $this->getContainer()->getParameter("wiki_tag.document_class");
if (is_a($entity, $class))
{
- $logger->debug("treating document : " . $entity->getTitle());
+ $logger->debug("treating document : " . $entity->getId());
$this->container->get('doctrine')->getRepository("WikiTagBundle:Document")->writeDocument($entity, $this->getContainer()->getParameter("wiki_tag.document_id_column"), $this->getContainer()->getParameter("wiki_tag.fields"));
}
elseif (is_a($entity, "IRI\Bundle\WikiTagBundle\Model\DocumentTagInterface"))
--- a/Model/Document.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Model/Document.php Fri Dec 09 02:21:17 2011 +0100
@@ -74,7 +74,7 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.BaseDocumentInterface::setExternalId()
*/
function setExternalId($externalId)
@@ -83,7 +83,7 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getExternalId()
*/
function getExternalId()
@@ -92,7 +92,7 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getTags()
*/
function getTags()
@@ -101,18 +101,18 @@
}
/**
- * TODO: (non-PHPdoc)
+ * (non-PHPdoc)
* @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::setTagsStr()
*/
function setTagsStr($tagsStr)
{
$this->tagsStr = $tagsStr;
}
-
- /**
- * TODO: (non-PHPdoc)
- * @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getTagsStr()
- */
+
+ /**
+ * (non-PHPdoc)
+ * @see IRI\Bundle\WikiTagBundle\Model.DocumentInterface::getTagsStr()
+ */
function getTagsStr()
{
return $this->tagsStr;
--- a/Model/DocumentInterface.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Model/DocumentInterface.php Fri Dec 09 02:21:17 2011 +0100
@@ -51,6 +51,13 @@
function getManualOrder();
/**
+ * Get the list of tags
+ *
+ * @return array of IRI\Bundle\WikiTagBundle\Model\DocumentTagInterface
+ */
+ function getTags();
+
+ /**
* Get tagsStr
*
* @return string
@@ -63,5 +70,5 @@
* @param $tagsStr
*/
function setTagsStr($tagsStr);
-
+
}
--- a/Model/DocumentTag.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Model/DocumentTag.php Fri Dec 09 02:21:17 2011 +0100
@@ -189,4 +189,6 @@
return $WIKIPEDIA_VERSION_PERMALINK_TEMPLATE.$this->wikipediaRevisionId;
}
+
+
}
\ No newline at end of file
--- a/Model/DocumentTagInterface.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Model/DocumentTagInterface.php Fri Dec 09 02:21:17 2011 +0100
@@ -102,5 +102,6 @@
* @return object
*/
function getDocument();
+
}
\ No newline at end of file
--- a/Model/Tag.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Model/Tag.php Fri Dec 09 02:21:17 2011 +0100
@@ -15,7 +15,7 @@
abstract class Tag implements TagInterface {
- public static $TAG_URL_STATUS_DICT = array('null_result'=>0,'redirection'=>1,'homonyme'=>2,'match'=>3);
+ public static $TAG_URL_STATUS_DICT = array('null_result'=>0,'redirection'=>1,'homonyme'=>2,'match'=>3, 'unsemantized'=>4);
/**
* @var integer $id
@@ -317,6 +317,10 @@
*/
public function getUrlStatusText()
{
+ if(is_null($this->getUrlStatus()))
+ {
+ return null;
+ }
switch ($this->getUrlStatus()) {
case 0:
return "null_result";
@@ -326,6 +330,10 @@
return "homonyme";
case 3:
return "match";
+ case 4:
+ return "unsemantized";
+ default:
+ return "";
}
}
--- a/Resources/config/services.yml Thu Dec 08 18:43:14 2011 +0100
+++ b/Resources/config/services.yml Fri Dec 09 02:21:17 2011 +0100
@@ -3,7 +3,8 @@
wiki_tag.document_listener.class: IRI\Bundle\WikiTagBundle\Listener\DocumentListener
wiki_tag.wiki_tag_document_listener.class: IRI\Bundle\WikiTagBundle\Listener\WikiTagDocumentListener
wiki_tag.shema_utils.class: IRI\Bundle\WikiTagBundle\Utils\SchemaUtils
- wiki_tag.search_class: IRI\Bundle\WikiTagBundle\Search\Search
+ wiki_tag.search_service_class: IRI\Bundle\WikiTagBundle\Services\SearchService
+ wiki_tag.document_service_class: IRI\Bundle\WikiTagBundle\Services\DocumentService
services:
@@ -25,9 +26,14 @@
arguments: [@service_container]
wiki_tag.search:
- class: %wiki_tag.search_class%
+ class: %wiki_tag.search_service_class%
arguments: [@service_container]
+ wiki_tag.document:
+ class: %wiki_tag.document_service_class%
+ arguments: [@service_container]
+
+
# wiki_tag.example:
# class: %wiki_tag.example.class%
# arguments: [@service_id, "plain_value", %parameter%]
--- a/Resources/views/WikiTag/TagListTable.html.twig Thu Dec 08 18:43:14 2011 +0100
+++ b/Resources/views/WikiTag/TagListTable.html.twig Fri Dec 09 02:21:17 2011 +0100
@@ -16,10 +16,10 @@
{% endif %}
</th>
<th>original_label</th>
- <th class="text_centered">Lien W</th>
- <th class="text_centered">Lien D</th>
+ <th class="wikitag_text_centered">Lien W</th>
+ <th class="wikitag_text_centered">Lien D</th>
<th>Catégorie</th>
- <th class="large_25 text_centered">Supprimer<br/>le lien W</th>
+ <th class="wikitag_large_25 wikitag_text_centered">Supprimer le lien W</th>
<th>Alias</th>
<th>
{% if sort != "nba" and sort != "nbd" %}
@@ -70,7 +70,11 @@
{% endif %}
</td>
<td class="wikitag_category" id="{{tag.id}}">{% if tag.category %}{{ tag.category.label }}{% endif %}</td>
+ {% if tag.urlstatus and tag.urlstatus != 4 and tag.urlstatus != 0 %}
<td class="wikitag_text_centered wikitag_td_icon wikitag_remove_wp_link" id="{{tag.id}}" alt="{{tag.label}}" ></td>
+ {% else %}
+ <td class="wikitag_text_centered wikitag_td_icon"></td>
+ % endif %}
<td class="wikitag_alias" id="{{tag.id}}" >{% if tag.alias %}{{tag.alias}}{% endif %}</td>
<td class="wikitag_text_centered">
{% if nb_docs > 0 %}
@@ -82,4 +86,4 @@
<td class="wikitag_text_centered">{{tag.popularity}}</td></tr>
{% endfor %}
</table>
-{% endblock %}
\ No newline at end of file
+{% endblock %}
--- a/Search/Search.php Thu Dec 08 18:43:14 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-<?php
-/*
- * This file is part of the WikiTagBundle package.
- *
- * (c) IRI <http://www.iri.centrepompidou.fr/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-namespace IRI\Bundle\WikiTagBundle\Search;
-
-use Symfony\Component\DependencyInjection\ContainerAware;
-use Symfony\Component\DependencyInjection\ContainerInterface;
-
-class Search extends ContainerAware
-{
- /**
- * Get the container associated with this service.
- * @return ContainerInterface
- */
- public function getContainer()
- {
- return $this->container;
- }
-
- /**
- * Public constructor with container as parameter for contruct injection.
- * @param ContainerInterface $container
- */
- public function __construct(ContainerInterface $container)
- {
- $this->setContainer($container);
- }
-
- private $doctrine;
-
- public function getDoctrine()
- {
- if(is_null($this->doctrine))
- {
- $this->doctrine = $this->getContainer()->get('doctrine');
- }
- return $this->doctrine;
- }
- /**
- *
- * Enter description here ...
- * @param string $value
- * @param array $conditions
- * @param array $fields
- */
- public function search($value, array $conditions, array $fields=null)
- {
- if(is_null($fields))
- {
- $fields = $this->getContainer()->getParameter("wiki_tag.fields");
- }
- $doctrine = $this->getContainer()->get('doctrine');
- $res = $doctrine->getRepository('WikiTagBundle:Document');
- $fieldquery = array();
- foreach ($fields as $fieldname => $fielddef) {
- if(isset($fielddef['weight']))
- {
- $weight = $fielddef['weight'];
- }
- else
- {
- $weight = 1.0;
- }
- $fieldquery[] = array("columns"=>$fieldname, "value"=>$value, "weight"=>$weight);
- }
-
- $score_res = $res->search($fieldquery, $conditions);
-
- return $score_res;
- }
-
- /**
- * Service to reorder the tags using their notes in the index search
- * @param IRI\Bundle\WikiTagBundle\Model\DocumentInterface $document
- */
- public function reorderTagsForDocument($document)
- {
- $doctrine = $this->getContainer()->get('doctrine');
-
- $tags_score = array();
-
- foreach($document->getTags() as $tag)
- {
- $label = $tag->getTag()->getLabel();
-
- $score_res = $this->search($label, array("id"=>$document->getId()));
-
- if(count($score_res)>0)
- {
- $score = floatval($score_res[0]['score']);
- }
- else
- {
- $score = 0.0;
- }
- $tags_score[] = array($score,$tag);
- }
- // sort tags based on score
- $i=1;
- usort($tags_score, function($a, $b) {
- return $a[0]<$b[0]?1:-1;
- });
-
- foreach($tags_score as $item)
- {
- $tag = $item[1];
- $tag->setTagOrder($i++);
- $tag->setIndexNote($item[0]);
- $doctrine->getEntityManager()->persist($tag);
- }
-
- }
-
- public function getTagCloud($max_tags)
- {
- $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag');
- return $rep->getTagCloud($max_tags);
- }
-
- public function completion($seed)
- {
- $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag');
-
- $res = array();
- foreach ($rep->getCompletion($seed) as $value) {
- $res[] = $value['label'];
- }
-
- return $res;
-
- }
-
-
-}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Services/DocumentService.php Fri Dec 09 02:21:17 2011 +0100
@@ -0,0 +1,81 @@
+<?php
+/*
+ * This file is part of the WikiTagBundle package.
+ *
+ * (c) IRI <http://www.iri.centrepompidou.fr/>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace IRI\Bundle\WikiTagBundle\Services;
+
+use Symfony\Component\DependencyInjection\ContainerAware;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+class DocumentService extends ContainerAware
+{
+ /**
+ * Get the container associated with this service.
+ * @return ContainerInterface
+ */
+ public function getContainer()
+ {
+ return $this->container;
+ }
+
+ /**
+ * Public constructor with container as parameter for contruct injection.
+ * @param ContainerInterface $container
+ */
+ public function __construct(ContainerInterface $container)
+ {
+ $this->setContainer($container);
+ }
+
+ private $doctrine;
+
+ public function getDoctrine()
+ {
+ if(is_null($this->doctrine))
+ {
+ $this->doctrine = $this->getContainer()->get('doctrine');
+ }
+ return $this->doctrine;
+ }
+
+
+ /**
+ * Copy the list of tags of one document to another.
+ *
+ * @param mixed $id_doc_src the source document id
+ * @param mixed $id_doc_tgt the target document id
+ */
+ public function copyTags($id_doc_src, $id_doc_tgt)
+ {
+
+ $doctrine = $this->getDoctrine();
+ $em = $doctrine->getEntityManager();
+
+ $doc_rep = $em->getRepository("WikiTagBundle:Document");
+
+ $src_doc = $doc_rep->findOneByExternalId($id_doc_src);
+ if(is_null($src_doc))
+ {
+ throw new Exception("cloneTags: no source doc");
+ }
+
+ $tgt_doc = $doc_rep->findOneByExternalId($id_doc_tgt);
+ if(is_null($tgt_doc))
+ {
+ throw new Exception("cloneTags: no target doc");
+ }
+
+
+ $doc_rep->copyTags($src_doc, $tgt_doc);
+
+ $em->flush();
+
+ }
+
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Services/SearchService.php Fri Dec 09 02:21:17 2011 +0100
@@ -0,0 +1,140 @@
+<?php
+/*
+ * This file is part of the WikiTagBundle package.
+ *
+ * (c) IRI <http://www.iri.centrepompidou.fr/>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace IRI\Bundle\WikiTagBundle\Services;
+
+use Symfony\Component\DependencyInjection\ContainerAware;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+class SearchService extends ContainerAware
+{
+ /**
+ * Get the container associated with this service.
+ * @return ContainerInterface
+ */
+ public function getContainer()
+ {
+ return $this->container;
+ }
+
+ /**
+ * Public constructor with container as parameter for contruct injection.
+ * @param ContainerInterface $container
+ */
+ public function __construct(ContainerInterface $container)
+ {
+ $this->setContainer($container);
+ }
+
+ private $doctrine;
+
+ public function getDoctrine()
+ {
+ if(is_null($this->doctrine))
+ {
+ $this->doctrine = $this->getContainer()->get('doctrine');
+ }
+ return $this->doctrine;
+ }
+ /**
+ *
+ * Enter description here ...
+ * @param string $value
+ * @param array $conditions
+ * @param array $fields
+ */
+ public function search($value, array $conditions, array $fields=null)
+ {
+ if(is_null($fields))
+ {
+ $fields = $this->getContainer()->getParameter("wiki_tag.fields");
+ }
+ $doctrine = $this->getContainer()->get('doctrine');
+ $res = $doctrine->getRepository('WikiTagBundle:Document');
+ $fieldquery = array();
+ foreach ($fields as $fieldname => $fielddef) {
+ if(isset($fielddef['weight']))
+ {
+ $weight = $fielddef['weight'];
+ }
+ else
+ {
+ $weight = 1.0;
+ }
+ $fieldquery[] = array("columns"=>$fieldname, "value"=>$value, "weight"=>$weight);
+ }
+
+ $score_res = $res->search($fieldquery, $conditions);
+
+ return $score_res;
+ }
+
+ /**
+ * Service to reorder the tags using their notes in the index search
+ * @param IRI\Bundle\WikiTagBundle\Model\DocumentInterface $document
+ */
+ public function reorderTagsForDocument($document)
+ {
+ $doctrine = $this->getContainer()->get('doctrine');
+
+ $tags_score = array();
+
+ foreach($document->getTags() as $tag)
+ {
+ $label = $tag->getTag()->getLabel();
+
+ $score_res = $this->search($label, array("id"=>$document->getId()));
+
+ if(count($score_res)>0)
+ {
+ $score = floatval($score_res[0]['score']);
+ }
+ else
+ {
+ $score = 0.0;
+ }
+ $tags_score[] = array($score,$tag);
+ }
+ // sort tags based on score
+ $i=1;
+ usort($tags_score, function($a, $b) {
+ return $a[0]<$b[0]?1:-1;
+ });
+
+ foreach($tags_score as $item)
+ {
+ $tag = $item[1];
+ $tag->setTagOrder($i++);
+ $tag->setIndexNote($item[0]);
+ $doctrine->getEntityManager()->persist($tag);
+ }
+
+ }
+
+ public function getTagCloud($max_tags)
+ {
+ $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag');
+ return $rep->getTagCloud($max_tags);
+ }
+
+ public function completion($seed)
+ {
+ $rep = $this->getDoctrine()->getRepository('WikiTagBundle:Tag');
+
+ $res = array();
+ foreach ($rep->getCompletion($seed) as $value) {
+ $res[] = $value['label'];
+ }
+
+ return $res;
+
+ }
+
+
+}
\ No newline at end of file
--- a/Tests/Search/SearchServiceTest.php Thu Dec 08 18:43:14 2011 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-<?php
-/*
- * This file is part of the WikiTagBundle package.
- *
- * (c) IRI <http://www.iri.centrepompidou.fr/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace IRI\Bundle\WikiTagBundle\Tests\Services;
-
-require_once(__DIR__ . "/../../../../../../../app/AppKernel.php");
-
-class SearchServiceTest extends \PHPUnit_Framework_TestCase
-{
-
- protected $_container;
-
- public function __construct()
- {
- $kernel = new \AppKernel("test", true);
- $kernel->boot();
- $this->_container = $kernel->getContainer();
- parent::__construct();
- }
-
- protected function get($service)
- {
- return $this->_container->get($service);
- }
-
-
- public function testTagCloud()
- {
-
- $search_service = $this->get("wiki_tag.search");
-
- $result = $search_service->getTagCloud(30);
-
- $this->assertNotNull($result, "tag cloud should not be null");
- $this->assertLessThanOrEqual(30, count($result));
- }
-
-
- public function testCompletion()
- {
-
- $search_service = $this->get("wiki_tag.search");
-
- $result = $search_service->completion("fra");
-
- $this->assertNotNull($result, "tag cloud should not be null");
- $this->assertGreaterThanOrEqual(1, count($result));
- }
-
-
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Tests/Services/DocumentServiceTest.php Fri Dec 09 02:21:17 2011 +0100
@@ -0,0 +1,47 @@
+<?php
+/*
+ * This file is part of the WikiTagBundle package.
+ *
+ * (c) IRI <http://www.iri.centrepompidou.fr/>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace IRI\Bundle\WikiTagBundle\Tests\Services;
+
+require_once(__DIR__ . "/../../../../../../../app/AppKernel.php");
+
+class DocumentServiceTest extends \PHPUnit_Framework_TestCase
+{
+
+ protected $_container;
+
+ public function __construct()
+ {
+ $kernel = new \AppKernel("test", true);
+ $kernel->boot();
+ $this->_container = $kernel->getContainer();
+ parent::__construct();
+ }
+
+ protected function get($service)
+ {
+ return $this->_container->get($service);
+ }
+
+
+ public function testCopyTags()
+ {
+
+ $search_service = $this->get("wiki_tag.document");
+
+ // TODO : get doc 1
+ // TODO : get doc 2
+ // call copyTags
+
+ }
+
+
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Tests/Services/SearchServiceTest.php Fri Dec 09 02:21:17 2011 +0100
@@ -0,0 +1,59 @@
+<?php
+/*
+ * This file is part of the WikiTagBundle package.
+ *
+ * (c) IRI <http://www.iri.centrepompidou.fr/>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace IRI\Bundle\WikiTagBundle\Tests\Services;
+
+require_once(__DIR__ . "/../../../../../../../app/AppKernel.php");
+
+class SearchServiceTest extends \PHPUnit_Framework_TestCase
+{
+
+ protected $_container;
+
+ public function __construct()
+ {
+ $kernel = new \AppKernel("test", true);
+ $kernel->boot();
+ $this->_container = $kernel->getContainer();
+ parent::__construct();
+ }
+
+ protected function get($service)
+ {
+ return $this->_container->get($service);
+ }
+
+
+ public function testTagCloud()
+ {
+
+ $search_service = $this->get("wiki_tag.search");
+
+ $result = $search_service->getTagCloud(30);
+
+ $this->assertNotNull($result, "tag cloud should not be null");
+ $this->assertLessThanOrEqual(30, count($result));
+ }
+
+
+ public function testCompletion()
+ {
+
+ $search_service = $this->get("wiki_tag.search");
+
+ $result = $search_service->completion("fra");
+
+ $this->assertNotNull($result, "tag cloud should not be null");
+ $this->assertGreaterThanOrEqual(1, count($result));
+ }
+
+
+}
+
--- a/Utils/SchemaUtils.php Thu Dec 08 18:43:14 2011 +0100
+++ b/Utils/SchemaUtils.php Fri Dec 09 02:21:17 2011 +0100
@@ -90,7 +90,6 @@
public function filter_foreign_key(array $sqls)
{
$res_sqls = array();
- //TODO : take the column and table names from the schema
foreach ($sqls as $sql) {
if(!preg_match("/ADD CONSTRAINT .+ FOREIGN KEY \(.*\) REFERENCES wikitag_document\(id\)/i", $sql))
{