hacioguz / solr-php-client

Automatically exported from code.google.com/p/solr-php-client
Other
0 stars 0 forks source link

Support for highlighting #44

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I needed to have support for highlighting so I produced a quick patch to do 
what I needed to do.  All I did was have it add the highlighting to the 
document if highlighting was turned on using the extra options parameter in the 
search function.

Don't know if you want to use this or not (since it really is just a quickfix), 
but I figured it would be polite to offer it.

Original issue reported on code.google.com by KumoriK...@gmail.com on 5 Jul 2010 at 5:07

Attachments:

GoogleCodeExporter commented 8 years ago
Whoops...just noticed that I was examining the $results->response instead of 
just $results for something with the highlighting on it, and that's why I was 
not finding it.  Oh well, I still find that change useful for myself, so I'll 
keep it.

Original comment by KumoriK...@gmail.com on 5 Jul 2010 at 6:55

GoogleCodeExporter commented 8 years ago
I could see something like this being useful for simpler access to 
highlighting, however there are some gotchas that would need to be worked out:

 * not everyone uses the name "id" for their uniquely identifying field - personally I use "guid" - so that would need to be configurable.

 * I would want to set and get the highlighting similar to how boosts are handled so that its not considered just another document key / value(s) pair

Original comment by donovan....@gmail.com on 8 Jul 2010 at 10:51

GoogleCodeExporter commented 8 years ago
Changing to an acknowledged enhancement request

Original comment by donovan....@gmail.com on 8 Jul 2010 at 10:53

GoogleCodeExporter commented 8 years ago
I'll see what I can do about it if I get some time.

Original comment by KumoriK...@gmail.com on 9 Jul 2010 at 12:29

GoogleCodeExporter commented 8 years ago
Here is an upgraded patch.  I created two new classes. Apache_Solr_SolrOpts, an 
abstract class that provides an easy interface to dealing with search 
parameters and field overrides for those parameters, and 
Apache_Solr_HighlightOpts an extension of that class that takes care of all the 
highlighting parameters.  

I created 2 new instance variables in Apache_Solr_Service, one to keep track of 
the id field, and one to hold the Apache_Solr_HighlightOpts instance.  When the 
search method is called it will pull the (highlight) parameters out of that 
object.

I added a parameter to the Apache_Solr_Service and Apache_Solr_Response 
constructors to allow the feeding in of the id parameter.  The 
Apache_Solr_HighlightOpts is completely handled through getters/setters.

I switched the highlighting around so that it works in the same way that the 
boosts do.

Hopefully the Apache_Solr_SolrOpts class will make it easier for someone (if 
they want to) to do similar work for the facets as well.

Original comment by KumoriK...@gmail.com on 14 Jul 2010 at 6:50

Attachments:

GoogleCodeExporter commented 8 years ago
Hi KumoriKage,

Can you give a quick summary of what your patch does?  We've been using 
highlighting with the SPC for close to a year now and haven't had any problems, 
so I'm just wondering what you're adding to it.

Thanks.

Original comment by liam.obo...@gmail.com on 2 Dec 2010 at 6:27

GoogleCodeExporter commented 8 years ago
The patch adds a Apache_Solr_HighlightOpts class which has getters and setters 
for each of the possible options for highlighting (those documented on the wiki 
page) including getters and setters for field overrides for each of the 
options.  You can then call $service->setHighlightOptions($options) to provide 
it particular options, or $service->setHighlightOptions() to set the default 
instance (basically the same thing as setting "hl=true" in the options).

The patch adds an argument on the constructor for the name of the id field, so 
that it can match up the highlighting returned by Solr to the Document that it 
comes from.  This allows you to call $document->getFieldHighlighting($field) as 
well as attaching it to the information in $document->getField($field).

I also created an Apache_Solr_SolrOpts class to act as a base for SolrOpts, in 
case somebody wanted to implement something similar for facets.

The patch will likely fail to apply against trunk from SVN.  I believe that the 
revision that I made it against is r36.  However if you would like to use it, I 
will try to update my patch so that it works against trunk.

Original comment by KumoriK...@gmail.com on 2 Dec 2010 at 6:58

GoogleCodeExporter commented 8 years ago
Thanks, it sounds like a usability improvement but doesn't seem to add any 
features that we aren't currently able to use; it sounds like it's worth 
adding, but there's no urgency :)

Original comment by liam.obo...@gmail.com on 15 Dec 2010 at 3:24

GoogleCodeExporter commented 8 years ago
Hello everyone. I really need highlight feature. 
to KumoriK...@gmail.com, could you update your patch to the current trunk 
version. Thanks in advance.

Original comment by Gtp...@gmail.com on 20 Jan 2011 at 10:30

GoogleCodeExporter commented 8 years ago
Here is a patch against trunk.

@liam: Sorry it took so long, but just as I got that message things got really 
hectic...thankfully gtp posted this message and reminded me about at just the 
right time (currently have to wait for someone else to continue my work).

@Gtp...:here you go

Original comment by KumoriK...@gmail.com on 20 Jan 2011 at 7:26

Attachments:

GoogleCodeExporter commented 8 years ago
Is there any tutorial or example how to use this patch?

Original comment by sebastia...@gmail.com on 29 Aug 2011 at 10:24

GoogleCodeExporter commented 8 years ago
No there isn't.

I'm going to assume you mean how to use the API as opposed to actually applying 
the patch (just looking up how to apply a patch to SVN should work fine for 
that).

Basically, you need to tell Apache_Solr_Service what the ID field for your 
schema is (it defaults to "id"), this can be set through the final argument in 
the constructor or  through the #setIdField method.

If all you want is basic highlighting with no special parameters, all you have 
to do is call #setHighlightOptions() with no parameters. 

If you do need to set highlighting options, then you need to create a new 
Apache_Solr_HighlightOpts instance and use its methods to set whatever options 
you need, and then feed that object to the #setHighlightOptions() method.  

After that you will be able to access the highlighting using the 
#getFieldHighlighting() method or under the "highlighting" key from the 
#getField() method.

Original comment by KumoriK...@gmail.com on 29 Aug 2011 at 11:42

GoogleCodeExporter commented 8 years ago
Hi KumoriKage,

I really need highlight feature. 
I do this follow / solr-php-client-highlighting.patch - 46.8 KB / patch. But 
don't highlighting. 

I'm using Apache Solr 4.2 & SolrPhpClient.r60.2011-05-04.zip.

Please assist me on this.

Original comment by firsts...@gmail.com on 21 May 2013 at 5:10