Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
b32163fa
Commit
b32163fa
authored
Jul 11, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
0813509b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
27 deletions
+73
-27
Search.php
lib/Doctrine/Search.php
+32
-16
Standard.php
lib/Doctrine/Search/Analyzer/Standard.php
+7
-1
Listener.php
lib/Doctrine/Search/Listener.php
+20
-6
Template.php
lib/Doctrine/Search/Template.php
+14
-4
No files found.
lib/Doctrine/Search.php
View file @
b32163fa
...
...
@@ -32,7 +32,29 @@
*/
class
Doctrine_Search
{
public
function
buildDefinition
(
Doctrine_Record
$record
)
protected
$_options
=
array
(
'generateFiles'
=>
true
);
public
function
__construct
(
array
$options
)
{
$this
->
_options
=
array_merge
(
$this
->
_options
,
$options
);
}
public
function
getOption
(
$option
)
{
if
(
isset
(
$this
->
_options
[
$option
]))
{
return
$this
->
_option
[
$option
];
}
return
null
;
}
public
function
setOption
(
$option
,
$value
)
{
$this
->
_options
[
$option
]
=
$value
;
return
$this
;
}
public
function
buildDefinition
(
Doctrine_Table
$table
)
{
$columns
=
array
(
'keyword'
=>
array
(
'type'
=>
'string'
,
...
...
@@ -44,15 +66,15 @@ class Doctrine_Search
'position'
=>
array
(
'type'
=>
'integer'
,
'length'
=>
8
));
$id
=
$
record
->
getTable
()
->
getIdentifier
();
$name
=
$
record
->
getTable
()
->
getComponentName
();
$id
=
$
table
->
getIdentifier
();
$name
=
$
table
->
getComponentName
();
$options
=
array
(
'className'
=>
$name
.
'Index'
);
$fk
=
array
();
foreach
((
array
)
$id
as
$column
)
{
$def
=
$
record
->
getTable
()
->
getDefinitionOf
(
$column
);
$def
=
$
table
->
getDefinitionOf
(
$column
);
unset
(
$def
[
'autoincrement'
]);
unset
(
$def
[
'sequence'
]);
...
...
@@ -77,18 +99,12 @@ class Doctrine_Search
$def
=
$builder
->
buildDefinition
(
$options
,
$columns
,
$relations
);
if
(
!
$this
->
_options
[
'generateFiles'
])
{
eval
(
$def
);
}
/**
print "<pre>";
print_r
(
$def
);
print_r(htmlentities($def));
*/
}
}
/**
fields:
[keyword] [field] [foreign_id] [position]
fields:
[keyword] [field] [match]
example data:
'orm' 'content' '1:36|2:23'
*/
lib/Doctrine/Search/Analyzer/Standard.php
View file @
b32163fa
...
...
@@ -34,6 +34,12 @@ class Doctrine_Search_Analyzer_Standard implements Doctrine_Search_Analyzer_Inte
{
public
function
analyze
(
$text
)
{
$text
=
explode
(
' '
,
$text
);
foreach
(
$text
as
$i
=>
$term
)
{
$text
[
$i
]
=
strtolower
(
trim
(
$term
));
}
return
$text
;
}
}
lib/Doctrine/Search/Listener.php
View file @
b32163fa
...
...
@@ -32,23 +32,37 @@
*/
class
Doctrine_Search_Listener
extends
Doctrine_Record_Listener
{
protected
$_search
;
public
function
__construct
(
Doctrine_Search
$search
)
{
$this
->
_search
=
$search
;
}
public
function
preUpdate
(
Doctrine_Event
$event
)
{
{
}
public
function
postUpdate
(
Doctrine_Event
$event
)
{
{
}
public
function
preInsert
(
Doctrine_Event
$event
)
{
{
}
public
function
postInsert
(
Doctrine_Event
$event
)
{
{
$fields
=
$this
->
_search
->
getOption
(
'fields'
);
foreach
(
$fields
as
$field
)
{
$terms
=
$this
->
_search
->
analyze
(
$field
);
foreach
(
$terms
as
$term
)
{
}
}
}
}
lib/Doctrine/Search/Template.php
View file @
b32163fa
...
...
@@ -32,10 +32,20 @@
*/
class
Doctrine_Search_Template
extends
Doctrine_Template
{
protected
$_search
;
public
function
__construct
(
array
$options
)
{
$this
->
_search
=
new
Doctrine_Search
(
$options
);
}
public
function
setUp
()
{
$id
=
$record
->
getTable
()
->
getIdentifier
();
$name
=
$record
->
getTable
()
->
getComponentName
()
.
'Index'
;
$this
->
_search
->
buildDefinition
(
$this
->
_table
);
$id
=
$this
->
_table
->
getIdentifier
();
$name
=
$this
->
_table
->
getComponentName
()
.
'Index'
;
$this
->
_search
->
setOption
(
'className'
,
$name
);
foreach
((
array
)
$id
as
$column
)
{
$foreign
[]
=
strtolower
(
$name
.
'_'
.
$column
);
...
...
@@ -44,7 +54,7 @@ class Doctrine_Search_Template extends Doctrine_Template
$foreign
=
(
count
(
$foreign
)
>
1
)
?
array_keys
(
$foreign
)
:
key
(
$foreign
);
$this
->
hasMany
(
$name
,
array
(
'local'
=>
$id
,
'foreign'
=>
$foreign
));
$this
->
addListener
(
new
Doctrine_Search_Listener
());
$this
->
addListener
(
new
Doctrine_Search_Listener
(
$this
->
_search
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment