Skip to content

Instantly share code, notes, and snippets.

@boblail
Created October 11, 2010 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boblail/621125 to your computer and use it in GitHub Desktop.
Save boblail/621125 to your computer and use it in GitHub Desktop.
Sample use of Pericope
@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
@boblail
Copy link
Author

boblail commented Oct 11, 2010

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment