egeloen / IvoryLuceneSearchBundle

Provides a Zend Lucene Search integration for your Symfony2 project.
MIT License
29 stars 11 forks source link

Index doesn't exists in the specified directory. #1

Closed Sgnx closed 10 years ago

Sgnx commented 12 years ago

Hi,

I am getting such an error: Index doesn't exists in the specified directory.

Could Anyone help me what am i doing wrong?

egeloen commented 12 years ago

Can you explain more precisely where and how do you get this error ?

Sgnx commented 12 years ago

Ok, I found a mistake but i have another question:

I'm using sonataAdmin.

in Config i have: services: ivory_lucene_search: class: Ivory\LuceneSearchBundle\Model\LuceneManager

in RestaurantAdmin.php i have:

public function postUpdate($object) {

$luceneSearch = $this->configurationPool->getContainer()->get('ivory_lucene_search');
$indexes = array(
'identifier1' => array(
    'path' => '/home/platne/sgnx/public_html/web/zend/lucene/index1/ '
)
);

$luceneSearch->setIndexes($indexes);
$index = $luceneSearch->getIndex('identifier1');
  // remove existing entries
  foreach ($index->find('pk:'.$object->getId()) as $hit)
  {
    $index->delete($hit->id);
  }

  // don't index expired and non-activated jobs

  $doc = new Document();

  // store job primary key to identify it in the search results
  $doc->addField(Field::Keyword('pk', $object->getId()));

  // index job fields
  $doc->addField(Field::UnStored('position', $object->getPosition(), 'utf-8'));
  $doc->addField(Field::Keyword('typer', $object->getType(), 'utf-8'));
  $doc->addField(Field::Text('name', $object->getName(), 'utf-8'));
  $doc->addField(Field::Text('description', $object->getDescription(), 'utf-8'));
  $categories_for_indexing = '';
    $doc->addField(Field::Keyword('garden', $object->getGarden(), 'utf-8'));
    $doc->addField(Field::Keyword('smoking', $object->getSmoking(), 'utf-8'));
    $doc->addField(Field::Keyword('wifi', $object->getWifi(), 'utf-8'));
    $doc->addField(Field::Keyword('cattering', $object->getCattering(), 'utf-8'));
    $doc->addField(Field::Keyword('price_level', $object->getPriceLevel(), 'utf-8'));
    foreach ($object->getKitchen() as $kitchen)
        {
          $categories_for_indexing .= $kitchen->getName(). ',';
        }
    $doc->addField(Field::UnStored('categories', $categories_for_indexing, 'utf-8'));

    // Add your document to the index
    $index->addDocument($doc);

    // Commit your change
    $index->commit();

}

There is no error anymore but in /index1/ directory there are no files. Could You give me a clue what am i doing wrong ?

egeloen commented 12 years ago

Have you created the /home/platne/sgnx/public_html/web/zend/lucene/index1/ directory manually ?

Sgnx commented 12 years ago

web/zend/lucene was created by me but index1 directory was created automatic.

Sgnx commented 12 years ago

any clues ?

egeloen commented 12 years ago

I have reorganized your code to be more robust. So, in your config:

ivory_lucene_search:
    indentifier1:
        path: "/home/platne/sgnx/public_html/web/zend/lucene/index1"

And so, your code will look like:

public function postUpdate($object)
{
    $index = $this->configurationPool->getContainer()->get('ivory_lucene_search')->getIndex('identifier1');
    // you code here
}

I have try it on a new symfony-standard edition & it's work.

Sgnx commented 12 years ago

Hi I update my config and RestaurantAdmin.php but i receive:

The lucene index path "identifier1" does not exist. 500 Internal Server Error - InvalidArgumentException

Sgnx commented 12 years ago

?:)

egeloen commented 12 years ago

I will look your problem this week end. I'm totally busy currently...

Sgnx commented 12 years ago

Any ideas ?:) I know that You are very busy but if You find time to solve my problem I will appreaciete that a lot.

