floriansemm / SolrBundle

Solr-Integration into Symfony and Doctrine2
http://floriansemm.github.io/SolrBundle
MIT License
123 stars 73 forks source link

How to use Custom Tokenizer on Solr Field? #154

Closed jakesylvestre closed 7 years ago

jakesylvestre commented 7 years ago

Hello,

I'm trying to search for exact matches in my solr documents. One way that it's been suggested to do this is to use the KeywordTokenizerFactory. I'm wondering how (if it's possible) to implement this in a @Solr\Field annotation for an attribute in an entity.

Thanks!

Also, I just realized I accidentally posted #153 before this (and I can't delete it), so just ignore that.

Koalabaerchen commented 7 years ago

Looking at the annotation it doesn't seem like it. It also doesn't seem like you can add your own field types inside the annotation (without overwriting the annotation and extend it).

What you could do though is create a new fieldType inside the schema.xml with your required tokenizer, then also create a new field using that type.
Then create a copyField inside that schema as well that copies your field that comes from the entity into that new field with your required tokenizer and then do the query on that new field.

jakesylvestre commented 7 years ago

@Koalabaerchen that seems like it would be a really great feature to have.

floriansemm commented 7 years ago

@jakesyl those kind of configuration (define copyFields, configure Tokenizer and Filter) should be done directly in your schema.xml.

jakesylvestre commented 7 years ago

@floriansemm is there any technical reason they can't be done with annotations, and if not would you be open to a PR that added that functionality?

Koalabaerchen commented 7 years ago

@jakesyl the problem is those configurations all happen on the solr server itself. All you can do from the outside is to run queries to select and populate the fields.

Since Symfony is a framework where you can literally add anything you want to entities. Florian solved that problem by using the dynamic fields functionality to easily populate Solr.
To my knowledge there is no way to define the tokenizer and similar on the fly in Solr except inside the schema.xml

(To be precise, the Solr core doesn't even use the schema.xml but on startup/initialization creates a managed-schema file out of all the configurations and it only does that on startup)

edit: I think you can at least add fields on the fly inside the admin panel of Solr. But not fieldTypes itself.

jakesylvestre commented 7 years ago

Alright that makes sense, as you can probably tell my Solr knowledge is pretty limited. Thanks guys!