Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 909c129

Browse files
author
Charles Marion
committed
1 parent b36e7e5 commit 909c129

File tree

3 files changed

+88
-27
lines changed

3 files changed

+88
-27
lines changed

core/controllers/ImportController.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,28 @@ private function _recursiveParseDirectory($path,$currentdir)
133133
$item->setName($fileInfo->getFilename());
134134
$this->Item->save($item);
135135

136+
136137
// Set the keyword for the item
137-
$keyword = new ItemKeywordDao;
138+
$keyword = new ItemKeywordDao();
138139
$keyword->setValue($fileInfo->getFilename());
139140
$this->ItemKeyword->insertKeyword($keyword);
140-
141-
$this->Item->addKeyword($item,$keyword);
141+
$this->Item->addKeyword($item,$keyword);
142+
143+
$tmp=str_replace('.', ' ', $fileInfo->getFilename());
144+
$tmp=str_replace('_', ' ', $tmp);
145+
$tmp=str_replace('-', ' ', $tmp);
146+
147+
$keywords=explode(' ', $tmp);
148+
if(count($keywords)>1)
149+
{
150+
foreach ($keywords as $key => $value)
151+
{
152+
$keyword = new ItemKeywordDao();
153+
$keyword->setValue($value);
154+
$this->ItemKeyword->insertKeyword($keyword);
155+
$this->Item->addKeyword($item,$keyword);
156+
}
157+
}
142158

143159
// Set the policy of the item
144160
$this->Itempolicyuser->createPolicy($this->userSession->Dao,$item,MIDAS_POLICY_ADMIN);

core/controllers/UploadController.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
167167
$item->setThumbnail('');
168168
$this->Item->save($item);
169169

170-
// Set the keyword for the item
171-
$keyword = new ItemKeywordDao();
172-
$keyword->setValue($name);
173-
$this->ItemKeyword->insertKeyword($keyword);
174-
175170
$feed=$this->Feed->createFeed($this->userSession->Dao,MIDAS_FEED_CREATE_ITEM,$item);
176171
if(isset($privacy)&&$privacy=='public')
177172
{
@@ -192,9 +187,29 @@ private function createUploadedItem($userDao,$name,$path,$privacy=null)
192187
$itemRevisionDao->setUser_id($userDao->getKey());
193188
$itemRevisionDao->setDate(date('c'));
194189
$this->Item->addRevision($item,$itemRevisionDao);
195-
196-
$this->Item->addKeyword($item,$keyword);
197190

191+
// Set the keyword for the item
192+
$keyword = new ItemKeywordDao();
193+
$keyword->setValue($name);
194+
$this->ItemKeyword->insertKeyword($keyword);
195+
$this->Item->addKeyword($item,$keyword);
196+
197+
$tmp=str_replace('.', ' ', $name);
198+
$tmp=str_replace('_', ' ', $tmp);
199+
$tmp=str_replace('-', ' ', $tmp);
200+
201+
$keywords=explode(' ', $tmp);
202+
if(count($keywords)>1)
203+
{
204+
foreach ($keywords as $key => $value)
205+
{
206+
$keyword = new ItemKeywordDao();
207+
$keyword->setValue($value);
208+
$this->ItemKeyword->insertKeyword($keyword);
209+
$this->Item->addKeyword($item,$keyword);
210+
}
211+
}
212+
198213
// Add bitstreams to the revision
199214
$bitstreamDao = new BitstreamDao;
200215
$bitstreamDao->setName($name);

core/models/pdo/ItemKeywordModel.php

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,60 @@ function getItemsFromSearch($searchterm,$userDao,$limit=14,$group=true,$order='v
3030
}
3131
}
3232

33+
$searchterms=explode(' ', $searchterm);
3334
// Apparently it's slow to do a like in a subquery so we run it first
34-
$sql = $this->database->select()->from(array('itemkeyword'),array('keyword_id'))
35-
->where('value LIKE ?','%'.$searchterm.'%');
36-
$ids = '(';
35+
$sql = $this->database->select()->from(array('i'=>'itemkeyword'),array())
36+
->setIntegrityCheck(false);
37+
$sql->join(array('i2k' => 'item2keyword'),'i.keyword_id=i2k.keyword_id',array('item_id'));
38+
39+
if(empty($searchterms))
40+
{
41+
return array();
42+
}
43+
44+
foreach($searchterms as $key=>$term)
45+
{
46+
if($key==0)
47+
{
48+
$sql->where('value LIKE ?','%'.$term.'%');
49+
}
50+
else
51+
{
52+
$sql->orWhere('value LIKE ?','%'.$term.'%');
53+
}
54+
}
55+
3756
$rowset = $this->database->fetchAll($sql);
3857
$return = array();
58+
$itemIdsCount=array();
59+
$itemIds=array();
3960
foreach($rowset as $row)
4061
{
41-
if($ids != '(')
62+
if(isset($itemIdsCount[$row->item_id]))
4263
{
43-
$ids .= ',';
44-
}
45-
$ids .= $row->keyword_id;
64+
$itemIdsCount[$row->item_id]++;
65+
}
66+
else
67+
{
68+
$itemIdsCount[$row->item_id]=1;
69+
}
4670
}
47-
$ids .= ')';
48-
49-
// If we don't have any data we return
50-
if(count($rowset) == 0)
71+
foreach($itemIdsCount as $key=>$n)
5172
{
52-
return $return;
73+
if($n<count($searchterms))
74+
{
75+
unset($itemIdsCount[$key]);
76+
}
77+
else
78+
{
79+
$itemIds[]=$key;
80+
}
81+
}
82+
83+
if(empty($itemIds))
84+
{
85+
return array();
5386
}
54-
5587
$sql=$this->database->select();
5688
if($group)
5789
{
@@ -62,7 +94,6 @@ function getItemsFromSearch($searchterm,$userDao,$limit=14,$group=true,$order='v
6294
$sql->from(array('i' => 'item'));
6395
}
6496

65-
$sql->join(array('i2k' => 'item2keyword'),'i.item_id=i2k.item_id');
6697
if(!$isAdmin)
6798
{
6899
$sql ->joinLeft(array('ipu' => 'itempolicyuser'),'
@@ -85,7 +116,7 @@ function getItemsFromSearch($searchterm,$userDao,$limit=14,$group=true,$order='v
85116
);
86117
}
87118
$sql->setIntegrityCheck(false)
88-
->where('i2k.keyword_id IN '.$ids)
119+
->where('i.item_id IN (?)',$itemIds)
89120
->limit($limit)
90121
;
91122

@@ -107,7 +138,6 @@ function getItemsFromSearch($searchterm,$userDao,$limit=14,$group=true,$order='v
107138
$sql->order(array('i.view DESC'));
108139
break;
109140
}
110-
111141
$rowset = $this->database->fetchAll($sql);
112142
foreach($rowset as $row)
113143
{
@@ -130,7 +160,7 @@ function insertKeyword($keyword)
130160
{
131161
throw new Zend_Exception("Should be a keyword" );
132162
}
133-
163+
134164
// Check if the keyword already exists
135165
$row = $this->database->fetchRow($this->database->select()->from($this->_name)
136166
->where('value=?',$keyword->getValue()));

0 commit comments

Comments
 (0)