egeloen commented 12 years ago

I think I have solved your issue. The problem was I have not upgrade symfony2 to this last version and so, I don't detect FileSystem class has been moved to a dedicated component... See 10059470ea2d2dfbb5c29d

Sgnx commented 12 years ago

I upgrade vendor to current version but i'm still receiving : The lucene index path "identifier1" does not exist. ;/ I even tried once again:" $luceneSearch = $this->configurationPool->getContainer()->get('ivory_lucene_search'); $indexes = array( 'identifier1' => array( 'path' => '/home/platne/sgnx/public_html/web/zend/lucene/index1/ ' ) );

$luceneSearch->setIndexes($indexes); $index = $luceneSearch->getIndex('identifier1'); " but no files appeared in directories - same situation as 5 days ago :(

egeloen commented 12 years ago

I have investigated your issue but I'm not able to reproduce it. When I create an index, the directory is created with the index files.

That's strange because the directory is created by Lucene itself so, if it is created, the associated index files should be created too...

I have updated the test suite to keep the generated index directory after the test has been ran. So, can you run the test suite & look the Tests/Emulation/cache/directory_test directory to be sure the index files has been generated too in your env.

egeloen commented 12 years ago

Have you fix your issue?

egeloen commented 12 years ago

ping @Sgnx

egeloen commented 12 years ago

Closing as there is no activity and personally, all works fine.

briansanchez commented 11 years ago

yes, don't create manually the folder. the directory is created by Lucene.

lionelbzv commented 10 years ago

+1 @briansanchez => this error occurs if the folder was manually created, but it works fine if we let the bundle creating it...

egeloen commented 10 years ago

@briansanchez @StudioEcho This is because the bundle simply open the lucene index (see here) if the directory exists (making the predicate it exists, not you have simply create an empty folder). Maybe we can check the index file exists in the directory here. What do you think? I'm not sure what happening if we try to create an lucene index with an empty folder...

lionelbzv commented 10 years ago

i think you're right, the "file_exists" hsas to check the folder + the lucene index file

egeloen commented 10 years ago

@StudioEcho I have just check what is the internal directory structure when I bootstrap an empty Zend lucene index and I got:

|- read.lock.file
|- segments.gen
|- segments_1
|- write.lock.file

I'm not sure which file I can check in the file_exists?...

egeloen commented 10 years ago

Or maybe just check if the directory is not empty through scandir?

lionelbzv commented 10 years ago

Before fixing this, I have to tell you about related problems with this index creation:

Warning: mkdir() [<a href='function.mkdir'>function.mkdir</a>]: Permission denied in /myprojectfolder/vendor/zendframework/zendsearch/library/ZendSearch/Lucene/Storage/Directory/Filesystem.php line 90

If I look in the stack trace, I see this: "mkdir ('/myprojectfolder/index.lucene', '511') " - instead of "mkdir ('/myprojectfolder/index.lucene', 0777) "?

What do you think of this file permissions stuffs?

egeloen commented 10 years ago

@StudioEcho Have you configured the permissions node according to your need?

egeloen commented 10 years ago

Additionally, I always use ACL to manage my permissions which really simplify them.

lionelbzv commented 10 years ago

Yes I've tried with "permissions" attribute set to 0777 and with the default value.

If you manage with ACL, it requires a command line before calling your service, right?

egeloen commented 10 years ago

Nope, the ACL is managed on top of everything. Just need to put the appropriate flag recursively on the directories/files and you're done. For example you authorize www-data to write to the directory, if there is no UNIX permissions for www-data in order to write, it will still work :)

egeloen commented 10 years ago

@StudioEcho What do you prefer between file_exists, scandir, something else? Basically, I ask you because I don't use the bundle personally.

lionelbzv commented 10 years ago

a scandir will be ok for me, thanks

egeloen commented 10 years ago

@StudioEcho Your issue should be fixed by the referenced commit.

egeloen commented 10 years ago

Btw, I have tagged the 1.0.0 release :)