Created
October 11, 2010 20:10
-
-
Save boblail/621125 to your computer and use it in GitHub Desktop.
Sample use of Pericope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@query = params[:query] | |
pretty_keywords = [] | |
index_keywords = [] | |
Pericope.split(@query, /[\r\n,;]/).each do |keyword| | |
if keyword.is_a?(Pericope) | |
pretty_keywords << keyword.to_s | |
index_keywords << "(#{keyword.to_a.join(" | ")})" | |
else | |
keyword = keyword.strip | |
if keyword.length > 0 | |
p keyword | |
pretty_keywords << keyword | |
index_keywords << keyword | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example assumes that Bible references like Romans 3:1-3 are allowed as keywords on products. But 'Romans 3:1-3' is not indexed as plain text; instead it is indexed as an array of unique identifiers for Bible verses: ([45003001, 45003002, 45003003]) where 45 is the book number, 003 the chapter, and the least significant digits are the verse.
The Pericope class serializes and deserializes plain text Bible references as arrays of ranges of these unique identifiers.
This example uses the Pericope class to extract Bible references from a search query along with plain text keywords. It yields each keyword either as an instance of String or an instance of Pericope to the block. The
to_a
method of Pericope returns an array of Bible verse identifiers.