Source: site.view [edit]
Function name: test2
Arguments:
Description: Testing exceptions
Page type: webl
Render function:  
Module: sandbox

Page source:

/* Adds a person object to the search index  */
var addPerson = fun(person)
   var ok = true;

   // create is false, add to existing index.  "standard" analysis (no stemming). For stemming: "kstem" and "english" (porter)
   var writer = Wub_NewLuceneIndex("resumes33", true, "standard"); 
   var doc = Wub_NewLuceneDocument();

  // Add fields to doc
   ok = ok and Wub_AddLuceneField(doc, "id", person["id"], true, true, 0); // 0 = no special boost
   ok = ok and Wub_AddLuceneField(doc, "name", person["name"], true, true, 0);
   ok = ok and Wub_AddLuceneField(doc, "headline", (person["headline"] ? ""), true, true, 0);

   ok = ok and Wub_AddLuceneDocument(writer, doc);
   ok = ok and Wub_OptimizeLucene(writer);
   ok = ok and Wub_CloseLuceneIndex(writer);
end;

var reader = Wub_ReadLuceneIndex("resumes33");
var res = [];
   var docs = Wub_LuceneSearch(reader, "name", "cheyer", 20, "standard"); // use same analyzer as was indexed with
   Wub_CloseLuceneIndex(reader);

   var i = 0;
   var sz = (docs.size() ? 0);

   while (i < sz) do
      var doc = docs.get(i).getDoc();
      // var explaination = docs.get(i).getExplanation(); // explains score

      var d = [. .];
      d["id"] := doc.getField("id").stringValue();
      d["name"] := doc.getField("name").stringValue();
      d["headline"] := doc.getField("headline").stringValue();

      res = res + [d];
      i = i + 1
   end;
   res;

//var person = [. id="adam", name="Adam Cheyer", headline="Dad" .];

//addPerson(person);