Author: rande
Date: 2010-01-18 14:39:26 +0100 (Mon, 18 Jan 2010)
New Revision: 26811
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexer.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
Log:
[sfSolrPlugin] add Field search option to sfLuceneCriteria
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexer.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexer.class.php
2010-01-18 13:15:04 UTC (rev 26810)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexer.class.php
2010-01-18 13:39:26 UTC (rev 26811)
@@ -216,7 +216,7 @@
{
$values[] = $object->__toString();
}
-
+
return $values;
}
else if($value instanceof Doctrine_Record)
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php
===================================================================
---
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php
2010-01-18 13:15:04 UTC (rev 26810)
+++
plugins/sfSolrPlugin/branches/sf1.2/lib/indexer/sfLuceneDoctrineIndexerHandler.class.php
2010-01-18 13:39:26 UTC (rev 26811)
@@ -104,7 +104,6 @@
unset($record);
}
-
$search_engine = $this->getSearch()->getSearchService();
try
Modified:
plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
===================================================================
--- plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
2010-01-18 13:15:04 UTC (rev 26810)
+++ plugins/sfSolrPlugin/branches/sf1.2/lib/util/sfLuceneCriteria.class.php
2010-01-18 13:39:26 UTC (rev 26811)
@@ -29,7 +29,7 @@
$scoring = null,
$params = array(),
$path = null,
- $http_method = Apache_Solr_Service::METHOD_GET,
+ $http_method = sfLuceneApacheSolrService::METHOD_GET,
$limit = 10,
$offset = 0;
@@ -125,7 +125,40 @@
{
return new self;
}
+
+ public function checkQueryFragment($query, $force = false)
+ {
+ if($query instanceof sfLuceneCriteria)
+ {
+ if($this === $query)
+ {
+ throw new sfException('Cannot add itself as a subquery');
+ }
+
+ $query = $query->getQuery();
+ if(strlen($query) == 0)
+ {
+
+ return $this;
+ }
+
+ $query = '('.$query.')';
+ }
+ else if(is_object($query))
+ {
+
+ throw new sfException('Wrong object type');
+ }
+ else if($query !== sfLuceneApacheSolrService::escape($query) && !$force)
+ {
+
+ throw new sfException('Invalid terms : '.$query.' !=
'.sfLuceneApacheSolrService::escape($query));
+ }
+
+ return $query;
+ }
+
/**
* Adds a subquery to the query itself. It accepts either a string which
will
* be parsed or a sfLuceneCriteria object.
@@ -135,33 +168,16 @@
public function add($query, $type = sfLuceneCriteria::TYPE_AND, $force =
false)
{
- if($query instanceof sfLuceneCriteria)
- {
- if($this === $query)
- {
-
- throw new sfException('Cannot add itself as a subquery');
- }
+ $query = $this->checkQueryFragment($query, $force);
+
+ $this->query = strlen($this->query) == 0 ? $query : $this->query.'
'.$type.' '.$query;
- $query = $query->getQuery();
- if(strlen($query) == 0)
- {
-
- return $this;
- }
-
- $query = '('.$query.')';
- }
- else if(is_object($query))
- {
-
- throw new sfException('Wrong object type');
- }
- else if($query !== Apache_Solr_Service::escape($query) && !$force)
- {
-
- throw new sfException('Invalid terms : '.$query.' !=
'.Apache_Solr_Service::escape($query));
- }
+ return $this;
+ }
+
+ public function addField($field, $query, $type = sfLuceneCriteria::TYPE_AND,
$force = false)
+ {
+ $query = $field.':('.$this->checkQueryFragment($query, $force).')';
$this->query = strlen($this->query) == 0 ? $query : $this->query.'
'.$type.' '.$query;
@@ -182,6 +198,22 @@
return $this->addSane($query, $type);
}
+
+ /**
+ * equivalent to addSane
+ *
+ * Add a field subquery to the query itself. The phrase will be
automatically sanitized
+ *
+ * @param string $field
+ * @param string $phrase
+ * @param string $type : OR | AND operator
+ * @return sfLuceneCriteria
+ */
+ public function addFieldString($field, $query, $type =
sfLuceneCriteria::TYPE_AND)
+ {
+
+ return $this->addFieldSane($field, $query, $type);
+ }
/**
* Add a subquery to the query itself. The phrase will be splited by words
@@ -205,7 +237,31 @@
return $this;
}
+
+ /**
+ * Add a field subquery to the query itself. The phrase will be splited by
words
+ *
+ * @param string $field
+ * @param string $phrase
+ * @param string $type : OR | AND operator
+ * @param string $inner_type : OR | AND operator
+ * @return sfLuceneCriteria
+ */
+ public function addFieldSane($field, $phrase, $type =
sfLuceneCriteria::TYPE_AND, $inner_type = sfLuceneCriteria::TYPE_OR)
+ {
+ $keywords = preg_split("/[\ ,\.]+/", $phrase);
+ $c = new self;
+ foreach($keywords as $keyword)
+ {
+ $c->add(self::sanitize($keyword), $inner_type, true);
+ }
+
+ $this->addField($field, $c->getQuery(), $type, true);
+
+ return $this;
+ }
+
/**
* Add a subquery to the query itself. The phrase will be automatically
sanitized
*
@@ -218,6 +274,12 @@
return $this->add(self::sanitize($phrase), $type, true);
}
+
+ public function addFieldPhrase($field, $phrase, $type =
sfLuceneCriteria::TYPE_AND)
+ {
+
+ return $this->addField($field, self::sanitize($phrase), $type, true);
+ }
public function addWildcard($phrase, $type = sfLuceneCriteria::TYPE_AND)
{
@@ -225,6 +287,12 @@
return $this->add(self::sanitize($phrase), $type, true );
}
+ public function addFieldWildcard($field, $phrase, $type =
sfLuceneCriteria::TYPE_AND)
+ {
+
+ return $this->addField($field, self::sanitize($phrase), $type, true );
+ }
+
public function getHttpMethod()
{
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.