Sphinx Extension help

View: New views
9 Messages — Rating Filter:   Alert me  

Sphinx Extension help

by John Polling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm pretty new to Ruby and Radiant so please be gentle.  I've  
installed the Sphinx Search extension for a site search facility.  I  
need the search to include several other content models, such as  
NewsArticles, and not just Pages.

I've so far added this to the env ironment.rb

   config.after_initialize do
     ThinkingSphinx::Configuration.instance.model_directories << "#
{RAILS_ROOT}/vendor/extensions/news/app/models/"
     # Add new inflection rules using the following format:
     ActiveSupport::Inflector.inflections do |inflect|
       inflect.uncountable 'config'
     end
   end

This works fine as all the news gets indexed, however I'm struggling  
to search the news article.  When I do a search terms that has  
NewsArticles in it I get the following error message

undefined method `request' for #<NewsArticle:0x1064e3a48>

I've had a hunt around the code, but can't find anything that seems  
obvious.

I've so far updated the search_page.rb file as follows (it was only  
previously search the Page object):

   def process(request, response)
     @query = request.params[:query]
     # Ensure search is not run with empty term
     @results = @query.blank? ? ThinkingSphinx::Search.new
(0,@@per_page,0,0) : ThinkingSphinx.search(@query, :page =>  
request.params[:page], :per_page => @@per_page)
     super
   end

Another thing I've spotted when doing a search with on Page objects in  
the results is that the excerpt contains html tags.  I know I can  
strip the tags quite easily, but does it mean that the tags are being  
indexed and as such and class or id attributes etc might appear in  
search results?

One final question, there doesn't appear to be a link tag in the  
extension's tag class.  Do I need to write my own 'link' tag to link  
to the correct page?

thanks

John


_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Parent Message unknown Re: Sphinx Extension help

by Josh French :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> This works fine as all the news gets indexed, however I'm struggling
> to search the news article.  When I do a search terms that has
> NewsArticles in it I get the following error message

Hi John,

The Sphinx Search extension was initially built to work with arbitrary  
models but the actual results page is a late addition and so may need  
some tweaking. Can you paste a little more of the stack trace where  
you're getting the "undefined method `request'" error? I suspect it's  
just that the results tags are expecting Page objects and your  
NewsArticle pages don't conform to some assumption. (I am assuming  
that NewsArticle is *not* a Page subclass -- is that correct?)

>  does it mean that the tags are being
> indexed and as such and class or id attributes etc might appear

I *think* the strip_html option operates before your content gets  
indexed, but you might want to verify that with the Sphinx folks.

> One final question, there doesn't appear to be a link tag in the
> extension's tag class.  Do I need to write my own 'link' tag to link
> to the correct page?

In your case, you'll need to because you have polymorphic results  
objects. There's no way of knowing if your models have methods like  
link, url, or slug, so I can't supply tags that automatically expose  
the proper links.

In the simple case however -- a search that returns Page objects only  
-- within an r:results:each block you should be able to call any tag  
that a Page responds to, like r:url or r:title.

Josh
_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Sphinx Extension help

by John Polling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Josh,

Thanks for the info.  In regards to the stack trace this is what I'm  
getting

undefined method `request' for #<Advert:0x1064e3340>

/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/vendor/rails/activerecord/
lib/active_record/attribute_methods.rb:260:in `method_missing'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
38:in `set_process_variables'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
17:in `render_tag'
/Library/Ruby/Gems/1.8/gems/thinking-sphinx-1.2.12/lib/thinking_sphinx/
search.rb:102:in `collect'
/Library/Ruby/Gems/1.8/gems/thinking-sphinx-1.2.12/lib/thinking_sphinx/
search.rb:102:in `send'
/Library/Ruby/Gems/1.8/gems/thinking-sphinx-1.2.12/lib/thinking_sphinx/
search.rb:102:in `method_missing'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `send'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
10:in `initialize'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
18:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `send'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
10:in `initialize'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
18:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
18:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `send'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
10:in `initialize'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
18:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:287:in  
`parse'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:292:in  
`parse_object'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:142:in  
`render_snippet'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/standard_tags.rb:
374:in `tag:content'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `send'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/lib/radiant/taggable.rb:
33:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
10:in `initialize'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page_context.rb:
18:in `render_tag'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:287:in  
`parse'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:292:in  
`parse_object'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:126:in  
`render'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/models/page.rb:116:in  
`process_without_mailer'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/controllers/
site_controller.rb:46:in `process_page'
/Library/Ruby/Gems/1.8/gems/radiant-0.8.0/app/controllers/
site_controller.rb:20:in `show_page'

Thanks

John
On 30 Oct 2009, at 13:59, Josh French wrote:

