Embedding Semantic Queries in MediaWiki Search Results
I am using Semantic MediaWiki with Lucene search and looking for a way to embed a SQL or Semantic Search query using the search input terms to generate a small table of results.
For example: If I was searching for Bob's phone number and my semantic data is structured as [[bob's number::555-555-5555]] in the article [[Bo开发者_高级运维b]], I would like a search for 'bob number' to return not only the normal lucene results but a small table with semantic query results, i.e. an inline query like
{{#ask: [[Bob]]
| ?Number
| format=table
}}
where 'Bob' and 'Number' are filled in from the search terms and assuming the articles to be queried (i.e. [[Bob]]) adhere to a known format.
To generate a simple table of:
| Name | Number |
| Bob | 555-555-5555 |
I could also do this with a sql query rather than the semantic search inline query if necessary, I just don't know where to start as far as modifying the search results page or accessing the search terms to build that query. Any help as to where to start (or of course if there is an extension of some sort that already does this) would be greatly appreciated.
Are you using this extension for your Lucene search ?
http://www.mediawiki.org/wiki/Extension:MWSearch
I did something similar on top of search results from Sphinx instead of Lucene. As long as you can get an array of page names, the method should stay the same.
You will have to find where the text snippets are generated and replace them with a call to the MediaWiki parser if you want to evaluate the result of an #ask query.
In practice, I found calling the parser for each match in the result set significantly degrades performance of the search (up to 15 seconds per result page).
It is a lot more efficient to use a predefined Semantic MediaWiki property for your snippets (easy to do if you are using Semantic Forms) and retrieve the value of that property instead of calling the parser.
精彩评论