>> This works fine as all the news gets indexed, however I'm struggling
>> to search the news article.  When I do a search terms that has
>> NewsArticles in it I get the following error message
>
> Hi John,
>
> The Sphinx Search extension was initially built to work with arbitrary
> models but the actual results page is a late addition and so may need
> some tweaking. Can you paste a little more of the stack trace where
> you're getting the "undefined method `request'" error? I suspect it's
> just that the results tags are expecting Page objects and your
> NewsArticle pages don't conform to some assumption. (I am assuming
> that NewsArticle is *not* a Page subclass -- is that correct?)
>
>> does it mean that the tags are being
>> indexed and as such and class or id attributes etc might appear
>
> I *think* the strip_html option operates before your content gets
> indexed, but you might want to verify that with the Sphinx folks.
>
>> One final question, there doesn't appear to be a link tag in the
>> extension's tag class.  Do I need to write my own 'link' tag to link
>> to the correct page?
>
> In your case, you'll need to because you have polymorphic results
> objects. There's no way of knowing if your models have methods like
> link, url, or slug, so I can't supply tags that automatically expose
> the proper links.
>
> In the simple case however -- a search that returns Page objects only
> -- within an r:results:each block you should be able to call any tag  
> that a Page responds to, like r:url or r:title.
>
> Josh
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@...
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Sphinx Extension help

by John Polling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Actually I've managed to resolve this issue.  The extension uses the  
following code in the radius tag

     tag 'results:each' do |tag|
       tag.locals.results.collect do |result|
         tag.locals.page = result
         tag.expand
       end.join("\n")
     end

the variable tag.locals.page conflicts with the page object, so  
changing to tag.locals.foundpage solves the problem.

I also had to change the 'results:each:excerpt' to get the excerpt  
like this

tag.locals.results.excerpt_for(content, tag.locals.foundpage.class)

as excerpt_for needs to know what class it is working on.

Now all I need to do is write a custom link and title tag for the  
radius tags and I'm sorted.

John

On 30 Oct 2009, at 13:59, Josh French wrote:

>> This works fine as all the news gets indexed, however I'm struggling
>> to search the news article.  When I do a search terms that has
>> NewsArticles in it I get the following error message
>
> Hi John,
>
> The Sphinx Search extension was initially built to work with arbitrary
> models but the actual results page is a late addition and so may need
> some tweaking. Can you paste a little more of the stack trace where
> you're getting the "undefined method `request'" error? I suspect it's
> just that the results tags are expecting Page objects and your
> NewsArticle pages don't conform to some assumption. (I am assuming
> that NewsArticle is *not* a Page subclass -- is that correct?)
>
>> does it mean that the tags are being
>> indexed and as such and class or id attributes etc might appear
>
> I *think* the strip_html option operates before your content gets
> indexed, but you might want to verify that with the Sphinx folks.
>
>> One final question, there doesn't appear to be a link tag in the
>> extension's tag class.  Do I need to write my own 'link' tag to link
>> to the correct page?
>
> In your case, you'll need to because you have polymorphic results
> objects. There's no way of knowing if your models have methods like
> link, url, or slug, so I can't supply tags that automatically expose
> the proper links.
>
> In the simple case however -- a search that returns Page objects only
> -- within an r:results:each block you should be able to call any tag  
> that a Page responds to, like r:url or r:title.
>
> Josh
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@...
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Parent Message unknown Re: Sphinx Extension help

by Josh French :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John,

I've updated the Sphinx Search extension to be more flexible when  
handling results that aren't Pages. Can you update to the latest  
version and try again? Also, some basic tags like title and URL will  
be available as long as your model implements methods by the same  
name. That may spare you from having to write your own implementation  
of r:link.

Let me know if you run into any further problems.
Josh
_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Sphinx Extension help

by John Polling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Josh,

Thanks for the update.  I'll try and look into this in the next couple  
of days

John

On 2 Nov 2009, at 21:03, Josh French wrote:

> John,
>
> I've updated the Sphinx Search extension to be more flexible when
> handling results that aren't Pages. Can you update to the latest
> version and try again? Also, some basic tags like title and URL will
> be available as long as your model implements methods by the same
> name. That may spare you from having to write your own implementation
> of r:link.
>
> Let me know if you run into any further problems.
> Josh
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@...
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Sphinx Extension help

by John Polling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I've just moved my site to production and the Sphinx Search seems to  
be giving me problems

When I run a search I'm getting the following error.

undefined method `constantize' for nil:NilClass


Has anyone else had this?

Thanks

John

On 2 Nov 2009, at 21:03, Josh French wrote:

> John,
>
> I've updated the Sphinx Search extension to be more flexible when
> handling results that aren't Pages. Can you update to the latest
> version and try again? Also, some basic tags like title and URL will
> be available as long as your model implements methods by the same
> name. That may spare you from having to write your own implementation
> of r:link.
>
> Let me know if you run into any further problems.
> Josh
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@...
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Parent Message unknown Re: Sphinx Extension help

by Josh French :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> When I run a search I'm getting the following error.
>
> undefined method `constantize' for nil:NilClass

Hi John,

This may help: http://jimneath.org/2009/11/09/thinkingsphinx-and-nil-results/

Best,
Josh
_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Re: Sphinx Extension help

by John Polling-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Josh,

Unfortunately this hasn't resolved the issue.  It's weird that it  
works just fine on my local machine.

John

On 16 Nov 2009, at 14:43, Josh French wrote:

>> When I run a search I'm getting the following error.
>>
>> undefined method `constantize' for nil:NilClass
>
> Hi John,
>
> This may help: http://jimneath.org/2009/11/09/thinkingsphinx-and-nil-results/
>
> Best,
> Josh
> _______________________________________________
> Radiant mailing list
> Post:   Radiant@...
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@...
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant